remove redundant includes
[liba.git] / python / test / crc.py
blob677c9b39bbbc0b248719922bb5036b729abe900f
1 #!/usr/bin/env python
2 import os, sys
4 base = os.path.dirname(__file__)
5 path = os.path.dirname(base)
6 sys.path.insert(0, path)
7 if len(sys.argv) > 1:
8 sys.stdout = open(sys.argv[1], "w")
10 import liba # type: ignore
12 text = b"0123456789"
14 crc = liba.crc8(0x07)
15 assert crc.table
16 assert crc(text) == 0x45
17 assert crc(crc.pack(text)) == 0
19 crc = liba.crc8(0x31, reversed=True)
20 assert crc.table
21 assert crc(text) == 0x75
22 assert crc(crc.pack(text)) == 0
24 crc = liba.crc16(0x1021)
25 assert crc.table
26 assert crc(text) == 0x9C58
27 assert crc(crc.pack(text)) == 0
29 crc = liba.crc16(0x8005, reversed=True)
30 assert crc.table
31 assert crc(text) == 0x443D
32 assert crc(crc.pack(text)) == 0
34 crc = liba.crc32(0x1EDC6F41)
35 assert crc.table
36 assert crc(text) == 0x512B456E
37 assert crc(crc.pack(text)) == 0
39 crc = liba.crc32(0x04C11DB7, reversed=True)
40 assert crc.table
41 assert crc(text) == 0x450EAFB0
42 assert crc(crc.pack(text)) == 0
44 crc = liba.crc64(0x000000000000001B)
45 assert crc.table
46 assert crc(text) == 0xE4FFBEA588AFC790
47 assert crc(crc.pack(text)) == 0
49 crc = liba.crc64(0x42F0E1EBA9EA3693, reversed=True)
50 assert crc.table
51 assert crc(text) == 0xDA60676A5CDE0008
52 assert crc(crc.pack(text)) == 0