2015-01-08 04:47:04 -06:00
|
|
|
package trie
|
2014-11-19 08:05:08 -06:00
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
func TestIterator(t *testing.T) {
|
|
|
|
trie := NewEmpty()
|
|
|
|
vals := []struct{ k, v string }{
|
|
|
|
{"do", "verb"},
|
|
|
|
{"ether", "wookiedoo"},
|
|
|
|
{"horse", "stallion"},
|
2014-11-20 11:11:31 -06:00
|
|
|
{"shaman", "horse"},
|
|
|
|
{"doge", "coin"},
|
|
|
|
{"dog", "puppy"},
|
|
|
|
{"somethingveryoddindeedthis is", "myothernodedata"},
|
2014-11-19 08:05:08 -06:00
|
|
|
}
|
|
|
|
v := make(map[string]bool)
|
|
|
|
for _, val := range vals {
|
|
|
|
v[val.k] = false
|
|
|
|
trie.UpdateString(val.k, val.v)
|
|
|
|
}
|
2014-11-20 11:11:31 -06:00
|
|
|
trie.Commit()
|
2014-11-19 08:05:08 -06:00
|
|
|
|
|
|
|
it := trie.Iterator()
|
|
|
|
for it.Next() {
|
2015-03-16 10:36:58 -05:00
|
|
|
v[string(it.Key)] = true
|
2014-11-19 08:05:08 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
for k, found := range v {
|
|
|
|
if !found {
|
|
|
|
t.Error("iterator didn't find", k)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|