-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathdictionary_test.go
81 lines (78 loc) · 1.84 KB
/
dictionary_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
74
75
76
77
78
79
80
81
package orc
import (
"fmt"
"testing"
)
func TestDictionary(t *testing.T) {
tree := NewDictionary(5)
if v := tree.add("owen"); v != 0 {
t.Errorf("Test failed, got %v", v)
}
if v := tree.add("ashutosh"); v != 1 {
t.Errorf("Test failed, got %v", v)
}
if v := tree.add("owen"); v != 0 {
t.Errorf("Test failed, got %v", v)
}
if v := tree.add("alan"); v != 2 {
t.Errorf("Test failed, got %v", v)
}
if v := tree.add("alan"); v != 2 {
t.Errorf("Test failed, got %v", v)
}
if v := tree.add("ashutosh"); v != 1 {
t.Errorf("Test failed, got %v", v)
}
if v := tree.add("greg"); v != 3 {
t.Errorf("Test failed, got %v", v)
}
if v := tree.add("eric"); v != 4 {
t.Errorf("Test failed, got %v", v)
}
if v := tree.add("arun"); v != 5 {
t.Errorf("Test failed, got %v", v)
}
if v := tree.Size(); v != 6 {
t.Errorf("Test failed, got %v", v)
}
if v := tree.add("eric14"); v != 6 {
t.Errorf("Test failed, got %v", v)
}
if v := tree.add("o"); v != 7 {
t.Errorf("Test failed, got %v", v)
}
if v := tree.add("ziggy"); v != 8 {
t.Errorf("Test failed, got %v", v)
}
if v := tree.add("z"); v != 9 {
t.Errorf("Test failed, got %v", v)
}
if v := tree.add("greg"); v != 3 {
t.Errorf("Test failed, got %v", v)
}
if v := tree.add("zak"); v != 10 {
t.Errorf("Test failed, got %v", v)
}
if v := tree.add("eric1"); v != 11 {
t.Errorf("Test failed, got %v", v)
}
if v := tree.add("ash"); v != 12 {
t.Errorf("Test failed, got %v", v)
}
if v := tree.add("harry"); v != 13 {
t.Errorf("Test failed, got %v", v)
}
if v := tree.add("john"); v != 14 {
t.Errorf("Test failed, got %v", v)
}
tree.clear()
}
func TestDictionary2(t *testing.T) {
tree := NewDictionary(InitialDictionarySize)
for i := 0; i < 10000; i++ {
tree.add(fmt.Sprint(i))
}
if tree.Size() != 10000 {
t.Errorf("Test failed, got %v", tree.Size())
}
}