forked from pd0mz/go-dmr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
crc_test.go
60 lines (53 loc) · 1.09 KB
/
crc_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package dmr
import "testing"
func TestCRC9(t *testing.T) {
tests := map[uint16][]byte{
0x0000: []byte{},
0x0100: []byte{0x00, 0x01},
0x0179: []byte("hello world"),
}
for want, test := range tests {
var crc uint16
for _, b := range test {
crc9(&crc, b, 8)
}
crc9end(&crc, 8)
if crc != want {
t.Fatalf("crc9 %v failed: %#04x != %#04x", test, crc, want)
}
}
}
func TestCRC16(t *testing.T) {
tests := map[uint16][]byte{
0x0000: []byte{},
0x1021: []byte{0x00, 0x01},
0x3be4: []byte("hello world"),
}
for want, test := range tests {
var crc uint16
for _, b := range test {
crc16(&crc, b)
}
crc16end(&crc)
if crc != want {
t.Fatalf("crc16 %v failed: %#04x != %#04x", test, crc, want)
}
}
}
func TestCRC32(t *testing.T) {
tests := map[uint32][]byte{
0x00000000: []byte{},
0x04c11db7: []byte{0x00, 0x01},
0x737af2ae: []byte("hello world"),
}
for want, test := range tests {
var crc uint32
for _, b := range test {
crc32(&crc, b)
}
crc32end(&crc)
if crc != want {
t.Fatalf("crc32 %v failed: %#08x != %#08x", test, crc, want)
}
}
}