-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrc_test.go
More file actions
78 lines (72 loc) · 1.27 KB
/
Copy pathcrc_test.go
File metadata and controls
78 lines (72 loc) · 1.27 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package crc_test
import (
"testing"
"github.com/ravisuhag/astro/pkg/crc"
)
func TestComputeCRC16(t *testing.T) {
tests := []struct {
name string
data []byte
want uint16
}{
{
name: "standard ASCII 123456789",
data: []byte("123456789"),
want: 0x29B1,
},
{
name: "empty input",
data: []byte{},
want: 0xFFFF,
},
{
name: "single zero byte",
data: []byte{0x00},
want: 0xE1F0,
},
{
name: "single 0xFF byte",
data: []byte{0xFF},
want: 0xFF00,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := crc.ComputeCRC16(tt.data)
if got != tt.want {
t.Errorf("ComputeCRC16(%x) = 0x%04X, want 0x%04X", tt.data, got, tt.want)
}
})
}
}
func TestComputeCRC32(t *testing.T) {
tests := []struct {
name string
data []byte
want uint32
}{
{
name: "standard ASCII 123456789",
data: []byte("123456789"),
want: 0xE3069283,
},
{
name: "empty input",
data: []byte{},
want: 0x00000000,
},
{
name: "single zero byte",
data: []byte{0x00},
want: 0x527D5351,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := crc.ComputeCRC32(tt.data)
if got != tt.want {
t.Errorf("ComputeCRC32(%x) = 0x%08X, want 0x%08X", tt.data, got, tt.want)
}
})
}
}