mirror of
https://github.com/gonum/gonum.git
synced 2025-10-07 16:11:03 +08:00
graph/iterator: extend iteration tests and fix counting error
This commit is contained in:
@@ -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.
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user