| 1 |
package trie |
| 2 |
|
| 3 |
import ( |
| 4 |
|
| 5 |
"testing" |
| 6 |
) |
| 7 |
|
| 8 |
func Test(t *testing.T) { |
| 9 |
x := New() |
| 10 |
x.Insert(1, 100) |
| 11 |
if x.Len() != 1 { |
| 12 |
t.Errorf("expected len 1") |
| 13 |
} |
| 14 |
if x.Get(1).(int) != 100 { |
| 15 |
t.Errorf("expected to get 100 for 1") |
| 16 |
} |
| 17 |
x.Remove(1) |
| 18 |
if x.Len() != 0 { |
| 19 |
t.Errorf("expected len 0") |
| 20 |
} |
| 21 |
x.Insert(2, 200) |
| 22 |
x.Insert(1, 100) |
| 23 |
vs := make([]int, 0) |
| 24 |
x.Do(func(k, v interface{}) bool { |
| 25 |
vs = append(vs, k.(int)) |
| 26 |
return true |
| 27 |
}) |
| 28 |
if len(vs) != 2 || vs[0] != 1 || vs[1] != 2 { |
| 29 |
t.Errorf("expected in order traversal") |
| 30 |
} |
| 31 |
} |