-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsafe_trie_test.go
54 lines (47 loc) · 947 Bytes
/
safe_trie_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
package trie
import (
"fmt"
"testing"
)
func TestSafeTrieContains(t *testing.T) {
trie := Safe(NewRuneTrie())
for i := 0; i < 100; i++ {
trie.Insert("c")
trie.Insert("apple")
trie.Insert("banana")
go func(index int) {
trie.Insert(fmt.Sprintf("c%d", index))
trie.Insert(fmt.Sprintf("apple%d", index))
trie.Insert(fmt.Sprintf("banana%d", index))
}(i)
}
cases := []struct {
word string
exists bool
}{
{"c", true},
{"ce", false},
{"banana", true},
{"app", false},
{"aple", false},
{"ban", false},
{"apple", true},
{"apple125", false},
{"aaapple", false},
}
done := make(chan bool)
go func() {
for _, c := range cases {
actual := trie.Contains(c.word)
if actual != c.exists {
if c.exists {
t.Errorf("%s is expected to be found in the trie", c.word)
} else {
t.Errorf("%s is not expected to be found in the trie", c.word)
}
}
}
done <- true
}()
<-done
}