iterator_test.go 598 B

123456789101112131415161718192021222324252627282930313233
  1. package trie
  2. import "testing"
  3. func TestIterator(t *testing.T) {
  4. trie := NewEmpty()
  5. vals := []struct{ k, v string }{
  6. {"do", "verb"},
  7. {"ether", "wookiedoo"},
  8. {"horse", "stallion"},
  9. {"shaman", "horse"},
  10. {"doge", "coin"},
  11. {"dog", "puppy"},
  12. {"somethingveryoddindeedthis is", "myothernodedata"},
  13. }
  14. v := make(map[string]bool)
  15. for _, val := range vals {
  16. v[val.k] = false
  17. trie.UpdateString(val.k, val.v)
  18. }
  19. trie.Commit()
  20. it := trie.Iterator()
  21. for it.Next() {
  22. v[string(it.Key)] = true
  23. }
  24. for k, found := range v {
  25. if !found {
  26. t.Error("iterator didn't find", k)
  27. }
  28. }
  29. }