36 lines
532 B
Go
36 lines
532 B
Go
package avlkeydup
|
|
|
|
import (
|
|
"sort"
|
|
"testing"
|
|
|
|
"github.com/474420502/focus/compare"
|
|
)
|
|
|
|
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])
|
|
}
|
|
}
|
|
}
|