-
Notifications
You must be signed in to change notification settings - Fork 41
/
lcs_test.go
85 lines (83 loc) · 1.67 KB
/
lcs_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
package jsondiff
import (
"reflect"
"testing"
)
func Test_lcs(t *testing.T) {
for _, tc := range []struct {
name string
src []interface{}
tgt []interface{}
pairs [][2]int
}{
{
name: "identical slices",
src: []interface{}{"a", "b", "c"},
tgt: []interface{}{"a", "b", "c"},
pairs: [][2]int{
{0, 0},
{1, 1},
{2, 2},
},
},
{
name: "different slices (expand)",
src: []interface{}{"a", "b", "c", "e", "h", "j", "l", "m", "n", "p"},
tgt: []interface{}{"b", "c", "d", "e", "f", "j", "k", "l", "m", "r", "s", "t"},
pairs: [][2]int{
{1, 0},
{2, 1},
{3, 3},
{5, 5},
{6, 7},
{7, 8},
},
},
{
name: "different slices (shrink)",
src: []interface{}{"a", "b", "y", "w", "c"},
tgt: []interface{}{"a", "z", "b", "c"},
pairs: [][2]int{
{0, 0},
{1, 2},
{4, 3},
},
},
{
name: "slices with duplicates",
src: []interface{}{"a", "b", "a", "y", "c", "c"},
tgt: []interface{}{"z", "b", "a", "c", "c", "b"},
pairs: [][2]int{
{1, 1},
{2, 2},
{4, 3},
{5, 4},
},
},
{
name: "all deletions",
src: []interface{}{"a", "b", "c", "d"},
tgt: []interface{}{},
pairs: [][2]int{},
},
{
name: "all additions",
src: []interface{}{},
tgt: []interface{}{"a", "b", "c", "d"},
pairs: [][2]int{},
},
{
name: "all deletions and additions",
src: []interface{}{"a", "b", "c", "d"},
tgt: []interface{}{"e", "f", "g", "h"},
pairs: [][2]int{},
},
} {
t.Run(tc.name, func(t *testing.T) {
pairs := lcs(tc.src, tc.tgt)
if !reflect.DeepEqual(pairs, tc.pairs) {
t.Errorf("got %v, want %v", pairs, tc.pairs)
}
})
}
}