diff options
Diffstat (limited to 'framework/src/onos/utils/misc/src/test/java/org/onlab/graph/SRLGGraphSearchTest.java')
-rw-r--r-- | framework/src/onos/utils/misc/src/test/java/org/onlab/graph/SRLGGraphSearchTest.java | 69 |
1 files changed, 30 insertions, 39 deletions
diff --git a/framework/src/onos/utils/misc/src/test/java/org/onlab/graph/SRLGGraphSearchTest.java b/framework/src/onos/utils/misc/src/test/java/org/onlab/graph/SRLGGraphSearchTest.java index 885fbe5c..8bfd270c 100644 --- a/framework/src/onos/utils/misc/src/test/java/org/onlab/graph/SRLGGraphSearchTest.java +++ b/framework/src/onos/utils/misc/src/test/java/org/onlab/graph/SRLGGraphSearchTest.java @@ -17,44 +17,37 @@ package org.onlab.graph; import org.junit.Test; -import java.util.Set; + +import java.util.HashMap; import java.util.HashSet; import java.util.Map; -import java.util.HashMap; +import java.util.Set; import static com.google.common.collect.ImmutableSet.of; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; - - +import static org.onlab.graph.GraphPathSearch.ALL_PATHS; /** * Test of the Suurballe backup path algorithm. */ public class SRLGGraphSearchTest extends BreadthFirstSearchTest { + @Override protected AbstractGraphPathSearch<TestVertex, TestEdge> graphSearch() { - return new SRLGGraphSearch<TestVertex, TestEdge>(null); + return new SRLGGraphSearch<>(null); } - public void setWeights() { - weight = new EdgeWeight<TestVertex, TestEdge>() { - @Override - public double weight(TestEdge edge) { - return edge.weight(); - } - }; - } public void setDefaultWeights() { weight = null; } + @Override public void defaultGraphTest() { - } @Override public void defaultHopCountWeight() { - } @Test @@ -66,34 +59,34 @@ public class SRLGGraphSearchTest extends BreadthFirstSearchTest { TestEdge dC = new TestEdge(D, C, 1); Graph<TestVertex, TestEdge> graph = new AdjacencyListsGraph<>(of(A, B, C, D), of(aB, bC, aD, dC)); - Map<TestEdge, Integer> riskProfile = new HashMap<TestEdge, Integer>(); + Map<TestEdge, Integer> riskProfile = new HashMap<>(); riskProfile.put(aB, 0); riskProfile.put(bC, 0); riskProfile.put(aD, 1); riskProfile.put(dC, 1); - SRLGGraphSearch<TestVertex, TestEdge> search = - new SRLGGraphSearch<TestVertex, TestEdge>(2, riskProfile); - Set<Path<TestVertex, TestEdge>> paths = search.search(graph, A, C, weight, GraphPathSearch.ALL_PATHS).paths(); + SRLGGraphSearch<TestVertex, TestEdge> search = new SRLGGraphSearch<>(2, riskProfile); + Set<Path<TestVertex, TestEdge>> paths = search.search(graph, A, C, weight, ALL_PATHS).paths(); System.out.println("\n\n\n" + paths + "\n\n\n"); - assertTrue("one disjoint path pair found", paths.size() == 1); + assertEquals("one disjoint path pair found", 1, paths.size()); checkIsDisjoint(paths.iterator().next(), riskProfile); } + public void checkIsDisjoint(Path<TestVertex, TestEdge> p, Map<TestEdge, Integer> risks) { assertTrue("The path is not a DisjointPathPair", (p instanceof DisjointPathPair)); DisjointPathPair<TestVertex, TestEdge> q = (DisjointPathPair) p; - Set<Integer> p1Risks = new HashSet<Integer>(); - Set<Integer> p2Risks = new HashSet<Integer>(); - for (TestEdge e: q.edges()) { + Set<Integer> p1Risks = new HashSet<>(); + for (TestEdge e : q.edges()) { p1Risks.add(risks.get(e)); } if (!q.hasBackup()) { return; } - Path<TestVertex, TestEdge> pq = q.path2; + Path<TestVertex, TestEdge> pq = q.secondary(); for (TestEdge e: pq.edges()) { assertTrue("The paths are not disjoint", !p1Risks.contains(risks.get(e))); } } + @Test public void complexGraphTest() { setDefaultWeights(); @@ -105,16 +98,15 @@ public class SRLGGraphSearchTest extends BreadthFirstSearchTest { TestEdge bE = new TestEdge(B, E, 1); Graph<TestVertex, TestEdge> graph = new AdjacencyListsGraph<>(of(A, B, C, D, E), of(aB, bC, aD, dC, cE, bE)); - Map<TestEdge, Integer> riskProfile = new HashMap<TestEdge, Integer>(); + Map<TestEdge, Integer> riskProfile = new HashMap<>(); riskProfile.put(aB, 0); riskProfile.put(bC, 0); riskProfile.put(aD, 1); riskProfile.put(dC, 1); riskProfile.put(cE, 2); riskProfile.put(bE, 3); - SRLGGraphSearch<TestVertex, TestEdge> search = - new SRLGGraphSearch<TestVertex, TestEdge>(4, riskProfile); - Set<Path<TestVertex, TestEdge>> paths = search.search(graph, A, E, weight, GraphPathSearch.ALL_PATHS).paths(); + SRLGGraphSearch<TestVertex, TestEdge> search = new SRLGGraphSearch<>(4, riskProfile); + search.search(graph, A, E, weight, ALL_PATHS).paths(); } @Test @@ -128,19 +120,19 @@ public class SRLGGraphSearchTest extends BreadthFirstSearchTest { TestEdge cE = new TestEdge(C, E, 1); Graph<TestVertex, TestEdge> graph = new AdjacencyListsGraph<>(of(A, B, C, D, E), of(aB, bE, aD, dE, aC, cE)); - Map<TestEdge, Integer> riskProfile = new HashMap<TestEdge, Integer>(); + Map<TestEdge, Integer> riskProfile = new HashMap<>(); riskProfile.put(aB, 0); riskProfile.put(bE, 1); riskProfile.put(aD, 2); riskProfile.put(dE, 3); riskProfile.put(aC, 4); riskProfile.put(cE, 5); - SRLGGraphSearch<TestVertex, TestEdge> search = - new SRLGGraphSearch<TestVertex, TestEdge>(6, riskProfile); - Set<Path<TestVertex, TestEdge>> paths = search.search(graph, A, E, weight, GraphPathSearch.ALL_PATHS).paths(); + SRLGGraphSearch<TestVertex, TestEdge> search = new SRLGGraphSearch<>(6, riskProfile); + Set<Path<TestVertex, TestEdge>> paths = search.search(graph, A, E, weight, ALL_PATHS).paths(); assertTrue("> one disjoint path pair found", paths.size() >= 1); checkIsDisjoint(paths.iterator().next(), riskProfile); } + @Test public void onePath() { setDefaultWeights(); @@ -150,17 +142,17 @@ public class SRLGGraphSearchTest extends BreadthFirstSearchTest { TestEdge dC = new TestEdge(D, C, 1); Graph<TestVertex, TestEdge> graph = new AdjacencyListsGraph<>(of(A, B, C, D), of(aB, bC, aD, dC)); - Map<TestEdge, Integer> riskProfile = new HashMap<TestEdge, Integer>(); + Map<TestEdge, Integer> riskProfile = new HashMap<>(); riskProfile.put(aB, 0); riskProfile.put(bC, 0); riskProfile.put(aD, 1); riskProfile.put(dC, 0); - SRLGGraphSearch<TestVertex, TestEdge> search = - new SRLGGraphSearch<TestVertex, TestEdge>(2, riskProfile); - Set<Path<TestVertex, TestEdge>> paths = search.search(graph, A, C, weight, GraphPathSearch.ALL_PATHS).paths(); + SRLGGraphSearch<TestVertex, TestEdge> search = new SRLGGraphSearch<>(2, riskProfile); + Set<Path<TestVertex, TestEdge>> paths = search.search(graph, A, C, weight, ALL_PATHS).paths(); System.out.println(paths); assertTrue("no disjoint path pairs found", paths.size() == 0); } + @Test public void noPath() { setDefaultWeights(); @@ -175,9 +167,8 @@ public class SRLGGraphSearchTest extends BreadthFirstSearchTest { riskProfile.put(bC, 0); riskProfile.put(aD, 1); riskProfile.put(dC, 0); - SRLGGraphSearch<TestVertex, TestEdge> search = - new SRLGGraphSearch<>(2, riskProfile); - Set<Path<TestVertex, TestEdge>> paths = search.search(graph, A, E, weight, GraphPathSearch.ALL_PATHS).paths(); + SRLGGraphSearch<TestVertex, TestEdge> search = new SRLGGraphSearch<>(2, riskProfile); + Set<Path<TestVertex, TestEdge>> paths = search.search(graph, A, E, weight, ALL_PATHS).paths(); assertTrue("no disjoint path pairs found", paths.size() == 0); } } |