修改iterator ToHead ToTail的实现, 和使用方法.

This commit is contained in:
huangsimin
2020-03-18 11:44:27 +08:00
parent 239cb3c189
commit b34134e22f
15 changed files with 248 additions and 37 deletions

View File

@@ -152,7 +152,14 @@ func TestTreeSet_Iterator(t *testing.T) {
iter := set.Iterator()
iter.ToHead()
// 3 4 5
// if not call Next Prev will error
// 5 4 3
// if iter.Value() != nil {
// t.Error(iter.Value())
// }
iter.Next()
if iter.Value() != 3 {
t.Error(iter.Value())
}
@@ -162,12 +169,8 @@ func TestTreeSet_Iterator(t *testing.T) {
t.Error(iter.Value())
}
iter.Next()
if iter.Value() != 5 {
t.Error(iter.Value())
}
iter.ToTail()
iter.Prev()
if iter.Value() != 5 {
t.Error(iter.Value())
}
@@ -176,4 +179,16 @@ func TestTreeSet_Iterator(t *testing.T) {
if iter.Value() != 4 {
t.Error(iter.Value())
}
iter.ToHead()
iter.Prev()
if iter.Value() != 3 {
t.Error(iter.Value())
}
iter.ToTail()
iter.Next()
if iter.Value() != 5 {
t.Error(iter.Value())
}
}