graph/iterator: extend iteration tests and fix counting error
MODIFY
graph/iterator/nodes.go
graph/iterator/nodes.go
@@ -24,10 +24,7 @@ func (n *OrderedNodes) Len() int {
if n.idx >= len(n.nodes) {
return 0
}
- if n.idx <= 0 {
- return len(n.nodes)
- }
- return len(n.nodes[n.idx:])
+ return len(n.nodes[n.idx+1:])
}
// Next returns whether the next call of Node will return a valid node.

MODIFY
graph/iterator/nodes_test.go
graph/iterator/nodes_test.go
@@ -34,6 +34,9 @@ func TestOrderedNodesIterate(t *testing.T) {
var got []graph.Node
for it.Next() {
got = append(got, it.Node())
+ if len(got)+it.Len() != len(test.nodes) {
+ t.Errorf("unexpected iterator length during iteration for round %d: got:%d want:%d", i, it.Len(), len(test.nodes)-len(got))
+ }
}
want := test.nodes
if !reflect.DeepEqual(got, want) {
@@ -91,6 +94,9 @@ func TestImplicitNodesIterate(t *testing.T) {
var got []graph.Node
for it.Next() {
got = append(got, it.Node())
+ if len(got)+it.Len() != test.end-test.beg {
+ t.Errorf("unexpected iterator length during iteration for round %d: got:%d want:%d", i, it.Len(), (test.end-test.beg)-len(got))
+ }
}
if !reflect.DeepEqual(got, test.want) {
t.Errorf("unexpected iterator output for round %d: got:%#v want:%#v", i, got, test.want)

graph/iterator: extend iteration tests and fix counting error