2020-03-18 08:27:34 +00:00
|
|
|
package avlkey
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sort"
|
|
|
|
"testing"
|
|
|
|
|
2020-03-21 00:43:29 +00:00
|
|
|
"focus/compare"
|
2020-03-18 08:27:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestIerator(t *testing.T) {
|
|
|
|
tree := New(compare.Int)
|
|
|
|
l := []int{5, 10, 100, 30, 40, 70, 45, 35, 23}
|
|
|
|
for _, v := range l {
|
|
|
|
tree.Put(v, v)
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.Ints(l)
|
|
|
|
|
|
|
|
iter := tree.Iterator()
|
|
|
|
iter.ToHead()
|
|
|
|
for i := 0; iter.Next(); i++ {
|
|
|
|
|
|
|
|
if iter.Value() != l[i] {
|
|
|
|
t.Error(iter.Value(), l[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
iter.ToTail()
|
|
|
|
iter.Prev()
|
|
|
|
for i := len(l) - 1; iter.Next(); i-- {
|
|
|
|
|
|
|
|
if iter.Value() != l[i] {
|
|
|
|
t.Error(iter.Value(), l[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|