-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathhattrie_test.go
49 lines (45 loc) · 902 Bytes
/
hattrie_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
package safebrowsing
import (
"testing"
)
func TestNewTrie(t *testing.T) {
trie := NewTrie()
val := trie.Get("asdf")
if val != false {
t.Fatal("Unset value returned as true")
}
trie.Set("asdf")
val = trie.Get("asdf")
if val != true {
t.Fatal("Set value returned as false")
}
trie.Delete("asdf")
val = trie.Get("asdf")
if val != false {
t.Fatal("Deleted value returned as true")
}
}
func TestDeleteFromTrie(t *testing.T) {
trie := NewTrie()
trie.Delete("asdf")
val := trie.Get("asdf")
if val != false {
t.Fatal("Unset value returned as true")
}
}
func TestIterator(t *testing.T) {
trie := NewTrie()
trie.Set("a")
trie.Set("ab")
trie.Set("abc")
i := trie.Iterator()
if key := i.Next(); key != "a" {
t.Fatal("iterator failed")
}
if key := i.Next(); key != "ab" {
t.Fatal("iterator failed")
}
if key := i.Next(); key != "abc" {
t.Fatal("iterator failed")
}
}