unique iterator implementation
This commit is contained in:
parent
7fa20fc306
commit
890f1b69f4
3 changed files with 195 additions and 0 deletions
31
graph/iterator/unique_iterator_test.go
Normal file
31
graph/iterator/unique_iterator_test.go
Normal 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.")
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue