graph/iterator: fix Len for depleted ImplicitNodesIterator
MODIFY
graph/iterator/nodes.go
graph/iterator/nodes.go
@@ -389,6 +389,9 @@ func NewImplicitNodes(beg, end int, new func(id int) graph.Node) *ImplicitNodes
// Len returns the remaining number of nodes to be iterated over.
func (n *ImplicitNodes) Len() int {
+ if n.end <= n.curr {
+ return 0
+ }
return n.end - n.curr - 1
}

MODIFY
graph/iterator/nodes_test.go
graph/iterator/nodes_test.go
@@ -98,6 +98,9 @@ func TestImplicitNodesIterate(t *testing.T) {
t.Errorf("unexpected iterator length during iteration for round %d: got:%d want:%d", i, it.Len(), (test.end-test.beg)-len(got))
}
}
+ if it.Len() != 0 {
+ t.Errorf("unexpected depleted iterator length for round %d: got:%d want:0", i, it.Len())
+ }
if !reflect.DeepEqual(got, test.want) {
t.Errorf("unexpected iterator output for round %d: got:%#v want:%#v", i, got, test.want)
}

graph/iterator: fix Len for depleted ImplicitNodesIterator