mirror of
https://github.com/gonum/gonum.git
synced 2025-10-06 23:52:47 +08:00
graph: make graph analysis routines safe for indeterminate iterators
This is a change in design for the graph.NodesOf family of functions. The alternative was to provide an equivalent set of non-panicking routines in graph for internal use. The protection that was intended with the panic was to panic early rather than late when an indeterminate iterator exhausts slice index space. I think in hindsight this was an error and we should let things blow up in that (likely rare) situation. The majority of changes are in test code. Outside the iterator package, which is intimately tied to the determined iterator implementations, only one test now fails if an indeterminate iterator is used, product's Modular extended sub-graph isomorphism example, which is an algorithm that would have time complexity issues with large iterators anyway.
This commit is contained in:
@@ -28,7 +28,7 @@ var complementTests = []struct {
|
||||
|
||||
func TestComplement(t *testing.T) {
|
||||
for _, test := range complementTests {
|
||||
n := test.g.Nodes().Len()
|
||||
n := len(graph.NodesOf(test.g.Nodes()))
|
||||
wantM := n * (n - 1) // Double counting edges, but no self-loops.
|
||||
|
||||
var gotM int
|
||||
@@ -72,6 +72,10 @@ var nodeFilterIteratorTests = []struct {
|
||||
func TestNodeFilterIterator(t *testing.T) {
|
||||
for _, test := range nodeFilterIteratorTests {
|
||||
it := graph.NewNodeFilterIterator(test.src, test.filter, test.root)
|
||||
if it.Len() < 0 {
|
||||
t.Logf("don't test indeterminate iterators: %T", it)
|
||||
continue
|
||||
}
|
||||
for i := 0; i < 2; i++ {
|
||||
n := it.Len()
|
||||
if n != test.len {
|
||||
|
Reference in New Issue
Block a user