iterator_test.go 598 Bytes
Newer Older
1
package trie
obscuren's avatar
obscuren committed
2 3 4 5 6 7 8 9 10

import "testing"

func TestIterator(t *testing.T) {
	trie := NewEmpty()
	vals := []struct{ k, v string }{
		{"do", "verb"},
		{"ether", "wookiedoo"},
		{"horse", "stallion"},
11 12 13 14
		{"shaman", "horse"},
		{"doge", "coin"},
		{"dog", "puppy"},
		{"somethingveryoddindeedthis is", "myothernodedata"},
obscuren's avatar
obscuren committed
15 16 17 18 19 20
	}
	v := make(map[string]bool)
	for _, val := range vals {
		v[val.k] = false
		trie.UpdateString(val.k, val.v)
	}
21
	trie.Commit()
obscuren's avatar
obscuren committed
22 23 24 25 26 27 28 29 30 31 32 33

	it := trie.Iterator()
	for it.Next() {
		v[string(it.Key)] = true
	}

	for k, found := range v {
		if !found {
			t.Error("iterator didn't find", k)
		}
	}
}