diff --git a/java/server/src/test/java/org/softwareheritage/graph/AllowedEdgesTest.java b/java/server/src/test/java/org/softwareheritage/graph/AllowedEdgesTest.java index 66c633e..523a7f6 100644 --- a/java/server/src/test/java/org/softwareheritage/graph/AllowedEdgesTest.java +++ b/java/server/src/test/java/org/softwareheritage/graph/AllowedEdgesTest.java @@ -1,121 +1,121 @@ package org.softwareheritage.graph; import java.util.ArrayList; import org.junit.Test; import org.junit.Assert; import org.softwareheritage.graph.AllowedEdges; import org.softwareheritage.graph.GraphTest; import org.softwareheritage.graph.Node; public class AllowedEdgesTest extends GraphTest { - class EdgeType { - Node.Type src; - Node.Type dst; + class EdgeType { + Node.Type src; + Node.Type dst; - public EdgeType(Node.Type src, Node.Type dst) { - this.src = src; - this.dst = dst; - } + public EdgeType(Node.Type src, Node.Type dst) { + this.src = src; + this.dst = dst; + } - @Override - public boolean equals(Object otherObj) { - if (otherObj == this) return true; - if (!(otherObj instanceof EdgeType)) return false; + @Override + public boolean equals(Object otherObj) { + if (otherObj == this) return true; + if (!(otherObj instanceof EdgeType)) return false; - EdgeType other = (EdgeType) otherObj; - return src == other.src && dst == other.dst; + EdgeType other = (EdgeType) otherObj; + return src == other.src && dst == other.dst; + } } - } - - void assertEdgeRestriction(AllowedEdges edges, ArrayList expectedAllowed) { - Node.Type[] nodeTypes = Node.Type.values(); - for (Node.Type src : nodeTypes) { - for (Node.Type dst : nodeTypes) { - EdgeType edge = new EdgeType(src, dst); - boolean isAllowed = edges.isAllowed(src, dst); - boolean isExpected = false; - for (EdgeType expected : expectedAllowed) { - if (expected.equals(edge)) { - isExpected = true; - break; - } + + void assertEdgeRestriction(AllowedEdges edges, ArrayList expectedAllowed) { + Node.Type[] nodeTypes = Node.Type.values(); + for (Node.Type src : nodeTypes) { + for (Node.Type dst : nodeTypes) { + EdgeType edge = new EdgeType(src, dst); + boolean isAllowed = edges.isAllowed(src, dst); + boolean isExpected = false; + for (EdgeType expected : expectedAllowed) { + if (expected.equals(edge)) { + isExpected = true; + break; + } + } + + Assert.assertTrue("Edge type: " + src + " -> " + dst, isAllowed == isExpected); + } } + } + + @Test + public void dirToDirDirToCntEdges() { + Graph graph = getGraph(); + AllowedEdges edges = new AllowedEdges(graph, "dir:dir,dir:cnt"); + ArrayList expected = new ArrayList<>(); + expected.add(new EdgeType(Node.Type.DIR, Node.Type.DIR)); + expected.add(new EdgeType(Node.Type.DIR, Node.Type.CNT)); + assertEdgeRestriction(edges, expected); + } + + @Test + public void relToRevRevToRevRevToDirEdges() { + Graph graph = getGraph(); + AllowedEdges edges = new AllowedEdges(graph, "rel:rev,rev:rev,rev:dir"); + ArrayList expected = new ArrayList<>(); + expected.add(new EdgeType(Node.Type.REL, Node.Type.REV)); + expected.add(new EdgeType(Node.Type.REV, Node.Type.REV)); + expected.add(new EdgeType(Node.Type.REV, Node.Type.DIR)); + assertEdgeRestriction(edges, expected); + } - Assert.assertTrue("Edge type: " + src + " -> " + dst, isAllowed == isExpected); - } + @Test + public void revToAllDirToDirEdges() { + Graph graph = getGraph(); + AllowedEdges edges = new AllowedEdges(graph, "rev:*,dir:dir"); + ArrayList expected = new ArrayList<>(); + for (Node.Type dst : Node.Type.values()) { + expected.add(new EdgeType(Node.Type.REV, dst)); + } + expected.add(new EdgeType(Node.Type.DIR, Node.Type.DIR)); + assertEdgeRestriction(edges, expected); } - } - - @Test - public void dirToDirDirToCntEdges() { - Graph graph = getGraph(); - AllowedEdges edges = new AllowedEdges(graph, "dir:dir,dir:cnt"); - ArrayList expected = new ArrayList<>(); - expected.add(new EdgeType(Node.Type.DIR, Node.Type.DIR)); - expected.add(new EdgeType(Node.Type.DIR, Node.Type.CNT)); - assertEdgeRestriction(edges, expected); - } - - @Test - public void relToRevRevToRevRevToDirEdges() { - Graph graph = getGraph(); - AllowedEdges edges = new AllowedEdges(graph, "rel:rev,rev:rev,rev:dir"); - ArrayList expected = new ArrayList<>(); - expected.add(new EdgeType(Node.Type.REL, Node.Type.REV)); - expected.add(new EdgeType(Node.Type.REV, Node.Type.REV)); - expected.add(new EdgeType(Node.Type.REV, Node.Type.DIR)); - assertEdgeRestriction(edges, expected); - } - - @Test - public void revToAllDirToDirEdges() { - Graph graph = getGraph(); - AllowedEdges edges = new AllowedEdges(graph, "rev:*,dir:dir"); - ArrayList expected = new ArrayList<>(); - for (Node.Type dst : Node.Type.values()) { - expected.add(new EdgeType(Node.Type.REV, dst)); + + @Test + public void allToCntEdges() { + Graph graph = getGraph(); + AllowedEdges edges = new AllowedEdges(graph, "*:cnt"); + ArrayList expected = new ArrayList<>(); + for (Node.Type src : Node.Type.values()) { + expected.add(new EdgeType(src, Node.Type.CNT)); + } + assertEdgeRestriction(edges, expected); } - expected.add(new EdgeType(Node.Type.DIR, Node.Type.DIR)); - assertEdgeRestriction(edges, expected); - } - - @Test - public void allToCntEdges() { - Graph graph = getGraph(); - AllowedEdges edges = new AllowedEdges(graph, "*:cnt"); - ArrayList expected = new ArrayList<>(); - for (Node.Type src : Node.Type.values()) { - expected.add(new EdgeType(src, Node.Type.CNT)); + + @Test + public void allEdges() { + Graph graph = getGraph(); + AllowedEdges edges = new AllowedEdges(graph, "*:*"); + ArrayList expected = new ArrayList<>(); + for (Node.Type src : Node.Type.values()) { + for (Node.Type dst : Node.Type.values()) { + expected.add(new EdgeType(src, dst)); + } + } + assertEdgeRestriction(edges, expected); + + // Special null value used to quickly bypass edge check when no restriction + AllowedEdges edges2 = new AllowedEdges(graph, "*"); + Assert.assertNull(edges2.restrictedTo); } - assertEdgeRestriction(edges, expected); - } - - @Test - public void allEdges() { - Graph graph = getGraph(); - AllowedEdges edges = new AllowedEdges(graph, "*:*"); - ArrayList expected = new ArrayList<>(); - for (Node.Type src : Node.Type.values()) { - for (Node.Type dst : Node.Type.values()) { - expected.add(new EdgeType(src, dst)); - } + + @Test + public void noEdges() { + Graph graph = getGraph(); + AllowedEdges edges = new AllowedEdges(graph, ""); + AllowedEdges edges2 = new AllowedEdges(graph, null); + ArrayList expected = new ArrayList<>(); + assertEdgeRestriction(edges, expected); + assertEdgeRestriction(edges2, expected); } - assertEdgeRestriction(edges, expected); - - // Special null value used to quickly bypass edge check when no restriction - AllowedEdges edges2 = new AllowedEdges(graph, "*"); - Assert.assertNull(edges2.restrictedTo); - } - - @Test - public void noEdges() { - Graph graph = getGraph(); - AllowedEdges edges = new AllowedEdges(graph, ""); - AllowedEdges edges2 = new AllowedEdges(graph, null); - ArrayList expected = new ArrayList<>(); - assertEdgeRestriction(edges, expected); - assertEdgeRestriction(edges2, expected); - } } diff --git a/java/server/src/test/java/org/softwareheritage/graph/GraphTest.java b/java/server/src/test/java/org/softwareheritage/graph/GraphTest.java index 8ba1d07..b58a540 100644 --- a/java/server/src/test/java/org/softwareheritage/graph/GraphTest.java +++ b/java/server/src/test/java/org/softwareheritage/graph/GraphTest.java @@ -1,30 +1,30 @@ package org.softwareheritage.graph; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Collection; import org.junit.Assert; import org.junit.BeforeClass; import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; import org.softwareheritage.graph.Graph; public class GraphTest { - static Graph graph; + static Graph graph; - public static void assertEqualsAnyOrder(Collection expecteds, Collection actuals) { - Assert.assertThat(expecteds, containsInAnyOrder(actuals.toArray())); - } + public static void assertEqualsAnyOrder(Collection expecteds, Collection actuals) { + Assert.assertThat(expecteds, containsInAnyOrder(actuals.toArray())); + } - @BeforeClass - public static void setUp() throws IOException { - Path graphPath = Paths.get("src", "test", "dataset", "output", "example"); - graph = new Graph(graphPath.toString()); - } + @BeforeClass + public static void setUp() throws IOException { + Path graphPath = Paths.get("src", "test", "dataset", "output", "example"); + graph = new Graph(graphPath.toString()); + } - public Graph getGraph() { - return graph; - } + public Graph getGraph() { + return graph; + } } diff --git a/java/server/src/test/java/org/softwareheritage/graph/LeavesTest.java b/java/server/src/test/java/org/softwareheritage/graph/LeavesTest.java index 45e32e3..44792e1 100644 --- a/java/server/src/test/java/org/softwareheritage/graph/LeavesTest.java +++ b/java/server/src/test/java/org/softwareheritage/graph/LeavesTest.java @@ -1,111 +1,111 @@ package org.softwareheritage.graph; import java.util.ArrayList; import org.junit.Test; import org.softwareheritage.graph.Endpoint; import org.softwareheritage.graph.Graph; import org.softwareheritage.graph.GraphTest; import org.softwareheritage.graph.SwhPID; // Avoid warnings concerning Endpoint.Output.result manual cast @SuppressWarnings("unchecked") public class LeavesTest extends GraphTest { - @Test - public void forwardFromSnp() { - Graph graph = getGraph(); - SwhPID src = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); - Endpoint endpoint = new Endpoint(graph, "forward", "*"); - - ArrayList expectedLeaves = new ArrayList<>(); - expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001")); - expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004")); - expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000005")); - expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007")); - - ArrayList actualLeaves = (ArrayList) endpoint.leaves(new Endpoint.Input(src)).result; - GraphTest.assertEqualsAnyOrder(expectedLeaves, actualLeaves); - } - - @Test - public void forwardFromRel() { - Graph graph = getGraph(); - SwhPID src = new SwhPID("swh:1:rel:0000000000000000000000000000000000000019"); - Endpoint endpoint = new Endpoint(graph, "forward", "*"); - - ArrayList expectedLeaves = new ArrayList<>(); - expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000015")); - expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000014")); - expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001")); - expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004")); - expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000005")); - expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007")); - expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000011")); - - ArrayList actualLeaves = (ArrayList) endpoint.leaves(new Endpoint.Input(src)).result; - GraphTest.assertEqualsAnyOrder(expectedLeaves, actualLeaves); - } - - @Test - public void backwardFromLeaf() { - Graph graph = getGraph(); - - Endpoint endpoint1 = new Endpoint(graph, "backward", "*"); - SwhPID src1 = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000015"); - ArrayList expectedLeaves1 = new ArrayList<>(); - expectedLeaves1.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000019")); - ArrayList actualLeaves1 = (ArrayList) endpoint1.leaves(new Endpoint.Input(src1)).result; - GraphTest.assertEqualsAnyOrder(expectedLeaves1, actualLeaves1); - - Endpoint endpoint2 = new Endpoint(graph, "backward", "*"); - SwhPID src2 = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004"); - ArrayList expectedLeaves2 = new ArrayList<>(); - expectedLeaves2.add(new SwhPID("swh:1:ori:0000000000000000000000000000000000000021")); - expectedLeaves2.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000019")); - ArrayList actualLeaves2 = (ArrayList) endpoint2.leaves(new Endpoint.Input(src2)).result; - GraphTest.assertEqualsAnyOrder(expectedLeaves2, actualLeaves2); - } - - @Test - public void forwardRevToRevOnly() { - Graph graph = getGraph(); - SwhPID src = new SwhPID("swh:1:rev:0000000000000000000000000000000000000018"); - Endpoint endpoint = new Endpoint(graph, "forward", "rev:rev"); - - ArrayList expectedLeaves = new ArrayList<>(); - expectedLeaves.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000003")); - - ArrayList actualLeaves = (ArrayList) endpoint.leaves(new Endpoint.Input(src)).result; - GraphTest.assertEqualsAnyOrder(expectedLeaves, actualLeaves); - } - - @Test - public void forwardDirToAll() { - Graph graph = getGraph(); - SwhPID src = new SwhPID("swh:1:dir:0000000000000000000000000000000000000008"); - Endpoint endpoint = new Endpoint(graph, "forward", "dir:*"); - - ArrayList expectedLeaves = new ArrayList<>(); - expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004")); - expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000005")); - expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001")); - expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007")); - - ArrayList actualLeaves = (ArrayList) endpoint.leaves(new Endpoint.Input(src)).result; - GraphTest.assertEqualsAnyOrder(expectedLeaves, actualLeaves); - } - - @Test - public void backwardCntToDirDirToDir() { - Graph graph = getGraph(); - SwhPID src = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000005"); - Endpoint endpoint = new Endpoint(graph, "backward", "cnt:dir,dir:dir"); - - ArrayList expectedLeaves = new ArrayList<>(); - expectedLeaves.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000012")); - - ArrayList actualLeaves = (ArrayList) endpoint.leaves(new Endpoint.Input(src)).result; - GraphTest.assertEqualsAnyOrder(expectedLeaves, actualLeaves); - } + @Test + public void forwardFromSnp() { + Graph graph = getGraph(); + SwhPID src = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); + Endpoint endpoint = new Endpoint(graph, "forward", "*"); + + ArrayList expectedLeaves = new ArrayList<>(); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001")); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004")); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000005")); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007")); + + ArrayList actualLeaves = (ArrayList) endpoint.leaves(new Endpoint.Input(src)).result; + GraphTest.assertEqualsAnyOrder(expectedLeaves, actualLeaves); + } + + @Test + public void forwardFromRel() { + Graph graph = getGraph(); + SwhPID src = new SwhPID("swh:1:rel:0000000000000000000000000000000000000019"); + Endpoint endpoint = new Endpoint(graph, "forward", "*"); + + ArrayList expectedLeaves = new ArrayList<>(); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000015")); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000014")); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001")); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004")); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000005")); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007")); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000011")); + + ArrayList actualLeaves = (ArrayList) endpoint.leaves(new Endpoint.Input(src)).result; + GraphTest.assertEqualsAnyOrder(expectedLeaves, actualLeaves); + } + + @Test + public void backwardFromLeaf() { + Graph graph = getGraph(); + + Endpoint endpoint1 = new Endpoint(graph, "backward", "*"); + SwhPID src1 = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000015"); + ArrayList expectedLeaves1 = new ArrayList<>(); + expectedLeaves1.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000019")); + ArrayList actualLeaves1 = (ArrayList) endpoint1.leaves(new Endpoint.Input(src1)).result; + GraphTest.assertEqualsAnyOrder(expectedLeaves1, actualLeaves1); + + Endpoint endpoint2 = new Endpoint(graph, "backward", "*"); + SwhPID src2 = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004"); + ArrayList expectedLeaves2 = new ArrayList<>(); + expectedLeaves2.add(new SwhPID("swh:1:ori:0000000000000000000000000000000000000021")); + expectedLeaves2.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000019")); + ArrayList actualLeaves2 = (ArrayList) endpoint2.leaves(new Endpoint.Input(src2)).result; + GraphTest.assertEqualsAnyOrder(expectedLeaves2, actualLeaves2); + } + + @Test + public void forwardRevToRevOnly() { + Graph graph = getGraph(); + SwhPID src = new SwhPID("swh:1:rev:0000000000000000000000000000000000000018"); + Endpoint endpoint = new Endpoint(graph, "forward", "rev:rev"); + + ArrayList expectedLeaves = new ArrayList<>(); + expectedLeaves.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000003")); + + ArrayList actualLeaves = (ArrayList) endpoint.leaves(new Endpoint.Input(src)).result; + GraphTest.assertEqualsAnyOrder(expectedLeaves, actualLeaves); + } + + @Test + public void forwardDirToAll() { + Graph graph = getGraph(); + SwhPID src = new SwhPID("swh:1:dir:0000000000000000000000000000000000000008"); + Endpoint endpoint = new Endpoint(graph, "forward", "dir:*"); + + ArrayList expectedLeaves = new ArrayList<>(); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004")); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000005")); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001")); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007")); + + ArrayList actualLeaves = (ArrayList) endpoint.leaves(new Endpoint.Input(src)).result; + GraphTest.assertEqualsAnyOrder(expectedLeaves, actualLeaves); + } + + @Test + public void backwardCntToDirDirToDir() { + Graph graph = getGraph(); + SwhPID src = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000005"); + Endpoint endpoint = new Endpoint(graph, "backward", "cnt:dir,dir:dir"); + + ArrayList expectedLeaves = new ArrayList<>(); + expectedLeaves.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000012")); + + ArrayList actualLeaves = (ArrayList) endpoint.leaves(new Endpoint.Input(src)).result; + GraphTest.assertEqualsAnyOrder(expectedLeaves, actualLeaves); + } } diff --git a/java/server/src/test/java/org/softwareheritage/graph/NeighborsTest.java b/java/server/src/test/java/org/softwareheritage/graph/NeighborsTest.java index bbb393c..98336a9 100644 --- a/java/server/src/test/java/org/softwareheritage/graph/NeighborsTest.java +++ b/java/server/src/test/java/org/softwareheritage/graph/NeighborsTest.java @@ -1,145 +1,145 @@ package org.softwareheritage.graph; import java.util.ArrayList; import org.junit.Test; import org.softwareheritage.graph.Endpoint; import org.softwareheritage.graph.Graph; import org.softwareheritage.graph.GraphTest; import org.softwareheritage.graph.SwhPID; // Avoid warnings concerning Endpoint.Output.result manual cast @SuppressWarnings("unchecked") public class NeighborsTest extends GraphTest { - @Test - public void zeroNeighbor() { - Graph graph = getGraph(); - ArrayList expectedNodes = new ArrayList<>(); - - SwhPID src1 = new SwhPID("swh:1:ori:0000000000000000000000000000000000000021"); - Endpoint endpoint1 = new Endpoint(graph, "backward", "*"); - ArrayList actuals1 = (ArrayList) endpoint1.neighbors(new Endpoint.Input(src1)).result; - GraphTest.assertEqualsAnyOrder(expectedNodes, actuals1); - - SwhPID src2 = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004"); - Endpoint endpoint2 = new Endpoint(graph, "forward", "*"); - ArrayList actuals2 = (ArrayList) endpoint2.neighbors(new Endpoint.Input(src2)).result; - GraphTest.assertEqualsAnyOrder(expectedNodes, actuals2); - - SwhPID src3 = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000015"); - Endpoint endpoint3 = new Endpoint(graph, "forward", "*"); - ArrayList actuals3 = (ArrayList) endpoint3.neighbors(new Endpoint.Input(src3)).result; - GraphTest.assertEqualsAnyOrder(expectedNodes, actuals3); - - SwhPID src4 = new SwhPID("swh:1:rel:0000000000000000000000000000000000000019"); - Endpoint endpoint4 = new Endpoint(graph, "backward", "*"); - ArrayList actuals4 = (ArrayList) endpoint4.neighbors(new Endpoint.Input(src4)).result; - GraphTest.assertEqualsAnyOrder(expectedNodes, actuals4); - - SwhPID src5 = new SwhPID("swh:1:dir:0000000000000000000000000000000000000008"); - Endpoint endpoint5 = new Endpoint(graph, "forward", "snp:*,rev:*,rel:*"); - ArrayList actuals5 = (ArrayList) endpoint5.neighbors(new Endpoint.Input(src5)).result; - GraphTest.assertEqualsAnyOrder(expectedNodes, actuals5); - } - - @Test - public void oneNeighbor() { - Graph graph = getGraph(); - - SwhPID src1 = new SwhPID("swh:1:rev:0000000000000000000000000000000000000003"); - Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); - ArrayList expectedNodes1 = new ArrayList<>(); - expectedNodes1.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000002")); - ArrayList actuals1 = (ArrayList) endpoint1.neighbors(new Endpoint.Input(src1)).result; - GraphTest.assertEqualsAnyOrder(expectedNodes1, actuals1); - - SwhPID src2 = new SwhPID("swh:1:dir:0000000000000000000000000000000000000017"); - Endpoint endpoint2 = new Endpoint(graph, "forward", "dir:cnt"); - ArrayList expectedNodes2 = new ArrayList<>(); - expectedNodes2.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000014")); - ArrayList actuals2 = (ArrayList) endpoint2.neighbors(new Endpoint.Input(src2)).result; - GraphTest.assertEqualsAnyOrder(expectedNodes2, actuals2); - - SwhPID src3 = new SwhPID("swh:1:dir:0000000000000000000000000000000000000012"); - Endpoint endpoint3 = new Endpoint(graph, "backward", "*"); - ArrayList expectedNodes3 = new ArrayList<>(); - expectedNodes3.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000013")); - ArrayList actuals3 = (ArrayList) endpoint3.neighbors(new Endpoint.Input(src3)).result; - GraphTest.assertEqualsAnyOrder(expectedNodes3, actuals3); - - SwhPID src4 = new SwhPID("swh:1:rev:0000000000000000000000000000000000000009"); - Endpoint endpoint4 = new Endpoint(graph, "backward", "rev:rev"); - ArrayList expectedNodes4 = new ArrayList<>(); - expectedNodes4.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000013")); - ArrayList actuals4 = (ArrayList) endpoint4.neighbors(new Endpoint.Input(src4)).result; - GraphTest.assertEqualsAnyOrder(expectedNodes4, actuals4); - - SwhPID src5 = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); - Endpoint endpoint5 = new Endpoint(graph, "backward", "*"); - ArrayList expectedNodes5 = new ArrayList<>(); - expectedNodes5.add(new SwhPID("swh:1:ori:0000000000000000000000000000000000000021")); - ArrayList actuals5 = (ArrayList) endpoint5.neighbors(new Endpoint.Input(src5)).result; - GraphTest.assertEqualsAnyOrder(expectedNodes5, actuals5); - } - - @Test - public void twoNeighbors() { - Graph graph = getGraph(); - - SwhPID src1 = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); - Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); - ArrayList expectedNodes1 = new ArrayList<>(); - expectedNodes1.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000010")); - expectedNodes1.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000009")); - ArrayList actuals1 = (ArrayList) endpoint1.neighbors(new Endpoint.Input(src1)).result; - GraphTest.assertEqualsAnyOrder(expectedNodes1, actuals1); - - SwhPID src2 = new SwhPID("swh:1:dir:0000000000000000000000000000000000000008"); - Endpoint endpoint2 = new Endpoint(graph, "forward", "dir:cnt"); - ArrayList expectedNodes2 = new ArrayList<>(); - expectedNodes2.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001")); - expectedNodes2.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007")); - ArrayList actuals2 = (ArrayList) endpoint2.neighbors(new Endpoint.Input(src2)).result; - GraphTest.assertEqualsAnyOrder(expectedNodes2, actuals2); - - SwhPID src3 = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001"); - Endpoint endpoint3 = new Endpoint(graph, "backward", "*"); - ArrayList expectedNodes3 = new ArrayList<>(); - expectedNodes3.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000008")); - expectedNodes3.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000002")); - ArrayList actuals3 = (ArrayList) endpoint3.neighbors(new Endpoint.Input(src3)).result; - GraphTest.assertEqualsAnyOrder(expectedNodes3, actuals3); - - SwhPID src4 = new SwhPID("swh:1:rev:0000000000000000000000000000000000000009"); - Endpoint endpoint4 = new Endpoint(graph, "backward", "rev:snp,rev:rel"); - ArrayList expectedNodes4 = new ArrayList<>(); - expectedNodes4.add(new SwhPID("swh:1:snp:0000000000000000000000000000000000000020")); - expectedNodes4.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000010")); - ArrayList actuals4 = (ArrayList) endpoint4.neighbors(new Endpoint.Input(src4)).result; - GraphTest.assertEqualsAnyOrder(expectedNodes4, actuals4); - } - - @Test - public void threeNeighbors() { - Graph graph = getGraph(); - - SwhPID src1 = new SwhPID("swh:1:dir:0000000000000000000000000000000000000008"); - Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); - ArrayList expectedNodes1 = new ArrayList<>(); - expectedNodes1.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000006")); - expectedNodes1.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001")); - expectedNodes1.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007")); - ArrayList actuals1 = (ArrayList) endpoint1.neighbors(new Endpoint.Input(src1)).result; - GraphTest.assertEqualsAnyOrder(expectedNodes1, actuals1); - - SwhPID src2 = new SwhPID("swh:1:rev:0000000000000000000000000000000000000009"); - Endpoint endpoint2 = new Endpoint(graph, "backward", "*"); - ArrayList expectedNodes2 = new ArrayList<>(); - expectedNodes2.add(new SwhPID("swh:1:snp:0000000000000000000000000000000000000020")); - expectedNodes2.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000010")); - expectedNodes2.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000013")); - ArrayList actuals2 = (ArrayList) endpoint2.neighbors(new Endpoint.Input(src2)).result; - GraphTest.assertEqualsAnyOrder(expectedNodes2, actuals2); - } + @Test + public void zeroNeighbor() { + Graph graph = getGraph(); + ArrayList expectedNodes = new ArrayList<>(); + + SwhPID src1 = new SwhPID("swh:1:ori:0000000000000000000000000000000000000021"); + Endpoint endpoint1 = new Endpoint(graph, "backward", "*"); + ArrayList actuals1 = (ArrayList) endpoint1.neighbors(new Endpoint.Input(src1)).result; + GraphTest.assertEqualsAnyOrder(expectedNodes, actuals1); + + SwhPID src2 = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004"); + Endpoint endpoint2 = new Endpoint(graph, "forward", "*"); + ArrayList actuals2 = (ArrayList) endpoint2.neighbors(new Endpoint.Input(src2)).result; + GraphTest.assertEqualsAnyOrder(expectedNodes, actuals2); + + SwhPID src3 = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000015"); + Endpoint endpoint3 = new Endpoint(graph, "forward", "*"); + ArrayList actuals3 = (ArrayList) endpoint3.neighbors(new Endpoint.Input(src3)).result; + GraphTest.assertEqualsAnyOrder(expectedNodes, actuals3); + + SwhPID src4 = new SwhPID("swh:1:rel:0000000000000000000000000000000000000019"); + Endpoint endpoint4 = new Endpoint(graph, "backward", "*"); + ArrayList actuals4 = (ArrayList) endpoint4.neighbors(new Endpoint.Input(src4)).result; + GraphTest.assertEqualsAnyOrder(expectedNodes, actuals4); + + SwhPID src5 = new SwhPID("swh:1:dir:0000000000000000000000000000000000000008"); + Endpoint endpoint5 = new Endpoint(graph, "forward", "snp:*,rev:*,rel:*"); + ArrayList actuals5 = (ArrayList) endpoint5.neighbors(new Endpoint.Input(src5)).result; + GraphTest.assertEqualsAnyOrder(expectedNodes, actuals5); + } + + @Test + public void oneNeighbor() { + Graph graph = getGraph(); + + SwhPID src1 = new SwhPID("swh:1:rev:0000000000000000000000000000000000000003"); + Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); + ArrayList expectedNodes1 = new ArrayList<>(); + expectedNodes1.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000002")); + ArrayList actuals1 = (ArrayList) endpoint1.neighbors(new Endpoint.Input(src1)).result; + GraphTest.assertEqualsAnyOrder(expectedNodes1, actuals1); + + SwhPID src2 = new SwhPID("swh:1:dir:0000000000000000000000000000000000000017"); + Endpoint endpoint2 = new Endpoint(graph, "forward", "dir:cnt"); + ArrayList expectedNodes2 = new ArrayList<>(); + expectedNodes2.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000014")); + ArrayList actuals2 = (ArrayList) endpoint2.neighbors(new Endpoint.Input(src2)).result; + GraphTest.assertEqualsAnyOrder(expectedNodes2, actuals2); + + SwhPID src3 = new SwhPID("swh:1:dir:0000000000000000000000000000000000000012"); + Endpoint endpoint3 = new Endpoint(graph, "backward", "*"); + ArrayList expectedNodes3 = new ArrayList<>(); + expectedNodes3.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000013")); + ArrayList actuals3 = (ArrayList) endpoint3.neighbors(new Endpoint.Input(src3)).result; + GraphTest.assertEqualsAnyOrder(expectedNodes3, actuals3); + + SwhPID src4 = new SwhPID("swh:1:rev:0000000000000000000000000000000000000009"); + Endpoint endpoint4 = new Endpoint(graph, "backward", "rev:rev"); + ArrayList expectedNodes4 = new ArrayList<>(); + expectedNodes4.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000013")); + ArrayList actuals4 = (ArrayList) endpoint4.neighbors(new Endpoint.Input(src4)).result; + GraphTest.assertEqualsAnyOrder(expectedNodes4, actuals4); + + SwhPID src5 = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); + Endpoint endpoint5 = new Endpoint(graph, "backward", "*"); + ArrayList expectedNodes5 = new ArrayList<>(); + expectedNodes5.add(new SwhPID("swh:1:ori:0000000000000000000000000000000000000021")); + ArrayList actuals5 = (ArrayList) endpoint5.neighbors(new Endpoint.Input(src5)).result; + GraphTest.assertEqualsAnyOrder(expectedNodes5, actuals5); + } + + @Test + public void twoNeighbors() { + Graph graph = getGraph(); + + SwhPID src1 = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); + Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); + ArrayList expectedNodes1 = new ArrayList<>(); + expectedNodes1.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000010")); + expectedNodes1.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000009")); + ArrayList actuals1 = (ArrayList) endpoint1.neighbors(new Endpoint.Input(src1)).result; + GraphTest.assertEqualsAnyOrder(expectedNodes1, actuals1); + + SwhPID src2 = new SwhPID("swh:1:dir:0000000000000000000000000000000000000008"); + Endpoint endpoint2 = new Endpoint(graph, "forward", "dir:cnt"); + ArrayList expectedNodes2 = new ArrayList<>(); + expectedNodes2.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001")); + expectedNodes2.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007")); + ArrayList actuals2 = (ArrayList) endpoint2.neighbors(new Endpoint.Input(src2)).result; + GraphTest.assertEqualsAnyOrder(expectedNodes2, actuals2); + + SwhPID src3 = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001"); + Endpoint endpoint3 = new Endpoint(graph, "backward", "*"); + ArrayList expectedNodes3 = new ArrayList<>(); + expectedNodes3.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000008")); + expectedNodes3.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000002")); + ArrayList actuals3 = (ArrayList) endpoint3.neighbors(new Endpoint.Input(src3)).result; + GraphTest.assertEqualsAnyOrder(expectedNodes3, actuals3); + + SwhPID src4 = new SwhPID("swh:1:rev:0000000000000000000000000000000000000009"); + Endpoint endpoint4 = new Endpoint(graph, "backward", "rev:snp,rev:rel"); + ArrayList expectedNodes4 = new ArrayList<>(); + expectedNodes4.add(new SwhPID("swh:1:snp:0000000000000000000000000000000000000020")); + expectedNodes4.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000010")); + ArrayList actuals4 = (ArrayList) endpoint4.neighbors(new Endpoint.Input(src4)).result; + GraphTest.assertEqualsAnyOrder(expectedNodes4, actuals4); + } + + @Test + public void threeNeighbors() { + Graph graph = getGraph(); + + SwhPID src1 = new SwhPID("swh:1:dir:0000000000000000000000000000000000000008"); + Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); + ArrayList expectedNodes1 = new ArrayList<>(); + expectedNodes1.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000006")); + expectedNodes1.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001")); + expectedNodes1.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007")); + ArrayList actuals1 = (ArrayList) endpoint1.neighbors(new Endpoint.Input(src1)).result; + GraphTest.assertEqualsAnyOrder(expectedNodes1, actuals1); + + SwhPID src2 = new SwhPID("swh:1:rev:0000000000000000000000000000000000000009"); + Endpoint endpoint2 = new Endpoint(graph, "backward", "*"); + ArrayList expectedNodes2 = new ArrayList<>(); + expectedNodes2.add(new SwhPID("swh:1:snp:0000000000000000000000000000000000000020")); + expectedNodes2.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000010")); + expectedNodes2.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000013")); + ArrayList actuals2 = (ArrayList) endpoint2.neighbors(new Endpoint.Input(src2)).result; + GraphTest.assertEqualsAnyOrder(expectedNodes2, actuals2); + } } diff --git a/java/server/src/test/java/org/softwareheritage/graph/VisitTest.java b/java/server/src/test/java/org/softwareheritage/graph/VisitTest.java index fff3a28..3fde78c 100644 --- a/java/server/src/test/java/org/softwareheritage/graph/VisitTest.java +++ b/java/server/src/test/java/org/softwareheritage/graph/VisitTest.java @@ -1,547 +1,547 @@ package org.softwareheritage.graph; import java.util.ArrayList; import java.util.Set; import java.util.HashSet; import org.junit.Test; import org.softwareheritage.graph.Endpoint; import org.softwareheritage.graph.Graph; import org.softwareheritage.graph.GraphTest; import org.softwareheritage.graph.SwhPID; import org.softwareheritage.graph.SwhPath; // Avoid warnings concerning Endpoint.Output.result manual cast @SuppressWarnings("unchecked") public class VisitTest extends GraphTest { - private void assertSameNodesFromPaths(ArrayList paths, ArrayList nodes) { - Set expectedNodes = new HashSet(); - for (SwhPath path : paths) { - for (SwhPID node : path.getPath()) { - expectedNodes.add(node); - } + private void assertSameNodesFromPaths(ArrayList paths, ArrayList nodes) { + Set expectedNodes = new HashSet(); + for (SwhPath path : paths) { + for (SwhPID node : path.getPath()) { + expectedNodes.add(node); + } + } + GraphTest.assertEqualsAnyOrder(expectedNodes, nodes); + } + + @Test + public void forwardFromRoot() { + Graph graph = getGraph(); + SwhPID swhPID = new SwhPID("swh:1:ori:0000000000000000000000000000000000000021"); + Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); + ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhPID)).result; + Endpoint endpoint2 = new Endpoint(graph, "forward", "*"); + ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhPID)).result; + + ArrayList expectedPaths = new ArrayList(); + expectedPaths.add( + new SwhPath( + "swh:1:ori:0000000000000000000000000000000000000021", + "swh:1:snp:0000000000000000000000000000000000000020", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:cnt:0000000000000000000000000000000000000007" + )); + expectedPaths.add( + new SwhPath( + "swh:1:ori:0000000000000000000000000000000000000021", + "swh:1:snp:0000000000000000000000000000000000000020", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:cnt:0000000000000000000000000000000000000001" + )); + expectedPaths.add( + new SwhPath( + "swh:1:ori:0000000000000000000000000000000000000021", + "swh:1:snp:0000000000000000000000000000000000000020", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:dir:0000000000000000000000000000000000000006", + "swh:1:cnt:0000000000000000000000000000000000000004" + )); + expectedPaths.add( + new SwhPath( + "swh:1:ori:0000000000000000000000000000000000000021", + "swh:1:snp:0000000000000000000000000000000000000020", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:dir:0000000000000000000000000000000000000006", + "swh:1:cnt:0000000000000000000000000000000000000005" + )); + expectedPaths.add( + new SwhPath( + "swh:1:ori:0000000000000000000000000000000000000021", + "swh:1:snp:0000000000000000000000000000000000000020", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:rev:0000000000000000000000000000000000000003", + "swh:1:dir:0000000000000000000000000000000000000002", + "swh:1:cnt:0000000000000000000000000000000000000001" + )); + expectedPaths.add( + new SwhPath( + "swh:1:ori:0000000000000000000000000000000000000021", + "swh:1:snp:0000000000000000000000000000000000000020", + "swh:1:rel:0000000000000000000000000000000000000010", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:cnt:0000000000000000000000000000000000000007" + )); + expectedPaths.add( + new SwhPath( + "swh:1:ori:0000000000000000000000000000000000000021", + "swh:1:snp:0000000000000000000000000000000000000020", + "swh:1:rel:0000000000000000000000000000000000000010", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:cnt:0000000000000000000000000000000000000001" + )); + expectedPaths.add( + new SwhPath( + "swh:1:ori:0000000000000000000000000000000000000021", + "swh:1:snp:0000000000000000000000000000000000000020", + "swh:1:rel:0000000000000000000000000000000000000010", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:dir:0000000000000000000000000000000000000006", + "swh:1:cnt:0000000000000000000000000000000000000004" + )); + expectedPaths.add( + new SwhPath( + "swh:1:ori:0000000000000000000000000000000000000021", + "swh:1:snp:0000000000000000000000000000000000000020", + "swh:1:rel:0000000000000000000000000000000000000010", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:dir:0000000000000000000000000000000000000006", + "swh:1:cnt:0000000000000000000000000000000000000005" + )); + expectedPaths.add( + new SwhPath( + "swh:1:ori:0000000000000000000000000000000000000021", + "swh:1:snp:0000000000000000000000000000000000000020", + "swh:1:rel:0000000000000000000000000000000000000010", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:rev:0000000000000000000000000000000000000003", + "swh:1:dir:0000000000000000000000000000000000000002", + "swh:1:cnt:0000000000000000000000000000000000000001" + )); + + GraphTest.assertEqualsAnyOrder(expectedPaths, paths); + assertSameNodesFromPaths(expectedPaths, nodes); + } + + @Test + public void forwardFromMiddle() { + Graph graph = getGraph(); + SwhPID swhPID = new SwhPID("swh:1:dir:0000000000000000000000000000000000000012"); + Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); + ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhPID)).result; + Endpoint endpoint2 = new Endpoint(graph, "forward", "*"); + ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhPID)).result; + + ArrayList expectedPaths = new ArrayList(); + expectedPaths.add( + new SwhPath( + "swh:1:dir:0000000000000000000000000000000000000012", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:cnt:0000000000000000000000000000000000000007" + )); + expectedPaths.add( + new SwhPath( + "swh:1:dir:0000000000000000000000000000000000000012", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:cnt:0000000000000000000000000000000000000001" + )); + expectedPaths.add( + new SwhPath( + "swh:1:dir:0000000000000000000000000000000000000012", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:dir:0000000000000000000000000000000000000006", + "swh:1:cnt:0000000000000000000000000000000000000004" + )); + expectedPaths.add( + new SwhPath( + "swh:1:dir:0000000000000000000000000000000000000012", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:dir:0000000000000000000000000000000000000006", + "swh:1:cnt:0000000000000000000000000000000000000005" + )); + expectedPaths.add( + new SwhPath( + "swh:1:dir:0000000000000000000000000000000000000012", + "swh:1:cnt:0000000000000000000000000000000000000011" + )); + + GraphTest.assertEqualsAnyOrder(expectedPaths, paths); + assertSameNodesFromPaths(expectedPaths, nodes); + } + + @Test + public void forwardFromLeaf() { + Graph graph = getGraph(); + SwhPID swhPID = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004"); + Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); + ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhPID)).result; + Endpoint endpoint2 = new Endpoint(graph, "forward", "*"); + ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhPID)).result; + + ArrayList expectedPaths = new ArrayList(); + expectedPaths.add( + new SwhPath( + "swh:1:cnt:0000000000000000000000000000000000000004" + )); + + GraphTest.assertEqualsAnyOrder(expectedPaths, paths); + assertSameNodesFromPaths(expectedPaths, nodes); + } + + @Test + public void backwardFromRoot() { + Graph graph = getGraph(); + SwhPID swhPID = new SwhPID("swh:1:ori:0000000000000000000000000000000000000021"); + Endpoint endpoint1 = new Endpoint(graph, "backward", "*"); + ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhPID)).result; + Endpoint endpoint2 = new Endpoint(graph, "backward", "*"); + ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhPID)).result; + + ArrayList expectedPaths = new ArrayList(); + expectedPaths.add( + new SwhPath( + "swh:1:ori:0000000000000000000000000000000000000021" + )); + + GraphTest.assertEqualsAnyOrder(expectedPaths, paths); + assertSameNodesFromPaths(expectedPaths, nodes); + } + + @Test + public void backwardFromMiddle() { + Graph graph = getGraph(); + SwhPID swhPID = new SwhPID("swh:1:dir:0000000000000000000000000000000000000012"); + Endpoint endpoint1 = new Endpoint(graph, "backward", "*"); + ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhPID)).result; + Endpoint endpoint2 = new Endpoint(graph, "backward", "*"); + ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhPID)).result; + + ArrayList expectedPaths = new ArrayList(); + expectedPaths.add( + new SwhPath( + "swh:1:dir:0000000000000000000000000000000000000012", + "swh:1:rev:0000000000000000000000000000000000000013", + "swh:1:rev:0000000000000000000000000000000000000018", + "swh:1:rel:0000000000000000000000000000000000000019" + )); + + GraphTest.assertEqualsAnyOrder(expectedPaths, paths); + assertSameNodesFromPaths(expectedPaths, nodes); + } + + @Test + public void backwardFromLeaf() { + Graph graph = getGraph(); + SwhPID swhPID = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004"); + Endpoint endpoint1 = new Endpoint(graph, "backward", "*"); + ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhPID)).result; + Endpoint endpoint2 = new Endpoint(graph, "backward", "*"); + ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhPID)).result; + + ArrayList expectedPaths = new ArrayList(); + expectedPaths.add( + new SwhPath( + "swh:1:cnt:0000000000000000000000000000000000000004", + "swh:1:dir:0000000000000000000000000000000000000006", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:dir:0000000000000000000000000000000000000012", + "swh:1:rev:0000000000000000000000000000000000000013", + "swh:1:rev:0000000000000000000000000000000000000018", + "swh:1:rel:0000000000000000000000000000000000000019" + )); + expectedPaths.add( + new SwhPath( + "swh:1:cnt:0000000000000000000000000000000000000004", + "swh:1:dir:0000000000000000000000000000000000000006", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:rev:0000000000000000000000000000000000000013", + "swh:1:rev:0000000000000000000000000000000000000018", + "swh:1:rel:0000000000000000000000000000000000000019" + )); + expectedPaths.add( + new SwhPath( + "swh:1:cnt:0000000000000000000000000000000000000004", + "swh:1:dir:0000000000000000000000000000000000000006", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:snp:0000000000000000000000000000000000000020", + "swh:1:ori:0000000000000000000000000000000000000021" + )); + expectedPaths.add( + new SwhPath( + "swh:1:cnt:0000000000000000000000000000000000000004", + "swh:1:dir:0000000000000000000000000000000000000006", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:rel:0000000000000000000000000000000000000010", + "swh:1:snp:0000000000000000000000000000000000000020", + "swh:1:ori:0000000000000000000000000000000000000021" + )); + + GraphTest.assertEqualsAnyOrder(expectedPaths, paths); + assertSameNodesFromPaths(expectedPaths, nodes); + } + + @Test + public void forwardSnpToRev() { + Graph graph = getGraph(); + SwhPID swhPID = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); + Endpoint endpoint1 = new Endpoint(graph, "forward", "snp:rev"); + ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhPID)).result; + Endpoint endpoint2 = new Endpoint(graph, "forward", "snp:rev"); + ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhPID)).result; + + ArrayList expectedPaths = new ArrayList(); + expectedPaths.add( + new SwhPath( + "swh:1:snp:0000000000000000000000000000000000000020", + "swh:1:rev:0000000000000000000000000000000000000009" + )); + + GraphTest.assertEqualsAnyOrder(expectedPaths, paths); + assertSameNodesFromPaths(expectedPaths, nodes); + } + + @Test + public void forwardRelToRevRevToRev() { + Graph graph = getGraph(); + SwhPID swhPID = new SwhPID("swh:1:rel:0000000000000000000000000000000000000010"); + Endpoint endpoint1 = new Endpoint(graph, "forward", "rel:rev,rev:rev"); + ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhPID)).result; + Endpoint endpoint2 = new Endpoint(graph, "forward", "rel:rev,rev:rev"); + ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhPID)).result; + + ArrayList expectedPaths = new ArrayList(); + expectedPaths.add( + new SwhPath( + "swh:1:rel:0000000000000000000000000000000000000010", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:rev:0000000000000000000000000000000000000003" + )); + + GraphTest.assertEqualsAnyOrder(expectedPaths, paths); + assertSameNodesFromPaths(expectedPaths, nodes); + } + + @Test + public void forwardRevToAllDirToAll() { + Graph graph = getGraph(); + SwhPID swhPID = new SwhPID("swh:1:rev:0000000000000000000000000000000000000013"); + Endpoint endpoint1 = new Endpoint(graph, "forward", "rev:*,dir:*"); + ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhPID)).result; + Endpoint endpoint2 = new Endpoint(graph, "forward", "rev:*,dir:*"); + ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhPID)).result; + + ArrayList expectedPaths = new ArrayList(); + expectedPaths.add( + new SwhPath( + "swh:1:rev:0000000000000000000000000000000000000013", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:dir:0000000000000000000000000000000000000006", + "swh:1:cnt:0000000000000000000000000000000000000005" + )); + expectedPaths.add( + new SwhPath( + "swh:1:rev:0000000000000000000000000000000000000013", + "swh:1:dir:0000000000000000000000000000000000000012", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:dir:0000000000000000000000000000000000000006", + "swh:1:cnt:0000000000000000000000000000000000000005" + )); + expectedPaths.add( + new SwhPath( + "swh:1:rev:0000000000000000000000000000000000000013", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:dir:0000000000000000000000000000000000000006", + "swh:1:cnt:0000000000000000000000000000000000000004" + )); + expectedPaths.add( + new SwhPath( + "swh:1:rev:0000000000000000000000000000000000000013", + "swh:1:dir:0000000000000000000000000000000000000012", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:dir:0000000000000000000000000000000000000006", + "swh:1:cnt:0000000000000000000000000000000000000004" + )); + expectedPaths.add( + new SwhPath( + "swh:1:rev:0000000000000000000000000000000000000013", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:cnt:0000000000000000000000000000000000000007" + )); + expectedPaths.add( + new SwhPath( + "swh:1:rev:0000000000000000000000000000000000000013", + "swh:1:dir:0000000000000000000000000000000000000012", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:cnt:0000000000000000000000000000000000000007" + )); + expectedPaths.add( + new SwhPath( + "swh:1:rev:0000000000000000000000000000000000000013", + "swh:1:dir:0000000000000000000000000000000000000012", + "swh:1:cnt:0000000000000000000000000000000000000011" + )); + expectedPaths.add( + new SwhPath( + "swh:1:rev:0000000000000000000000000000000000000013", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:rev:0000000000000000000000000000000000000003", + "swh:1:dir:0000000000000000000000000000000000000002", + "swh:1:cnt:0000000000000000000000000000000000000001" + )); + expectedPaths.add( + new SwhPath( + "swh:1:rev:0000000000000000000000000000000000000013", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:cnt:0000000000000000000000000000000000000001" + )); + expectedPaths.add( + new SwhPath( + "swh:1:rev:0000000000000000000000000000000000000013", + "swh:1:dir:0000000000000000000000000000000000000012", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:cnt:0000000000000000000000000000000000000001" + )); + + GraphTest.assertEqualsAnyOrder(expectedPaths, paths); + assertSameNodesFromPaths(expectedPaths, nodes); + } + + @Test + public void forwardSnpToAllRevToAll() { + Graph graph = getGraph(); + SwhPID swhPID = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); + Endpoint endpoint1 = new Endpoint(graph, "forward", "snp:*,rev:*"); + ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhPID)).result; + Endpoint endpoint2 = new Endpoint(graph, "forward", "snp:*,rev:*"); + ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhPID)).result; + + ArrayList expectedPaths = new ArrayList(); + expectedPaths.add( + new SwhPath( + "swh:1:snp:0000000000000000000000000000000000000020", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:rev:0000000000000000000000000000000000000003", + "swh:1:dir:0000000000000000000000000000000000000002" + )); + expectedPaths.add( + new SwhPath( + "swh:1:snp:0000000000000000000000000000000000000020", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:dir:0000000000000000000000000000000000000008" + )); + expectedPaths.add( + new SwhPath( + "swh:1:snp:0000000000000000000000000000000000000020", + "swh:1:rel:0000000000000000000000000000000000000010" + )); + + GraphTest.assertEqualsAnyOrder(expectedPaths, paths); + assertSameNodesFromPaths(expectedPaths, nodes); + } + + @Test + public void forwardNoEdges() { + Graph graph = getGraph(); + SwhPID swhPID = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); + Endpoint endpoint1 = new Endpoint(graph, "forward", ""); + ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhPID)).result; + Endpoint endpoint2 = new Endpoint(graph, "forward", ""); + ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhPID)).result; + + ArrayList expectedPaths = new ArrayList(); + expectedPaths.add( + new SwhPath( + "swh:1:snp:0000000000000000000000000000000000000020" + )); + + GraphTest.assertEqualsAnyOrder(expectedPaths, paths); + assertSameNodesFromPaths(expectedPaths, nodes); + } + + @Test + public void backwardRevToRevRevToRel() { + Graph graph = getGraph(); + SwhPID swhPID = new SwhPID("swh:1:rev:0000000000000000000000000000000000000003"); + Endpoint endpoint1 = new Endpoint(graph, "backward", "rev:rev,rev:rel"); + ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhPID)).result; + Endpoint endpoint2 = new Endpoint(graph, "backward", "rev:rev,rev:rel"); + ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhPID)).result; + + ArrayList expectedPaths = new ArrayList(); + expectedPaths.add( + new SwhPath( + "swh:1:rev:0000000000000000000000000000000000000003", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:rev:0000000000000000000000000000000000000013", + "swh:1:rev:0000000000000000000000000000000000000018", + "swh:1:rel:0000000000000000000000000000000000000019" + )); + expectedPaths.add( + new SwhPath( + "swh:1:rev:0000000000000000000000000000000000000003", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:rel:0000000000000000000000000000000000000010" + )); + + GraphTest.assertEqualsAnyOrder(expectedPaths, paths); + assertSameNodesFromPaths(expectedPaths, nodes); + } + + @Test + public void forwardFromRootNodesOnly() { + Graph graph = getGraph(); + SwhPID swhPID = new SwhPID("swh:1:ori:0000000000000000000000000000000000000021"); + Endpoint endpoint = new Endpoint(graph, "forward", "*"); + ArrayList nodes = (ArrayList) endpoint.visitNodes(new Endpoint.Input(swhPID)).result; + + ArrayList expectedNodes = new ArrayList(); + expectedNodes.add(new SwhPID("swh:1:ori:0000000000000000000000000000000000000021")); + expectedNodes.add(new SwhPID("swh:1:snp:0000000000000000000000000000000000000020")); + expectedNodes.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000010")); + expectedNodes.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000009")); + expectedNodes.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000003")); + expectedNodes.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000002")); + expectedNodes.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001")); + expectedNodes.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000008")); + expectedNodes.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000006")); + expectedNodes.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004")); + expectedNodes.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000005")); + expectedNodes.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007")); + + GraphTest.assertEqualsAnyOrder(expectedNodes, nodes); + } + + @Test + public void backwardRevToAllNodesOnly() { + Graph graph = getGraph(); + SwhPID swhPID = new SwhPID("swh:1:rev:0000000000000000000000000000000000000003"); + Endpoint endpoint = new Endpoint(graph, "backward", "rev:*"); + ArrayList nodes = (ArrayList) endpoint.visitNodes(new Endpoint.Input(swhPID)).result; + + ArrayList expectedNodes = new ArrayList(); + expectedNodes.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000003")); + expectedNodes.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000009")); + expectedNodes.add(new SwhPID("swh:1:snp:0000000000000000000000000000000000000020")); + expectedNodes.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000010")); + expectedNodes.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000013")); + expectedNodes.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000018")); + expectedNodes.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000019")); + + GraphTest.assertEqualsAnyOrder(expectedNodes, nodes); } - GraphTest.assertEqualsAnyOrder(expectedNodes, nodes); - } - - @Test - public void forwardFromRoot() { - Graph graph = getGraph(); - SwhPID swhPID = new SwhPID("swh:1:ori:0000000000000000000000000000000000000021"); - Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); - ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhPID)).result; - Endpoint endpoint2 = new Endpoint(graph, "forward", "*"); - ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhPID)).result; - - ArrayList expectedPaths = new ArrayList(); - expectedPaths.add( - new SwhPath( - "swh:1:ori:0000000000000000000000000000000000000021", - "swh:1:snp:0000000000000000000000000000000000000020", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:cnt:0000000000000000000000000000000000000007" - )); - expectedPaths.add( - new SwhPath( - "swh:1:ori:0000000000000000000000000000000000000021", - "swh:1:snp:0000000000000000000000000000000000000020", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:cnt:0000000000000000000000000000000000000001" - )); - expectedPaths.add( - new SwhPath( - "swh:1:ori:0000000000000000000000000000000000000021", - "swh:1:snp:0000000000000000000000000000000000000020", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:dir:0000000000000000000000000000000000000006", - "swh:1:cnt:0000000000000000000000000000000000000004" - )); - expectedPaths.add( - new SwhPath( - "swh:1:ori:0000000000000000000000000000000000000021", - "swh:1:snp:0000000000000000000000000000000000000020", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:dir:0000000000000000000000000000000000000006", - "swh:1:cnt:0000000000000000000000000000000000000005" - )); - expectedPaths.add( - new SwhPath( - "swh:1:ori:0000000000000000000000000000000000000021", - "swh:1:snp:0000000000000000000000000000000000000020", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:rev:0000000000000000000000000000000000000003", - "swh:1:dir:0000000000000000000000000000000000000002", - "swh:1:cnt:0000000000000000000000000000000000000001" - )); - expectedPaths.add( - new SwhPath( - "swh:1:ori:0000000000000000000000000000000000000021", - "swh:1:snp:0000000000000000000000000000000000000020", - "swh:1:rel:0000000000000000000000000000000000000010", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:cnt:0000000000000000000000000000000000000007" - )); - expectedPaths.add( - new SwhPath( - "swh:1:ori:0000000000000000000000000000000000000021", - "swh:1:snp:0000000000000000000000000000000000000020", - "swh:1:rel:0000000000000000000000000000000000000010", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:cnt:0000000000000000000000000000000000000001" - )); - expectedPaths.add( - new SwhPath( - "swh:1:ori:0000000000000000000000000000000000000021", - "swh:1:snp:0000000000000000000000000000000000000020", - "swh:1:rel:0000000000000000000000000000000000000010", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:dir:0000000000000000000000000000000000000006", - "swh:1:cnt:0000000000000000000000000000000000000004" - )); - expectedPaths.add( - new SwhPath( - "swh:1:ori:0000000000000000000000000000000000000021", - "swh:1:snp:0000000000000000000000000000000000000020", - "swh:1:rel:0000000000000000000000000000000000000010", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:dir:0000000000000000000000000000000000000006", - "swh:1:cnt:0000000000000000000000000000000000000005" - )); - expectedPaths.add( - new SwhPath( - "swh:1:ori:0000000000000000000000000000000000000021", - "swh:1:snp:0000000000000000000000000000000000000020", - "swh:1:rel:0000000000000000000000000000000000000010", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:rev:0000000000000000000000000000000000000003", - "swh:1:dir:0000000000000000000000000000000000000002", - "swh:1:cnt:0000000000000000000000000000000000000001" - )); - - GraphTest.assertEqualsAnyOrder(expectedPaths, paths); - assertSameNodesFromPaths(expectedPaths, nodes); - } - - @Test - public void forwardFromMiddle() { - Graph graph = getGraph(); - SwhPID swhPID = new SwhPID("swh:1:dir:0000000000000000000000000000000000000012"); - Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); - ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhPID)).result; - Endpoint endpoint2 = new Endpoint(graph, "forward", "*"); - ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhPID)).result; - - ArrayList expectedPaths = new ArrayList(); - expectedPaths.add( - new SwhPath( - "swh:1:dir:0000000000000000000000000000000000000012", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:cnt:0000000000000000000000000000000000000007" - )); - expectedPaths.add( - new SwhPath( - "swh:1:dir:0000000000000000000000000000000000000012", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:cnt:0000000000000000000000000000000000000001" - )); - expectedPaths.add( - new SwhPath( - "swh:1:dir:0000000000000000000000000000000000000012", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:dir:0000000000000000000000000000000000000006", - "swh:1:cnt:0000000000000000000000000000000000000004" - )); - expectedPaths.add( - new SwhPath( - "swh:1:dir:0000000000000000000000000000000000000012", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:dir:0000000000000000000000000000000000000006", - "swh:1:cnt:0000000000000000000000000000000000000005" - )); - expectedPaths.add( - new SwhPath( - "swh:1:dir:0000000000000000000000000000000000000012", - "swh:1:cnt:0000000000000000000000000000000000000011" - )); - - GraphTest.assertEqualsAnyOrder(expectedPaths, paths); - assertSameNodesFromPaths(expectedPaths, nodes); - } - - @Test - public void forwardFromLeaf() { - Graph graph = getGraph(); - SwhPID swhPID = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004"); - Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); - ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhPID)).result; - Endpoint endpoint2 = new Endpoint(graph, "forward", "*"); - ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhPID)).result; - - ArrayList expectedPaths = new ArrayList(); - expectedPaths.add( - new SwhPath( - "swh:1:cnt:0000000000000000000000000000000000000004" - )); - - GraphTest.assertEqualsAnyOrder(expectedPaths, paths); - assertSameNodesFromPaths(expectedPaths, nodes); - } - - @Test - public void backwardFromRoot() { - Graph graph = getGraph(); - SwhPID swhPID = new SwhPID("swh:1:ori:0000000000000000000000000000000000000021"); - Endpoint endpoint1 = new Endpoint(graph, "backward", "*"); - ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhPID)).result; - Endpoint endpoint2 = new Endpoint(graph, "backward", "*"); - ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhPID)).result; - - ArrayList expectedPaths = new ArrayList(); - expectedPaths.add( - new SwhPath( - "swh:1:ori:0000000000000000000000000000000000000021" - )); - - GraphTest.assertEqualsAnyOrder(expectedPaths, paths); - assertSameNodesFromPaths(expectedPaths, nodes); - } - - @Test - public void backwardFromMiddle() { - Graph graph = getGraph(); - SwhPID swhPID = new SwhPID("swh:1:dir:0000000000000000000000000000000000000012"); - Endpoint endpoint1 = new Endpoint(graph, "backward", "*"); - ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhPID)).result; - Endpoint endpoint2 = new Endpoint(graph, "backward", "*"); - ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhPID)).result; - - ArrayList expectedPaths = new ArrayList(); - expectedPaths.add( - new SwhPath( - "swh:1:dir:0000000000000000000000000000000000000012", - "swh:1:rev:0000000000000000000000000000000000000013", - "swh:1:rev:0000000000000000000000000000000000000018", - "swh:1:rel:0000000000000000000000000000000000000019" - )); - - GraphTest.assertEqualsAnyOrder(expectedPaths, paths); - assertSameNodesFromPaths(expectedPaths, nodes); - } - - @Test - public void backwardFromLeaf() { - Graph graph = getGraph(); - SwhPID swhPID = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004"); - Endpoint endpoint1 = new Endpoint(graph, "backward", "*"); - ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhPID)).result; - Endpoint endpoint2 = new Endpoint(graph, "backward", "*"); - ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhPID)).result; - - ArrayList expectedPaths = new ArrayList(); - expectedPaths.add( - new SwhPath( - "swh:1:cnt:0000000000000000000000000000000000000004", - "swh:1:dir:0000000000000000000000000000000000000006", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:dir:0000000000000000000000000000000000000012", - "swh:1:rev:0000000000000000000000000000000000000013", - "swh:1:rev:0000000000000000000000000000000000000018", - "swh:1:rel:0000000000000000000000000000000000000019" - )); - expectedPaths.add( - new SwhPath( - "swh:1:cnt:0000000000000000000000000000000000000004", - "swh:1:dir:0000000000000000000000000000000000000006", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:rev:0000000000000000000000000000000000000013", - "swh:1:rev:0000000000000000000000000000000000000018", - "swh:1:rel:0000000000000000000000000000000000000019" - )); - expectedPaths.add( - new SwhPath( - "swh:1:cnt:0000000000000000000000000000000000000004", - "swh:1:dir:0000000000000000000000000000000000000006", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:snp:0000000000000000000000000000000000000020", - "swh:1:ori:0000000000000000000000000000000000000021" - )); - expectedPaths.add( - new SwhPath( - "swh:1:cnt:0000000000000000000000000000000000000004", - "swh:1:dir:0000000000000000000000000000000000000006", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:rel:0000000000000000000000000000000000000010", - "swh:1:snp:0000000000000000000000000000000000000020", - "swh:1:ori:0000000000000000000000000000000000000021" - )); - - GraphTest.assertEqualsAnyOrder(expectedPaths, paths); - assertSameNodesFromPaths(expectedPaths, nodes); - } - - @Test - public void forwardSnpToRev() { - Graph graph = getGraph(); - SwhPID swhPID = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); - Endpoint endpoint1 = new Endpoint(graph, "forward", "snp:rev"); - ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhPID)).result; - Endpoint endpoint2 = new Endpoint(graph, "forward", "snp:rev"); - ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhPID)).result; - - ArrayList expectedPaths = new ArrayList(); - expectedPaths.add( - new SwhPath( - "swh:1:snp:0000000000000000000000000000000000000020", - "swh:1:rev:0000000000000000000000000000000000000009" - )); - - GraphTest.assertEqualsAnyOrder(expectedPaths, paths); - assertSameNodesFromPaths(expectedPaths, nodes); - } - - @Test - public void forwardRelToRevRevToRev() { - Graph graph = getGraph(); - SwhPID swhPID = new SwhPID("swh:1:rel:0000000000000000000000000000000000000010"); - Endpoint endpoint1 = new Endpoint(graph, "forward", "rel:rev,rev:rev"); - ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhPID)).result; - Endpoint endpoint2 = new Endpoint(graph, "forward", "rel:rev,rev:rev"); - ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhPID)).result; - - ArrayList expectedPaths = new ArrayList(); - expectedPaths.add( - new SwhPath( - "swh:1:rel:0000000000000000000000000000000000000010", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:rev:0000000000000000000000000000000000000003" - )); - - GraphTest.assertEqualsAnyOrder(expectedPaths, paths); - assertSameNodesFromPaths(expectedPaths, nodes); - } - - @Test - public void forwardRevToAllDirToAll() { - Graph graph = getGraph(); - SwhPID swhPID = new SwhPID("swh:1:rev:0000000000000000000000000000000000000013"); - Endpoint endpoint1 = new Endpoint(graph, "forward", "rev:*,dir:*"); - ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhPID)).result; - Endpoint endpoint2 = new Endpoint(graph, "forward", "rev:*,dir:*"); - ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhPID)).result; - - ArrayList expectedPaths = new ArrayList(); - expectedPaths.add( - new SwhPath( - "swh:1:rev:0000000000000000000000000000000000000013", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:dir:0000000000000000000000000000000000000006", - "swh:1:cnt:0000000000000000000000000000000000000005" - )); - expectedPaths.add( - new SwhPath( - "swh:1:rev:0000000000000000000000000000000000000013", - "swh:1:dir:0000000000000000000000000000000000000012", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:dir:0000000000000000000000000000000000000006", - "swh:1:cnt:0000000000000000000000000000000000000005" - )); - expectedPaths.add( - new SwhPath( - "swh:1:rev:0000000000000000000000000000000000000013", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:dir:0000000000000000000000000000000000000006", - "swh:1:cnt:0000000000000000000000000000000000000004" - )); - expectedPaths.add( - new SwhPath( - "swh:1:rev:0000000000000000000000000000000000000013", - "swh:1:dir:0000000000000000000000000000000000000012", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:dir:0000000000000000000000000000000000000006", - "swh:1:cnt:0000000000000000000000000000000000000004" - )); - expectedPaths.add( - new SwhPath( - "swh:1:rev:0000000000000000000000000000000000000013", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:cnt:0000000000000000000000000000000000000007" - )); - expectedPaths.add( - new SwhPath( - "swh:1:rev:0000000000000000000000000000000000000013", - "swh:1:dir:0000000000000000000000000000000000000012", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:cnt:0000000000000000000000000000000000000007" - )); - expectedPaths.add( - new SwhPath( - "swh:1:rev:0000000000000000000000000000000000000013", - "swh:1:dir:0000000000000000000000000000000000000012", - "swh:1:cnt:0000000000000000000000000000000000000011" - )); - expectedPaths.add( - new SwhPath( - "swh:1:rev:0000000000000000000000000000000000000013", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:rev:0000000000000000000000000000000000000003", - "swh:1:dir:0000000000000000000000000000000000000002", - "swh:1:cnt:0000000000000000000000000000000000000001" - )); - expectedPaths.add( - new SwhPath( - "swh:1:rev:0000000000000000000000000000000000000013", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:cnt:0000000000000000000000000000000000000001" - )); - expectedPaths.add( - new SwhPath( - "swh:1:rev:0000000000000000000000000000000000000013", - "swh:1:dir:0000000000000000000000000000000000000012", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:cnt:0000000000000000000000000000000000000001" - )); - - GraphTest.assertEqualsAnyOrder(expectedPaths, paths); - assertSameNodesFromPaths(expectedPaths, nodes); - } - - @Test - public void forwardSnpToAllRevToAll() { - Graph graph = getGraph(); - SwhPID swhPID = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); - Endpoint endpoint1 = new Endpoint(graph, "forward", "snp:*,rev:*"); - ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhPID)).result; - Endpoint endpoint2 = new Endpoint(graph, "forward", "snp:*,rev:*"); - ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhPID)).result; - - ArrayList expectedPaths = new ArrayList(); - expectedPaths.add( - new SwhPath( - "swh:1:snp:0000000000000000000000000000000000000020", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:rev:0000000000000000000000000000000000000003", - "swh:1:dir:0000000000000000000000000000000000000002" - )); - expectedPaths.add( - new SwhPath( - "swh:1:snp:0000000000000000000000000000000000000020", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:dir:0000000000000000000000000000000000000008" - )); - expectedPaths.add( - new SwhPath( - "swh:1:snp:0000000000000000000000000000000000000020", - "swh:1:rel:0000000000000000000000000000000000000010" - )); - - GraphTest.assertEqualsAnyOrder(expectedPaths, paths); - assertSameNodesFromPaths(expectedPaths, nodes); - } - - @Test - public void forwardNoEdges() { - Graph graph = getGraph(); - SwhPID swhPID = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); - Endpoint endpoint1 = new Endpoint(graph, "forward", ""); - ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhPID)).result; - Endpoint endpoint2 = new Endpoint(graph, "forward", ""); - ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhPID)).result; - - ArrayList expectedPaths = new ArrayList(); - expectedPaths.add( - new SwhPath( - "swh:1:snp:0000000000000000000000000000000000000020" - )); - - GraphTest.assertEqualsAnyOrder(expectedPaths, paths); - assertSameNodesFromPaths(expectedPaths, nodes); - } - - @Test - public void backwardRevToRevRevToRel() { - Graph graph = getGraph(); - SwhPID swhPID = new SwhPID("swh:1:rev:0000000000000000000000000000000000000003"); - Endpoint endpoint1 = new Endpoint(graph, "backward", "rev:rev,rev:rel"); - ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhPID)).result; - Endpoint endpoint2 = new Endpoint(graph, "backward", "rev:rev,rev:rel"); - ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhPID)).result; - - ArrayList expectedPaths = new ArrayList(); - expectedPaths.add( - new SwhPath( - "swh:1:rev:0000000000000000000000000000000000000003", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:rev:0000000000000000000000000000000000000013", - "swh:1:rev:0000000000000000000000000000000000000018", - "swh:1:rel:0000000000000000000000000000000000000019" - )); - expectedPaths.add( - new SwhPath( - "swh:1:rev:0000000000000000000000000000000000000003", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:rel:0000000000000000000000000000000000000010" - )); - - GraphTest.assertEqualsAnyOrder(expectedPaths, paths); - assertSameNodesFromPaths(expectedPaths, nodes); - } - - @Test - public void forwardFromRootNodesOnly() { - Graph graph = getGraph(); - SwhPID swhPID = new SwhPID("swh:1:ori:0000000000000000000000000000000000000021"); - Endpoint endpoint = new Endpoint(graph, "forward", "*"); - ArrayList nodes = (ArrayList) endpoint.visitNodes(new Endpoint.Input(swhPID)).result; - - ArrayList expectedNodes = new ArrayList(); - expectedNodes.add(new SwhPID("swh:1:ori:0000000000000000000000000000000000000021")); - expectedNodes.add(new SwhPID("swh:1:snp:0000000000000000000000000000000000000020")); - expectedNodes.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000010")); - expectedNodes.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000009")); - expectedNodes.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000003")); - expectedNodes.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000002")); - expectedNodes.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001")); - expectedNodes.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000008")); - expectedNodes.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000006")); - expectedNodes.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004")); - expectedNodes.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000005")); - expectedNodes.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007")); - - GraphTest.assertEqualsAnyOrder(expectedNodes, nodes); - } - - @Test - public void backwardRevToAllNodesOnly() { - Graph graph = getGraph(); - SwhPID swhPID = new SwhPID("swh:1:rev:0000000000000000000000000000000000000003"); - Endpoint endpoint = new Endpoint(graph, "backward", "rev:*"); - ArrayList nodes = (ArrayList) endpoint.visitNodes(new Endpoint.Input(swhPID)).result; - - ArrayList expectedNodes = new ArrayList(); - expectedNodes.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000003")); - expectedNodes.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000009")); - expectedNodes.add(new SwhPID("swh:1:snp:0000000000000000000000000000000000000020")); - expectedNodes.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000010")); - expectedNodes.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000013")); - expectedNodes.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000018")); - expectedNodes.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000019")); - - GraphTest.assertEqualsAnyOrder(expectedNodes, nodes); - } } diff --git a/java/server/src/test/java/org/softwareheritage/graph/WalkTest.java b/java/server/src/test/java/org/softwareheritage/graph/WalkTest.java index e8184f4..1daab45 100644 --- a/java/server/src/test/java/org/softwareheritage/graph/WalkTest.java +++ b/java/server/src/test/java/org/softwareheritage/graph/WalkTest.java @@ -1,239 +1,239 @@ package org.softwareheritage.graph; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.junit.Assert; import org.junit.Test; import org.softwareheritage.graph.Endpoint; import org.softwareheritage.graph.Graph; import org.softwareheritage.graph.GraphTest; import org.softwareheritage.graph.SwhPID; import org.softwareheritage.graph.SwhPath; public class WalkTest extends GraphTest { - @Test - public void forwardRootToLeaf() { - Graph graph = getGraph(); - SwhPID src = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); - String dstFmt = "swh:1:cnt:0000000000000000000000000000000000000005"; - - SwhPath solution1 = - new SwhPath( - "swh:1:snp:0000000000000000000000000000000000000020", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:dir:0000000000000000000000000000000000000006", - "swh:1:cnt:0000000000000000000000000000000000000005" - ); - SwhPath solution2 = - new SwhPath( - "swh:1:snp:0000000000000000000000000000000000000020", - "swh:1:rel:0000000000000000000000000000000000000010", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:dir:0000000000000000000000000000000000000006", - "swh:1:cnt:0000000000000000000000000000000000000005" - ); - - Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); - SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; - Endpoint endpoint2 = new Endpoint(graph, "forward", "*"); - SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; - - List possibleSolutions = Arrays.asList(solution1, solution2); - Assert.assertTrue(possibleSolutions.contains(dfsPath)); - Assert.assertTrue(possibleSolutions.contains(bfsPath)); - } - - @Test - public void forwardLeafToLeaf() { - Graph graph = getGraph(); - SwhPID src = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007"); - String dstFmt = "cnt"; - - SwhPath expectedPath = - new SwhPath( - "swh:1:cnt:0000000000000000000000000000000000000007" - ); - - Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); - SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; - Endpoint endpoint2 = new Endpoint(graph, "forward", "*"); - SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; - - Assert.assertEquals(dfsPath, expectedPath); - Assert.assertEquals(bfsPath, expectedPath); - } - - @Test - public void forwardRevToRev() { - Graph graph = getGraph(); - SwhPID src = new SwhPID("swh:1:rev:0000000000000000000000000000000000000018"); - String dstFmt = "swh:1:rev:0000000000000000000000000000000000000003"; - - SwhPath expectedPath = - new SwhPath( - "swh:1:rev:0000000000000000000000000000000000000018", - "swh:1:rev:0000000000000000000000000000000000000013", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:rev:0000000000000000000000000000000000000003" - ); - - Endpoint endpoint1 = new Endpoint(graph, "forward", "rev:rev"); - SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; - Endpoint endpoint2 = new Endpoint(graph, "forward", "rev:rev"); - SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; - - Assert.assertEquals(dfsPath, expectedPath); - Assert.assertEquals(bfsPath, expectedPath); - } - - @Test - public void backwardRevToRev() { - Graph graph = getGraph(); - SwhPID src = new SwhPID("swh:1:rev:0000000000000000000000000000000000000003"); - String dstFmt = "swh:1:rev:0000000000000000000000000000000000000018"; - - SwhPath expectedPath = - new SwhPath( - "swh:1:rev:0000000000000000000000000000000000000003", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:rev:0000000000000000000000000000000000000013", - "swh:1:rev:0000000000000000000000000000000000000018" - ); - - Endpoint endpoint1 = new Endpoint(graph, "backward", "rev:rev"); - SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; - Endpoint endpoint2 = new Endpoint(graph, "backward", "rev:rev"); - SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; - - Assert.assertEquals(dfsPath, expectedPath); - Assert.assertEquals(bfsPath, expectedPath); - } - - @Test - public void backwardCntToFirstSnp() { - Graph graph = getGraph(); - SwhPID src = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001"); - String dstFmt = "snp"; - - SwhPath solution1 = - new SwhPath( - "swh:1:cnt:0000000000000000000000000000000000000001", - "swh:1:dir:0000000000000000000000000000000000000002", - "swh:1:rev:0000000000000000000000000000000000000003", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:snp:0000000000000000000000000000000000000020" - ); - SwhPath solution2 = - new SwhPath( - "swh:1:cnt:0000000000000000000000000000000000000001", - "swh:1:dir:0000000000000000000000000000000000000002", - "swh:1:rev:0000000000000000000000000000000000000003", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:rel:0000000000000000000000000000000000000010", - "swh:1:snp:0000000000000000000000000000000000000020" - ); - SwhPath solution3 = - new SwhPath( - "swh:1:cnt:0000000000000000000000000000000000000001", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:snp:0000000000000000000000000000000000000020" - ); - SwhPath solution4 = - new SwhPath( - "swh:1:cnt:0000000000000000000000000000000000000001", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:rel:0000000000000000000000000000000000000010", - "swh:1:snp:0000000000000000000000000000000000000020" - ); - - Endpoint endpoint1 = new Endpoint(graph, "backward", "*"); - SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; - Endpoint endpoint2 = new Endpoint(graph, "backward", "*"); - SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; - - List possibleSolutions = Arrays.asList(solution1, solution2, solution3, solution4); - Assert.assertTrue(possibleSolutions.contains(dfsPath)); - Assert.assertTrue(possibleSolutions.contains(bfsPath)); - } - - @Test - public void forwardRevToFirstCnt() { - Graph graph = getGraph(); - SwhPID src = new SwhPID("swh:1:rev:0000000000000000000000000000000000000009"); - String dstFmt = "cnt"; - - SwhPath solution1 = - new SwhPath( - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:cnt:0000000000000000000000000000000000000007" - ); - SwhPath solution2 = - new SwhPath( - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:dir:0000000000000000000000000000000000000006", - "swh:1:cnt:0000000000000000000000000000000000000005" - ); - SwhPath solution3 = - new SwhPath( - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:dir:0000000000000000000000000000000000000006", - "swh:1:cnt:0000000000000000000000000000000000000004" - ); - SwhPath solution4 = - new SwhPath( - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:cnt:0000000000000000000000000000000000000001" - ); - SwhPath solution5 = - new SwhPath( - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:rev:0000000000000000000000000000000000000003", - "swh:1:dir:0000000000000000000000000000000000000002", - "swh:1:cnt:0000000000000000000000000000000000000001" - ); - - Endpoint endpoint1 = new Endpoint(graph, "forward", "rev:*,dir:*"); - SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; - Endpoint endpoint2 = new Endpoint(graph, "forward", "rev:*,dir:*"); - SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; - - List possibleSolutions = - Arrays.asList(solution1, solution2, solution3, solution4, solution5); - Assert.assertTrue(possibleSolutions.contains(dfsPath)); - Assert.assertTrue(possibleSolutions.contains(bfsPath)); - } - - @Test - public void backwardDirToFirstRel() { - Graph graph = getGraph(); - SwhPID src = new SwhPID("swh:1:dir:0000000000000000000000000000000000000016"); - String dstFmt = "rel"; - - SwhPath expectedPath = - new SwhPath( - "swh:1:dir:0000000000000000000000000000000000000016", - "swh:1:dir:0000000000000000000000000000000000000017", - "swh:1:rev:0000000000000000000000000000000000000018", - "swh:1:rel:0000000000000000000000000000000000000019" - ); - - Endpoint endpoint1 = new Endpoint(graph, "backward", "dir:dir,dir:rev,rev:*"); - SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; - Endpoint endpoint2 = new Endpoint(graph, "backward", "dir:dir,dir:rev,rev:*"); - SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; - - Assert.assertEquals(dfsPath, expectedPath); - Assert.assertEquals(bfsPath, expectedPath); - } + @Test + public void forwardRootToLeaf() { + Graph graph = getGraph(); + SwhPID src = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); + String dstFmt = "swh:1:cnt:0000000000000000000000000000000000000005"; + + SwhPath solution1 = + new SwhPath( + "swh:1:snp:0000000000000000000000000000000000000020", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:dir:0000000000000000000000000000000000000006", + "swh:1:cnt:0000000000000000000000000000000000000005" + ); + SwhPath solution2 = + new SwhPath( + "swh:1:snp:0000000000000000000000000000000000000020", + "swh:1:rel:0000000000000000000000000000000000000010", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:dir:0000000000000000000000000000000000000006", + "swh:1:cnt:0000000000000000000000000000000000000005" + ); + + Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); + SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; + Endpoint endpoint2 = new Endpoint(graph, "forward", "*"); + SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; + + List possibleSolutions = Arrays.asList(solution1, solution2); + Assert.assertTrue(possibleSolutions.contains(dfsPath)); + Assert.assertTrue(possibleSolutions.contains(bfsPath)); + } + + @Test + public void forwardLeafToLeaf() { + Graph graph = getGraph(); + SwhPID src = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007"); + String dstFmt = "cnt"; + + SwhPath expectedPath = + new SwhPath( + "swh:1:cnt:0000000000000000000000000000000000000007" + ); + + Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); + SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; + Endpoint endpoint2 = new Endpoint(graph, "forward", "*"); + SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; + + Assert.assertEquals(dfsPath, expectedPath); + Assert.assertEquals(bfsPath, expectedPath); + } + + @Test + public void forwardRevToRev() { + Graph graph = getGraph(); + SwhPID src = new SwhPID("swh:1:rev:0000000000000000000000000000000000000018"); + String dstFmt = "swh:1:rev:0000000000000000000000000000000000000003"; + + SwhPath expectedPath = + new SwhPath( + "swh:1:rev:0000000000000000000000000000000000000018", + "swh:1:rev:0000000000000000000000000000000000000013", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:rev:0000000000000000000000000000000000000003" + ); + + Endpoint endpoint1 = new Endpoint(graph, "forward", "rev:rev"); + SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; + Endpoint endpoint2 = new Endpoint(graph, "forward", "rev:rev"); + SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; + + Assert.assertEquals(dfsPath, expectedPath); + Assert.assertEquals(bfsPath, expectedPath); + } + + @Test + public void backwardRevToRev() { + Graph graph = getGraph(); + SwhPID src = new SwhPID("swh:1:rev:0000000000000000000000000000000000000003"); + String dstFmt = "swh:1:rev:0000000000000000000000000000000000000018"; + + SwhPath expectedPath = + new SwhPath( + "swh:1:rev:0000000000000000000000000000000000000003", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:rev:0000000000000000000000000000000000000013", + "swh:1:rev:0000000000000000000000000000000000000018" + ); + + Endpoint endpoint1 = new Endpoint(graph, "backward", "rev:rev"); + SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; + Endpoint endpoint2 = new Endpoint(graph, "backward", "rev:rev"); + SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; + + Assert.assertEquals(dfsPath, expectedPath); + Assert.assertEquals(bfsPath, expectedPath); + } + + @Test + public void backwardCntToFirstSnp() { + Graph graph = getGraph(); + SwhPID src = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001"); + String dstFmt = "snp"; + + SwhPath solution1 = + new SwhPath( + "swh:1:cnt:0000000000000000000000000000000000000001", + "swh:1:dir:0000000000000000000000000000000000000002", + "swh:1:rev:0000000000000000000000000000000000000003", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:snp:0000000000000000000000000000000000000020" + ); + SwhPath solution2 = + new SwhPath( + "swh:1:cnt:0000000000000000000000000000000000000001", + "swh:1:dir:0000000000000000000000000000000000000002", + "swh:1:rev:0000000000000000000000000000000000000003", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:rel:0000000000000000000000000000000000000010", + "swh:1:snp:0000000000000000000000000000000000000020" + ); + SwhPath solution3 = + new SwhPath( + "swh:1:cnt:0000000000000000000000000000000000000001", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:snp:0000000000000000000000000000000000000020" + ); + SwhPath solution4 = + new SwhPath( + "swh:1:cnt:0000000000000000000000000000000000000001", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:rel:0000000000000000000000000000000000000010", + "swh:1:snp:0000000000000000000000000000000000000020" + ); + + Endpoint endpoint1 = new Endpoint(graph, "backward", "*"); + SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; + Endpoint endpoint2 = new Endpoint(graph, "backward", "*"); + SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; + + List possibleSolutions = Arrays.asList(solution1, solution2, solution3, solution4); + Assert.assertTrue(possibleSolutions.contains(dfsPath)); + Assert.assertTrue(possibleSolutions.contains(bfsPath)); + } + + @Test + public void forwardRevToFirstCnt() { + Graph graph = getGraph(); + SwhPID src = new SwhPID("swh:1:rev:0000000000000000000000000000000000000009"); + String dstFmt = "cnt"; + + SwhPath solution1 = + new SwhPath( + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:cnt:0000000000000000000000000000000000000007" + ); + SwhPath solution2 = + new SwhPath( + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:dir:0000000000000000000000000000000000000006", + "swh:1:cnt:0000000000000000000000000000000000000005" + ); + SwhPath solution3 = + new SwhPath( + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:dir:0000000000000000000000000000000000000006", + "swh:1:cnt:0000000000000000000000000000000000000004" + ); + SwhPath solution4 = + new SwhPath( + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:cnt:0000000000000000000000000000000000000001" + ); + SwhPath solution5 = + new SwhPath( + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:rev:0000000000000000000000000000000000000003", + "swh:1:dir:0000000000000000000000000000000000000002", + "swh:1:cnt:0000000000000000000000000000000000000001" + ); + + Endpoint endpoint1 = new Endpoint(graph, "forward", "rev:*,dir:*"); + SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; + Endpoint endpoint2 = new Endpoint(graph, "forward", "rev:*,dir:*"); + SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; + + List possibleSolutions = + Arrays.asList(solution1, solution2, solution3, solution4, solution5); + Assert.assertTrue(possibleSolutions.contains(dfsPath)); + Assert.assertTrue(possibleSolutions.contains(bfsPath)); + } + + @Test + public void backwardDirToFirstRel() { + Graph graph = getGraph(); + SwhPID src = new SwhPID("swh:1:dir:0000000000000000000000000000000000000016"); + String dstFmt = "rel"; + + SwhPath expectedPath = + new SwhPath( + "swh:1:dir:0000000000000000000000000000000000000016", + "swh:1:dir:0000000000000000000000000000000000000017", + "swh:1:rev:0000000000000000000000000000000000000018", + "swh:1:rel:0000000000000000000000000000000000000019" + ); + + Endpoint endpoint1 = new Endpoint(graph, "backward", "dir:dir,dir:rev,rev:*"); + SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; + Endpoint endpoint2 = new Endpoint(graph, "backward", "dir:dir,dir:rev,rev:*"); + SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; + + Assert.assertEquals(dfsPath, expectedPath); + Assert.assertEquals(bfsPath, expectedPath); + } }