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
|
package crc
import (
"testing"
)
type crcTest struct {
name string
input []byte
seq int
expected byte
}
var crcTests = []crcTest{
{
name: "sequence 0",
input: []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
seq: 0,
expected: 0x2f,
},
{
name: "sequence 1",
input: []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
seq: 1,
expected: 0x2d,
},
{
name: "sequence 2",
input: []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
seq: 2,
expected: 0x37,
},
}
func TestCRCs(t *testing.T) {
for _, ct := range crcTests {
t.Run(ct.name, func(t *testing.T) {
crc := Byte(ct.input, ct.seq)
if crc != ct.expected {
t.Errorf("crc byte didn't match expected")
t.Logf("output: %#v", crc)
t.Logf("expected: %#v", ct.expected)
}
})
}
}
|