From 5e75797cdab66c268eed6cb240a49b240edc207e Mon Sep 17 00:00:00 2001 From: Yohan Simard Date: Sun, 31 May 2020 20:26:42 +0200 Subject: [PATCH] Better tests for the square map --- .../shortestpath/ShortestPathTest.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/be-graphes-algos/src/test/java/org/insa/graphs/algorithm/shortestpath/ShortestPathTest.java b/be-graphes-algos/src/test/java/org/insa/graphs/algorithm/shortestpath/ShortestPathTest.java index 5a28beb..e089e4c 100644 --- a/be-graphes-algos/src/test/java/org/insa/graphs/algorithm/shortestpath/ShortestPathTest.java +++ b/be-graphes-algos/src/test/java/org/insa/graphs/algorithm/shortestpath/ShortestPathTest.java @@ -66,15 +66,21 @@ public abstract class ShortestPathTest { assertTrue(sol.isFeasible()); Path path = sol.getPath(); assertTrue(path.isValid()); - // skip these tests for the square map where there may be several arcs with the same cost + // check the optimality locally + if (arcInspector == arcInspectors[0]) + assertEquals(path, Path.createShortestPathFromNodes(data.getGraph(), path.getNodes())); + if (arcInspector == arcInspectors[1]) + assertEquals(path, Path.createFastestPathFromNodes(data.getGraph(), path.getNodes())); + + // skip this test for the square map where there may be several paths with the same cost if (i != 0) { - // check the optimality locally - if (arcInspector == arcInspectors[0]) - assertEquals(path, Path.createShortestPathFromNodes(data.getGraph(), path.getNodes())); - if (arcInspector == arcInspectors[1]) - assertEquals(path, Path.createFastestPathFromNodes(data.getGraph(), path.getNodes())); // Check result against Bellman Ford algorithm assertEquals(sol.getPath(), oracle.getPath()); + } else { // in the square map case, compare only the costs + if (arcInspector == arcInspectors[0]) + assertEquals(sol.getPath().getLength(), oracle.getPath().getLength(), 1e-5); + if (arcInspector == arcInspectors[1]) + assertEquals(sol.getPath().getMinimumTravelTime(), oracle.getPath().getMinimumTravelTime(), 1e-1); } } }