unique iterator implementation

This commit is contained in:
Barak Michener 2015-04-26 17:23:29 -04:00
parent 7fa20fc306
commit 890f1b69f4
3 changed files with 195 additions and 0 deletions

View file

@ -0,0 +1,31 @@
package iterator
import (
"reflect"
"testing"
)
func TestUniqueIteratorBasics(t *testing.T) {
allIt := NewFixed(Identity)
allIt.Add(1)
allIt.Add(2)
allIt.Add(3)
allIt.Add(3)
allIt.Add(2)
u := NewUnique(allIt)
expect := []int{1, 2, 3}
for i := 0; i < 2; i++ {
if got := iterated(u); !reflect.DeepEqual(got, expect) {
t.Errorf("Failed to iterate Unique correctly on repeat %d: got:%v expected:%v", i, got, expect)
}
u.Reset()
}
for _, v := range []int{1, 2, 3} {
if !u.Contains(v) {
t.Errorf("Failed to find a correct value in the unique iterator.")
}
}
}