-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstate_test.go
More file actions
53 lines (47 loc) · 1.12 KB
/
state_test.go
File metadata and controls
53 lines (47 loc) · 1.12 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
package comb
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestBytesTo(t *testing.T) {
t.Parallel()
textState1 := NewFromString("12345678", 0)
textState2 := textState1.MoveBy(4)
binaryState1 := NewFromBytes([]byte{1, 2, 3, 4, 5, 6, 7, 8}, 0)
binaryState2 := binaryState1.MoveBy(4)
testCases := []struct {
name string
state1 State
state2 State
wantBytes []byte
}{
{
name: "text moved forward",
state1: textState1,
state2: textState2,
wantBytes: []byte("1234"),
}, {
name: "text moved backward",
state1: textState2,
state2: textState1,
wantBytes: []byte{},
}, {
name: "binary moved forward",
state1: binaryState1,
state2: binaryState2,
wantBytes: []byte{1, 2, 3, 4},
}, {
name: "binary moved backward",
state1: binaryState2,
state2: binaryState1,
wantBytes: []byte{},
},
}
for _, tt := range testCases {
tt := tt // needed for not testing the same case N times
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
assert.Equal(t, tt.wantBytes, tt.state1.BytesTo(tt.state2))
})
}
}