...
1
2
3
4
5 package stringset
6
7 import "testing"
8
9 func TestStringSet(t *testing.T) {
10 testCases := [][]string{
11 {""},
12 {"∫"},
13 {"a", "b", "c"},
14 {"", "a", "bb", "ccc"},
15 {" ", "aaa", "bb", "c"},
16 }
17 test := func(tc int, b *Builder) {
18 set := b.Set()
19 if set.Len() != len(testCases[tc]) {
20 t.Errorf("%d:Len() = %d; want %d", tc, set.Len(), len(testCases[tc]))
21 }
22 for i, s := range testCases[tc] {
23 if x := b.Index(s); x != i {
24 t.Errorf("%d:Index(%q) = %d; want %d", tc, s, x, i)
25 }
26 if p := Search(&set, s); p != i {
27 t.Errorf("%d:Search(%q) = %d; want %d", tc, s, p, i)
28 }
29 if set.Elem(i) != s {
30 t.Errorf("%d:Elem(%d) = %s; want %s", tc, i, set.Elem(i), s)
31 }
32 }
33 if p := Search(&set, "apple"); p != -1 {
34 t.Errorf(`%d:Search("apple") = %d; want -1`, tc, p)
35 }
36 }
37 for i, tc := range testCases {
38 b := NewBuilder()
39 for _, s := range tc {
40 b.Add(s)
41 }
42 b.Add(tc...)
43 test(i, b)
44 }
45 for i, tc := range testCases {
46 b := NewBuilder()
47 b.Add(tc...)
48 for _, s := range tc {
49 b.Add(s)
50 }
51 test(i, b)
52 }
53 }
54
View as plain text