-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslicearray_test.go
104 lines (102 loc) · 1.9 KB
/
slicearray_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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package k2tree
import (
"bytes"
"testing"
)
func TestSliceArrayInsertTable(t *testing.T) {
tt := []struct {
n int
at int
input []byte
output []byte
length int
}{
{
n: 4,
at: 12,
input: []byte{0xAB, 0xCD, 0xEF},
length: 24,
output: []byte{0xAB, 0xC0, 0xDE, 0xF0},
},
{
n: 12,
at: 4,
input: []byte{0xAB, 0xCD, 0xEF},
length: 24,
output: []byte{0xA0, 0x00, 0xBC, 0xDE, 0xF0},
},
{
n: 8,
at: 4,
input: []byte{0xAB, 0xCD, 0xEF},
length: 24,
output: []byte{0xA0, 0x0B, 0xCD, 0xEF},
},
{
n: 16,
at: 8,
input: []byte{0xAB, 0xCD, 0xEF},
length: 24,
output: []byte{0xAB, 0x00, 0x00, 0xCD, 0xEF},
},
{
n: 12,
at: 8,
input: []byte{0xAB, 0xCD, 0xEF},
length: 24,
output: []byte{0xAB, 0x00, 0x0C, 0xDE, 0xF0},
},
{
n: 4,
at: 8,
input: []byte{0xAB, 0xCD, 0xEF},
length: 24,
output: []byte{0xAB, 0x0C, 0xDE, 0xF0},
},
{
n: 4,
at: 12,
input: []byte{0xAB, 0xCD, 0xEF, 0x10},
length: 28,
output: []byte{0xAB, 0xC0, 0xDE, 0xF1},
},
{
n: 4,
at: 16,
input: []byte{0xAB, 0xCD, 0xEF, 0x10},
length: 28,
output: []byte{0xAB, 0xCD, 0x0E, 0xF1},
},
{
n: 12,
at: 8,
input: []byte{0xAB, 0xCD, 0xEF, 0x10},
length: 28,
output: []byte{0xAB, 0x00, 0x0C, 0xDE, 0xF1},
},
{
n: 12,
at: 12,
input: []byte{0xAB, 0xCD, 0xEF, 0x10},
length: 28,
output: []byte{0xAB, 0xC0, 0x00, 0xDE, 0xF1},
},
{
n: 4,
at: 4,
input: []byte{0x19},
length: 8,
output: []byte{0x10, 0x90},
},
}
for _, x := range tt {
s := &sliceArray{
bytes: x.input,
length: x.length,
}
s.Insert(x.n, x.at)
if !bytes.Equal(s.bytes, x.output) {
t.Errorf("mismatch! got %#v expected %#v (n: %d, at %d, len %d)", s.bytes, x.output, x.n, x.at, x.length)
}
}
}