jung
jung copied to clipboard
fix flaky test(testDAG) under TestMinimumSpanningTree
Hi, edu.uci.ics.jung.algorithms.shortestpath.TestMinimumSpanningTree.testDAG is expressing a non-deterministic behavior under NonDex(https://github.com/TestingResearchIllinois/NonDex), because MinimumSpanningTree is using hashset & hashmap for implementation. Thus the fix would be replacing hash-components with tree-components, which ensure the deterministic order. Please let me know if there are any problems or you want to discuss more about this fix.
Good catch--thanks!
However, you need to use LinkedHashSet
and LinkedHashMap
to guarantee that it would work in general, because the Tree
classes assume that the nodes have a natural ordering. Because the nodes used in the tests happen to have that property, it works fine there, but it would break code elsewhere.
If convenient, please update your patch; otherwise I'll take care of it.
Hi, I changed TreeSet & TreeMap to LinkedHashSet & LinkedHashMap. However, this change will fail the maven test (TestMinimumSpanningTree.testDAG). Not sure what caused the problem.
Hmm. I don't have time to look into this tonight in detail, but let me know if you spot the problem. What's the error you're seeing?
Hi jrtom: Here is the log I got:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running edu.uci.ics.jung.algorithms.shortestpath.TestMinimumSpanningTree
graph.nodes()[B0, A, B1]
mst.nodes()[B0, B1, A]
graph.edges()[0, 1]
mst.edges()[]
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.13 sec <<< FAILURE!
.......
.......
.......
Results :
Failed tests: testDAG(edu.uci.ics.jung.algorithms.shortestpath.TestMinimumSpanningTree): **expected:<[0, 1]> but was:<[]>**
Thanks for your suggested fix. It turns out that there was an additional fix needed, which I supplied in #263, so this patch is no longer needed, but I appreciate you lending a hand. :)