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
|
package skate
import (
"reflect"
"sort"
"testing"
)
func TestMatchSetLookup(t *testing.T) {
var cases = []struct {
s string
ps []string
n int
result []string
}{
{
s: "",
ps: []string{},
n: -1,
result: nil,
},
{
s: "hello",
ps: []string{"lo"},
n: -1,
result: nil,
},
{
s: "hello",
ps: []string{"zz"},
n: -1,
result: nil,
},
{
s: "hello",
ps: []string{"h", "he", "hel"},
n: -1,
result: nil,
},
{
s: "hello",
ps: []string{"hello"},
n: -1,
result: []string{"hello"},
},
{
s: "hello world",
ps: []string{"hello", "world"},
n: -1,
result: nil,
},
{
s: "he",
ps: []string{"hello", "world", "hel"},
n: -1,
result: []string{"hello", "hel"},
},
{
s: "american italian proceedings",
ps: []string{
"italian",
"american",
"american italian",
"american italian proceedings",
"proceedings",
},
n: -1,
result: []string{"american italian proceedings"},
},
{
s: "american",
ps: []string{
"american proceedings XII",
"american journal",
"american",
},
n: -1,
result: []string{
"american proceedings XII",
"american journal",
"american",
},
},
}
for _, c := range cases {
ms := NewMatchSet(c.ps)
result := ms.Lookup(c.s, c.n)
sort.Strings(result)
sort.Strings(c.result)
if !reflect.DeepEqual(result, c.result) {
t.Errorf("got %v, want %v -> s=%s ps=%s",
result, c.result, c.s, c.ps)
}
}
}
|