I can't figure out what's going wrong here. This test fails:
@Test
public void testSimpleCase() {
assertTrue(JGraphtUtilities.graphEquality(ChooseRootTest.generateSimpleCaseGraph(), ChooseRootTest.generateSimpleCaseGraph()));
}
public static <V, E> boolean graphEquality(Graph<V, E> g0, Graph<V, E> g1) {
boolean result = true;
if (g0.edgeSet().equals(g1.edgeSet()) && g0.vertexSet().equals(g1.vertexSet())) {
for (E e : g0.edgeSet()) {
if (g0.getEdgeWeight(e) != g1.getEdgeWeight(e)) {
result = false;
}
}
}
else {
return false; //for the above test, this is what is returned
}
return result;
}
The debugger shows that the method decides that the two vertex sets and edge sets aren't equal, so it returns false. How is this possible?
Side note: I'm trying to write an equality check for JGraphT graphs. How is it possible that this hasn't been done already?
UPDATE: I think that DefaultWeightedEdge doesn't override equals, so that wouldn't work. I did a different way of checking that edges exist between all necessary vertices, and now it seems to work.