disable git when .git does not exist
[liba.git] / python / test / crc.py
blob4185152210e38df03243917dc1d70c7493c7f7a6
1 #!/usr/bin/env python
2 import os, sys
4 sys.path.insert(0, os.getcwd())
5 if len(sys.argv) > 1:
6 sys.stdout = open(sys.argv[1], "w")
8 import liba # type: ignore
10 text = b"0123456789"
12 crc = liba.crc8(0x07)
13 assert crc.table
14 assert crc(text) == 0x45
15 assert crc(crc.pack(text)) == 0
17 crc = liba.crc8(0x31, reversed=True)
18 assert crc.table
19 assert crc(text) == 0x75
20 assert crc(crc.pack(text)) == 0
22 crc = liba.crc16(0x1021)
23 assert crc.table
24 assert crc(text) == 0x9C58
25 assert crc(crc.pack(text)) == 0
27 crc = liba.crc16(0x8005, reversed=True)
28 assert crc.table
29 assert crc(text) == 0x443D
30 assert crc(crc.pack(text)) == 0
32 crc = liba.crc32(0x1EDC6F41)
33 assert crc.table
34 assert crc(text) == 0x512B456E
35 assert crc(crc.pack(text)) == 0
37 crc = liba.crc32(0x04C11DB7, reversed=True)
38 assert crc.table
39 assert crc(text) == 0x450EAFB0
40 assert crc(crc.pack(text)) == 0
42 crc = liba.crc64(0x000000000000001B)
43 assert crc.table
44 assert crc(text) == 0xE4FFBEA588AFC790
45 assert crc(crc.pack(text)) == 0
47 crc = liba.crc64(0x42F0E1EBA9EA3693, reversed=True)
48 assert crc.table
49 assert crc(text) == 0xDA60676A5CDE0008
50 assert crc(crc.pack(text)) == 0