-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsearch_whitebox_test.go
73 lines (69 loc) · 1.96 KB
/
search_whitebox_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
package trie
import (
"fmt"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestTrie_getEditOps(t *testing.T) {
testCases := []struct {
fromKeyColumn []string
toKey []string
rows [][]int
expectedOps []*EditOp
}{
{
fromKeyColumn: strings.Split("sitting", ""),
toKey: strings.Split("kitten", ""),
rows: [][]int{
{0, 1, 2, 3, 4, 5, 6},
{1, 1, 2, 3, 4, 5, 6},
{2, 2, 1, 2, 3, 4, 5},
{3, 3, 2, 1, 2, 3, 4},
{4, 4, 3, 2, 1, 2, 3},
{5, 5, 4, 3, 2, 2, 3},
{6, 6, 5, 4, 3, 3, 2},
{7, 7, 6, 5, 4, 4, 3},
},
expectedOps: []*EditOp{
{Type: EditOpTypeReplace, KeyPart: "s", ReplaceWith: "k"},
{Type: EditOpTypeNoEdit, KeyPart: "i"},
{Type: EditOpTypeNoEdit, KeyPart: "t"},
{Type: EditOpTypeNoEdit, KeyPart: "t"},
{Type: EditOpTypeReplace, KeyPart: "i", ReplaceWith: "e"},
{Type: EditOpTypeNoEdit, KeyPart: "n"},
{Type: EditOpTypeDelete, KeyPart: "g"},
},
},
{
fromKeyColumn: strings.Split("Sunday", ""),
toKey: strings.Split("Saturday", ""),
rows: [][]int{
{0, 1, 2, 3, 4, 5, 6, 7, 8},
{1, 0, 1, 2, 3, 4, 5, 6, 7},
{2, 1, 1, 2, 2, 3, 4, 5, 6},
{3, 2, 2, 2, 3, 3, 4, 5, 6},
{4, 3, 3, 3, 3, 4, 3, 4, 5},
{5, 4, 3, 4, 4, 4, 4, 3, 4},
{6, 5, 4, 4, 5, 5, 5, 4, 3},
},
expectedOps: []*EditOp{
{Type: EditOpTypeNoEdit, KeyPart: "S"},
{Type: EditOpTypeInsert, KeyPart: "a"},
{Type: EditOpTypeInsert, KeyPart: "t"},
{Type: EditOpTypeNoEdit, KeyPart: "u"},
{Type: EditOpTypeReplace, KeyPart: "n", ReplaceWith: "r"},
{Type: EditOpTypeNoEdit, KeyPart: "d"},
{Type: EditOpTypeNoEdit, KeyPart: "a"},
{Type: EditOpTypeNoEdit, KeyPart: "y"},
},
},
}
for _, tc := range testCases {
t.Run(fmt.Sprintf("from %v to %v", tc.fromKeyColumn, tc.toKey), func(t *testing.T) {
tri := New()
actual := tri.getEditOps(&tc.rows, &tc.fromKeyColumn, tc.toKey)
assert.Equal(t, tc.expectedOps, actual)
})
}
}