is the order of print_graph guarateed to be the same?

@szhorvat
It’s in tests/unit/test_utilities.inc . It uses IGRAPH_FROM(graph, i), IGRAPH_TO(graph, i), which use the from and to fields of the igraph_s struct. These don’t seem to have a guaranteed order. If so, tests could fail in the future if internals change, even though the correct graph is printed.

The order of the edges should be preserved regardless of the exact implementation of igraph_t. Internally, there are some sorted indices, but this does not (and should not) affect the actual edge index.

Ah, I think I asked the wrong question.

If I call igraph_small with two different edge orders, they also print out differently, I should have just checked that:

directed: true
vcount: 3
edges: {
0 1
0 2
}
directed: true
vcount: 3
edges: {
0 2
0 1
}

But suppose I am now testing igraph_full_citation for example. If I use print_graph to check it’s output, and at some point igraph_full_citation changes internally to output the edges in a different order, the test fails, even though nothing’s wrong. This would be prevented by ordering the output.

So my suggestion would be to order the output of print_graph so tests are more stable. Or am I missing something?

1 Like

Yes, this is a good suggestion. I’ll look into it.

Something related: I also want to add a new public function that verifies that two graphs are the same (not isomorphic, but having exactly the same edges, i.e. 1-2, 2-3 and 2-3, 1-2 are the same, but 1-3, 3-2 is different). I briefly discussed this with @tamas about a month ago.

That would also solve my current issue completely :slight_smile:

@GroteGnoom I have now added a function, print_graph_canon(), that outputs the graph in a canonical representation.

Something unrelated: You might be interested in looking at code coverage reports, Generating test coverage reports · igraph/igraph Wiki · GitHub

1 Like