forked from yihuang/go-block-stm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.go
81 lines (76 loc) · 1.45 KB
/
utils_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
package block_stm
import (
"testing"
"github.com/test-go/testify/require"
)
type DiffEntry struct {
Key Key
IsNew bool
}
func TestDiffOrderedList(t *testing.T) {
testCases := []struct {
name string
old []Key
new []Key
expected []DiffEntry
}{
{
name: "empty lists",
old: []Key{},
new: []Key{},
expected: []DiffEntry{},
},
{
name: "old is longer",
old: []Key{
[]byte("a"),
[]byte("b"),
[]byte("c"),
[]byte("d"),
[]byte("e"),
},
new: []Key{
[]byte("b"),
[]byte("c"),
[]byte("f"),
},
expected: []DiffEntry{
{Key: []byte("a"), IsNew: false},
{Key: []byte("d"), IsNew: false},
{Key: []byte("e"), IsNew: false},
{Key: []byte("f"), IsNew: true},
},
},
{
name: "new is longer",
old: []Key{
[]byte("a"),
[]byte("c"),
[]byte("e"),
},
new: []Key{
[]byte("b"),
[]byte("c"),
[]byte("d"),
[]byte("e"),
[]byte("f"),
},
expected: []DiffEntry{
{Key: []byte("a"), IsNew: false},
{Key: []byte("b"), IsNew: true},
{Key: []byte("d"), IsNew: true},
{Key: []byte("f"), IsNew: true},
},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result := []DiffEntry{}
DiffOrderedList(tc.old, tc.new, func(key Key, leftOrRight bool) bool {
result = append(result, DiffEntry{key, leftOrRight})
return true
})
require.Equal(t, tc.expected, result)
})
}
}