Changeset View
Changeset View
Standalone View
Standalone View
java/src/test/java/org/softwareheritage/graph/VisitTest.java
Show All 14 Lines | private void assertSameNodesFromPaths(ArrayList<SwhPath> paths, ArrayList<SWHID> nodes) { | ||||
for (SwhPath path : paths) { | for (SwhPath path : paths) { | ||||
expectedNodes.addAll(path.getPath()); | expectedNodes.addAll(path.getPath()); | ||||
} | } | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes, nodes); | GraphTest.assertEqualsAnyOrder(expectedNodes, nodes); | ||||
} | } | ||||
@Test | @Test | ||||
public void forwardFromRoot() { | public void forwardFromRoot() { | ||||
Graph graph = getGraph(); | SwhBidirectionalGraph graph = getGraph(); | ||||
SWHID swhid = new SWHID("swh:1:ori:0000000000000000000000000000000000000021"); | SWHID swhid = new SWHID("swh:1:ori:0000000000000000000000000000000000000021"); | ||||
Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); | Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); | ||||
ArrayList<SwhPath> paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhid)).result; | ArrayList<SwhPath> paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhid)).result; | ||||
Endpoint endpoint2 = new Endpoint(graph, "forward", "*"); | Endpoint endpoint2 = new Endpoint(graph, "forward", "*"); | ||||
ArrayList<SWHID> nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result; | ArrayList<SWHID> nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result; | ||||
ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ||||
expectedPaths.add(new SwhPath("swh:1:ori:0000000000000000000000000000000000000021", | expectedPaths.add(new SwhPath("swh:1:ori:0000000000000000000000000000000000000021", | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | public void forwardFromRoot() { | ||||
"swh:1:cnt:0000000000000000000000000000000000000001")); | "swh:1:cnt:0000000000000000000000000000000000000001")); | ||||
GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | ||||
assertSameNodesFromPaths(expectedPaths, nodes); | assertSameNodesFromPaths(expectedPaths, nodes); | ||||
} | } | ||||
@Test | @Test | ||||
public void forwardFromMiddle() { | public void forwardFromMiddle() { | ||||
Graph graph = getGraph(); | SwhBidirectionalGraph graph = getGraph(); | ||||
SWHID swhid = new SWHID("swh:1:dir:0000000000000000000000000000000000000012"); | SWHID swhid = new SWHID("swh:1:dir:0000000000000000000000000000000000000012"); | ||||
Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); | Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); | ||||
ArrayList<SwhPath> paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhid)).result; | ArrayList<SwhPath> paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhid)).result; | ||||
Endpoint endpoint2 = new Endpoint(graph, "forward", "*"); | Endpoint endpoint2 = new Endpoint(graph, "forward", "*"); | ||||
ArrayList<SWHID> nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result; | ArrayList<SWHID> nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result; | ||||
ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ||||
expectedPaths.add(new SwhPath("swh:1:dir:0000000000000000000000000000000000000012", | expectedPaths.add(new SwhPath("swh:1:dir:0000000000000000000000000000000000000012", | ||||
Show All 14 Lines | public void forwardFromMiddle() { | ||||
"swh:1:cnt:0000000000000000000000000000000000000011")); | "swh:1:cnt:0000000000000000000000000000000000000011")); | ||||
GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | ||||
assertSameNodesFromPaths(expectedPaths, nodes); | assertSameNodesFromPaths(expectedPaths, nodes); | ||||
} | } | ||||
@Test | @Test | ||||
public void forwardFromLeaf() { | public void forwardFromLeaf() { | ||||
Graph graph = getGraph(); | SwhBidirectionalGraph graph = getGraph(); | ||||
SWHID swhid = new SWHID("swh:1:cnt:0000000000000000000000000000000000000004"); | SWHID swhid = new SWHID("swh:1:cnt:0000000000000000000000000000000000000004"); | ||||
Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); | Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); | ||||
ArrayList<SwhPath> paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhid)).result; | ArrayList<SwhPath> paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhid)).result; | ||||
Endpoint endpoint2 = new Endpoint(graph, "forward", "*"); | Endpoint endpoint2 = new Endpoint(graph, "forward", "*"); | ||||
ArrayList<SWHID> nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result; | ArrayList<SWHID> nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result; | ||||
ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ||||
expectedPaths.add(new SwhPath("swh:1:cnt:0000000000000000000000000000000000000004")); | expectedPaths.add(new SwhPath("swh:1:cnt:0000000000000000000000000000000000000004")); | ||||
GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | ||||
assertSameNodesFromPaths(expectedPaths, nodes); | assertSameNodesFromPaths(expectedPaths, nodes); | ||||
} | } | ||||
@Test | @Test | ||||
public void backwardFromRoot() { | public void backwardFromRoot() { | ||||
Graph graph = getGraph(); | SwhBidirectionalGraph graph = getGraph(); | ||||
SWHID swhid = new SWHID("swh:1:ori:0000000000000000000000000000000000000021"); | SWHID swhid = new SWHID("swh:1:ori:0000000000000000000000000000000000000021"); | ||||
Endpoint endpoint1 = new Endpoint(graph, "backward", "*"); | Endpoint endpoint1 = new Endpoint(graph, "backward", "*"); | ||||
ArrayList<SwhPath> paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhid)).result; | ArrayList<SwhPath> paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhid)).result; | ||||
Endpoint endpoint2 = new Endpoint(graph, "backward", "*"); | Endpoint endpoint2 = new Endpoint(graph, "backward", "*"); | ||||
ArrayList<SWHID> nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result; | ArrayList<SWHID> nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result; | ||||
ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ||||
expectedPaths.add(new SwhPath("swh:1:ori:0000000000000000000000000000000000000021")); | expectedPaths.add(new SwhPath("swh:1:ori:0000000000000000000000000000000000000021")); | ||||
GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | ||||
assertSameNodesFromPaths(expectedPaths, nodes); | assertSameNodesFromPaths(expectedPaths, nodes); | ||||
} | } | ||||
@Test | @Test | ||||
public void backwardFromMiddle() { | public void backwardFromMiddle() { | ||||
Graph graph = getGraph(); | SwhBidirectionalGraph graph = getGraph(); | ||||
SWHID swhid = new SWHID("swh:1:dir:0000000000000000000000000000000000000012"); | SWHID swhid = new SWHID("swh:1:dir:0000000000000000000000000000000000000012"); | ||||
Endpoint endpoint1 = new Endpoint(graph, "backward", "*"); | Endpoint endpoint1 = new Endpoint(graph, "backward", "*"); | ||||
ArrayList<SwhPath> paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhid)).result; | ArrayList<SwhPath> paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhid)).result; | ||||
Endpoint endpoint2 = new Endpoint(graph, "backward", "*"); | Endpoint endpoint2 = new Endpoint(graph, "backward", "*"); | ||||
ArrayList<SWHID> nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result; | ArrayList<SWHID> nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result; | ||||
ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ||||
expectedPaths.add(new SwhPath("swh:1:dir:0000000000000000000000000000000000000012", | expectedPaths.add(new SwhPath("swh:1:dir:0000000000000000000000000000000000000012", | ||||
"swh:1:rev:0000000000000000000000000000000000000013", | "swh:1:rev:0000000000000000000000000000000000000013", | ||||
"swh:1:rev:0000000000000000000000000000000000000018", | "swh:1:rev:0000000000000000000000000000000000000018", | ||||
"swh:1:rel:0000000000000000000000000000000000000019")); | "swh:1:rel:0000000000000000000000000000000000000019")); | ||||
GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | ||||
assertSameNodesFromPaths(expectedPaths, nodes); | assertSameNodesFromPaths(expectedPaths, nodes); | ||||
} | } | ||||
@Test | @Test | ||||
public void backwardFromLeaf() { | public void backwardFromLeaf() { | ||||
Graph graph = getGraph(); | SwhBidirectionalGraph graph = getGraph(); | ||||
SWHID swhid = new SWHID("swh:1:cnt:0000000000000000000000000000000000000004"); | SWHID swhid = new SWHID("swh:1:cnt:0000000000000000000000000000000000000004"); | ||||
Endpoint endpoint1 = new Endpoint(graph, "backward", "*"); | Endpoint endpoint1 = new Endpoint(graph, "backward", "*"); | ||||
ArrayList<SwhPath> paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhid)).result; | ArrayList<SwhPath> paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhid)).result; | ||||
Endpoint endpoint2 = new Endpoint(graph, "backward", "*"); | Endpoint endpoint2 = new Endpoint(graph, "backward", "*"); | ||||
ArrayList<SWHID> nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result; | ArrayList<SWHID> nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result; | ||||
ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ||||
expectedPaths.add(new SwhPath("swh:1:cnt:0000000000000000000000000000000000000004", | expectedPaths.add(new SwhPath("swh:1:cnt:0000000000000000000000000000000000000004", | ||||
Show All 25 Lines | public void backwardFromLeaf() { | ||||
"swh:1:ori:0000000000000000000000000000000000000021")); | "swh:1:ori:0000000000000000000000000000000000000021")); | ||||
GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | ||||
assertSameNodesFromPaths(expectedPaths, nodes); | assertSameNodesFromPaths(expectedPaths, nodes); | ||||
} | } | ||||
@Test | @Test | ||||
public void forwardSnpToRev() { | public void forwardSnpToRev() { | ||||
Graph graph = getGraph(); | SwhBidirectionalGraph graph = getGraph(); | ||||
SWHID swhid = new SWHID("swh:1:snp:0000000000000000000000000000000000000020"); | SWHID swhid = new SWHID("swh:1:snp:0000000000000000000000000000000000000020"); | ||||
Endpoint endpoint1 = new Endpoint(graph, "forward", "snp:rev"); | Endpoint endpoint1 = new Endpoint(graph, "forward", "snp:rev"); | ||||
ArrayList<SwhPath> paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhid)).result; | ArrayList<SwhPath> paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhid)).result; | ||||
Endpoint endpoint2 = new Endpoint(graph, "forward", "snp:rev"); | Endpoint endpoint2 = new Endpoint(graph, "forward", "snp:rev"); | ||||
ArrayList<SWHID> nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result; | ArrayList<SWHID> nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result; | ||||
ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ||||
expectedPaths.add(new SwhPath("swh:1:snp:0000000000000000000000000000000000000020", | expectedPaths.add(new SwhPath("swh:1:snp:0000000000000000000000000000000000000020", | ||||
"swh:1:rev:0000000000000000000000000000000000000009")); | "swh:1:rev:0000000000000000000000000000000000000009")); | ||||
GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | ||||
assertSameNodesFromPaths(expectedPaths, nodes); | assertSameNodesFromPaths(expectedPaths, nodes); | ||||
} | } | ||||
@Test | @Test | ||||
public void forwardRelToRevRevToRev() { | public void forwardRelToRevRevToRev() { | ||||
Graph graph = getGraph(); | SwhBidirectionalGraph graph = getGraph(); | ||||
SWHID swhid = new SWHID("swh:1:rel:0000000000000000000000000000000000000010"); | SWHID swhid = new SWHID("swh:1:rel:0000000000000000000000000000000000000010"); | ||||
Endpoint endpoint1 = new Endpoint(graph, "forward", "rel:rev,rev:rev"); | Endpoint endpoint1 = new Endpoint(graph, "forward", "rel:rev,rev:rev"); | ||||
ArrayList<SwhPath> paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhid)).result; | ArrayList<SwhPath> paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhid)).result; | ||||
Endpoint endpoint2 = new Endpoint(graph, "forward", "rel:rev,rev:rev"); | Endpoint endpoint2 = new Endpoint(graph, "forward", "rel:rev,rev:rev"); | ||||
ArrayList<SWHID> nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result; | ArrayList<SWHID> nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result; | ||||
ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ||||
expectedPaths.add(new SwhPath("swh:1:rel:0000000000000000000000000000000000000010", | expectedPaths.add(new SwhPath("swh:1:rel:0000000000000000000000000000000000000010", | ||||
"swh:1:rev:0000000000000000000000000000000000000009", | "swh:1:rev:0000000000000000000000000000000000000009", | ||||
"swh:1:rev:0000000000000000000000000000000000000003")); | "swh:1:rev:0000000000000000000000000000000000000003")); | ||||
GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | ||||
assertSameNodesFromPaths(expectedPaths, nodes); | assertSameNodesFromPaths(expectedPaths, nodes); | ||||
} | } | ||||
@Test | @Test | ||||
public void forwardRevToAllDirToAll() { | public void forwardRevToAllDirToAll() { | ||||
Graph graph = getGraph(); | SwhBidirectionalGraph graph = getGraph(); | ||||
SWHID swhid = new SWHID("swh:1:rev:0000000000000000000000000000000000000013"); | SWHID swhid = new SWHID("swh:1:rev:0000000000000000000000000000000000000013"); | ||||
Endpoint endpoint1 = new Endpoint(graph, "forward", "rev:*,dir:*"); | Endpoint endpoint1 = new Endpoint(graph, "forward", "rev:*,dir:*"); | ||||
ArrayList<SwhPath> paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhid)).result; | ArrayList<SwhPath> paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhid)).result; | ||||
Endpoint endpoint2 = new Endpoint(graph, "forward", "rev:*,dir:*"); | Endpoint endpoint2 = new Endpoint(graph, "forward", "rev:*,dir:*"); | ||||
ArrayList<SWHID> nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result; | ArrayList<SWHID> nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result; | ||||
ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ||||
expectedPaths.add(new SwhPath("swh:1:rev:0000000000000000000000000000000000000013", | expectedPaths.add(new SwhPath("swh:1:rev:0000000000000000000000000000000000000013", | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | public void forwardRevToAllDirToAll() { | ||||
"swh:1:cnt:0000000000000000000000000000000000000001")); | "swh:1:cnt:0000000000000000000000000000000000000001")); | ||||
GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | ||||
assertSameNodesFromPaths(expectedPaths, nodes); | assertSameNodesFromPaths(expectedPaths, nodes); | ||||
} | } | ||||
@Test | @Test | ||||
public void forwardSnpToAllRevToAll() { | public void forwardSnpToAllRevToAll() { | ||||
Graph graph = getGraph(); | SwhBidirectionalGraph graph = getGraph(); | ||||
SWHID swhid = new SWHID("swh:1:snp:0000000000000000000000000000000000000020"); | SWHID swhid = new SWHID("swh:1:snp:0000000000000000000000000000000000000020"); | ||||
Endpoint endpoint1 = new Endpoint(graph, "forward", "snp:*,rev:*"); | Endpoint endpoint1 = new Endpoint(graph, "forward", "snp:*,rev:*"); | ||||
ArrayList<SwhPath> paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhid)).result; | ArrayList<SwhPath> paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhid)).result; | ||||
Endpoint endpoint2 = new Endpoint(graph, "forward", "snp:*,rev:*"); | Endpoint endpoint2 = new Endpoint(graph, "forward", "snp:*,rev:*"); | ||||
ArrayList<SWHID> nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result; | ArrayList<SWHID> nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result; | ||||
ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ||||
expectedPaths.add(new SwhPath("swh:1:snp:0000000000000000000000000000000000000020", | expectedPaths.add(new SwhPath("swh:1:snp:0000000000000000000000000000000000000020", | ||||
"swh:1:rev:0000000000000000000000000000000000000009", | "swh:1:rev:0000000000000000000000000000000000000009", | ||||
"swh:1:rev:0000000000000000000000000000000000000003", | "swh:1:rev:0000000000000000000000000000000000000003", | ||||
"swh:1:dir:0000000000000000000000000000000000000002")); | "swh:1:dir:0000000000000000000000000000000000000002")); | ||||
expectedPaths.add(new SwhPath("swh:1:snp:0000000000000000000000000000000000000020", | expectedPaths.add(new SwhPath("swh:1:snp:0000000000000000000000000000000000000020", | ||||
"swh:1:rev:0000000000000000000000000000000000000009", | "swh:1:rev:0000000000000000000000000000000000000009", | ||||
"swh:1:dir:0000000000000000000000000000000000000008")); | "swh:1:dir:0000000000000000000000000000000000000008")); | ||||
expectedPaths.add(new SwhPath("swh:1:snp:0000000000000000000000000000000000000020", | expectedPaths.add(new SwhPath("swh:1:snp:0000000000000000000000000000000000000020", | ||||
"swh:1:rel:0000000000000000000000000000000000000010")); | "swh:1:rel:0000000000000000000000000000000000000010")); | ||||
GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | ||||
assertSameNodesFromPaths(expectedPaths, nodes); | assertSameNodesFromPaths(expectedPaths, nodes); | ||||
} | } | ||||
@Test | @Test | ||||
public void forwardNoEdges() { | public void forwardNoEdges() { | ||||
Graph graph = getGraph(); | SwhBidirectionalGraph graph = getGraph(); | ||||
SWHID swhid = new SWHID("swh:1:snp:0000000000000000000000000000000000000020"); | SWHID swhid = new SWHID("swh:1:snp:0000000000000000000000000000000000000020"); | ||||
Endpoint endpoint1 = new Endpoint(graph, "forward", ""); | Endpoint endpoint1 = new Endpoint(graph, "forward", ""); | ||||
ArrayList<SwhPath> paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhid)).result; | ArrayList<SwhPath> paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhid)).result; | ||||
Endpoint endpoint2 = new Endpoint(graph, "forward", ""); | Endpoint endpoint2 = new Endpoint(graph, "forward", ""); | ||||
ArrayList<SWHID> nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result; | ArrayList<SWHID> nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result; | ||||
ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ||||
expectedPaths.add(new SwhPath("swh:1:snp:0000000000000000000000000000000000000020")); | expectedPaths.add(new SwhPath("swh:1:snp:0000000000000000000000000000000000000020")); | ||||
GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | ||||
assertSameNodesFromPaths(expectedPaths, nodes); | assertSameNodesFromPaths(expectedPaths, nodes); | ||||
} | } | ||||
@Test | @Test | ||||
public void backwardRevToRevRevToRel() { | public void backwardRevToRevRevToRel() { | ||||
Graph graph = getGraph(); | SwhBidirectionalGraph graph = getGraph(); | ||||
SWHID swhid = new SWHID("swh:1:rev:0000000000000000000000000000000000000003"); | SWHID swhid = new SWHID("swh:1:rev:0000000000000000000000000000000000000003"); | ||||
Endpoint endpoint1 = new Endpoint(graph, "backward", "rev:rev,rev:rel"); | Endpoint endpoint1 = new Endpoint(graph, "backward", "rev:rev,rev:rel"); | ||||
ArrayList<SwhPath> paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhid)).result; | ArrayList<SwhPath> paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhid)).result; | ||||
Endpoint endpoint2 = new Endpoint(graph, "backward", "rev:rev,rev:rel"); | Endpoint endpoint2 = new Endpoint(graph, "backward", "rev:rev,rev:rel"); | ||||
ArrayList<SWHID> nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result; | ArrayList<SWHID> nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result; | ||||
ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ||||
expectedPaths.add(new SwhPath("swh:1:rev:0000000000000000000000000000000000000003", | expectedPaths.add(new SwhPath("swh:1:rev:0000000000000000000000000000000000000003", | ||||
"swh:1:rev:0000000000000000000000000000000000000009", | "swh:1:rev:0000000000000000000000000000000000000009", | ||||
"swh:1:rev:0000000000000000000000000000000000000013", | "swh:1:rev:0000000000000000000000000000000000000013", | ||||
"swh:1:rev:0000000000000000000000000000000000000018", | "swh:1:rev:0000000000000000000000000000000000000018", | ||||
"swh:1:rel:0000000000000000000000000000000000000019")); | "swh:1:rel:0000000000000000000000000000000000000019")); | ||||
expectedPaths.add(new SwhPath("swh:1:rev:0000000000000000000000000000000000000003", | expectedPaths.add(new SwhPath("swh:1:rev:0000000000000000000000000000000000000003", | ||||
"swh:1:rev:0000000000000000000000000000000000000009", | "swh:1:rev:0000000000000000000000000000000000000009", | ||||
"swh:1:rel:0000000000000000000000000000000000000010")); | "swh:1:rel:0000000000000000000000000000000000000010")); | ||||
GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | GraphTest.assertEqualsAnyOrder(expectedPaths, paths); | ||||
assertSameNodesFromPaths(expectedPaths, nodes); | assertSameNodesFromPaths(expectedPaths, nodes); | ||||
} | } | ||||
@Test | @Test | ||||
public void forwardFromRootNodesOnly() { | public void forwardFromRootNodesOnly() { | ||||
Graph graph = getGraph(); | SwhBidirectionalGraph graph = getGraph(); | ||||
SWHID swhid = new SWHID("swh:1:ori:0000000000000000000000000000000000000021"); | SWHID swhid = new SWHID("swh:1:ori:0000000000000000000000000000000000000021"); | ||||
Endpoint endpoint = new Endpoint(graph, "forward", "*"); | Endpoint endpoint = new Endpoint(graph, "forward", "*"); | ||||
ArrayList<SWHID> nodes = (ArrayList) endpoint.visitNodes(new Endpoint.Input(swhid)).result; | ArrayList<SWHID> nodes = (ArrayList) endpoint.visitNodes(new Endpoint.Input(swhid)).result; | ||||
ArrayList<SWHID> expectedNodes = new ArrayList<SWHID>(); | ArrayList<SWHID> expectedNodes = new ArrayList<SWHID>(); | ||||
expectedNodes.add(new SWHID("swh:1:ori:0000000000000000000000000000000000000021")); | expectedNodes.add(new SWHID("swh:1:ori:0000000000000000000000000000000000000021")); | ||||
expectedNodes.add(new SWHID("swh:1:snp:0000000000000000000000000000000000000020")); | expectedNodes.add(new SWHID("swh:1:snp:0000000000000000000000000000000000000020")); | ||||
expectedNodes.add(new SWHID("swh:1:rel:0000000000000000000000000000000000000010")); | expectedNodes.add(new SWHID("swh:1:rel:0000000000000000000000000000000000000010")); | ||||
expectedNodes.add(new SWHID("swh:1:rev:0000000000000000000000000000000000000009")); | expectedNodes.add(new SWHID("swh:1:rev:0000000000000000000000000000000000000009")); | ||||
expectedNodes.add(new SWHID("swh:1:rev:0000000000000000000000000000000000000003")); | expectedNodes.add(new SWHID("swh:1:rev:0000000000000000000000000000000000000003")); | ||||
expectedNodes.add(new SWHID("swh:1:dir:0000000000000000000000000000000000000002")); | expectedNodes.add(new SWHID("swh:1:dir:0000000000000000000000000000000000000002")); | ||||
expectedNodes.add(new SWHID("swh:1:cnt:0000000000000000000000000000000000000001")); | expectedNodes.add(new SWHID("swh:1:cnt:0000000000000000000000000000000000000001")); | ||||
expectedNodes.add(new SWHID("swh:1:dir:0000000000000000000000000000000000000008")); | expectedNodes.add(new SWHID("swh:1:dir:0000000000000000000000000000000000000008")); | ||||
expectedNodes.add(new SWHID("swh:1:dir:0000000000000000000000000000000000000006")); | expectedNodes.add(new SWHID("swh:1:dir:0000000000000000000000000000000000000006")); | ||||
expectedNodes.add(new SWHID("swh:1:cnt:0000000000000000000000000000000000000004")); | expectedNodes.add(new SWHID("swh:1:cnt:0000000000000000000000000000000000000004")); | ||||
expectedNodes.add(new SWHID("swh:1:cnt:0000000000000000000000000000000000000005")); | expectedNodes.add(new SWHID("swh:1:cnt:0000000000000000000000000000000000000005")); | ||||
expectedNodes.add(new SWHID("swh:1:cnt:0000000000000000000000000000000000000007")); | expectedNodes.add(new SWHID("swh:1:cnt:0000000000000000000000000000000000000007")); | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes, nodes); | GraphTest.assertEqualsAnyOrder(expectedNodes, nodes); | ||||
} | } | ||||
@Test | @Test | ||||
public void backwardRevToAllNodesOnly() { | public void backwardRevToAllNodesOnly() { | ||||
Graph graph = getGraph(); | SwhBidirectionalGraph graph = getGraph(); | ||||
SWHID swhid = new SWHID("swh:1:rev:0000000000000000000000000000000000000003"); | SWHID swhid = new SWHID("swh:1:rev:0000000000000000000000000000000000000003"); | ||||
Endpoint endpoint = new Endpoint(graph, "backward", "rev:*"); | Endpoint endpoint = new Endpoint(graph, "backward", "rev:*"); | ||||
ArrayList<SWHID> nodes = (ArrayList) endpoint.visitNodes(new Endpoint.Input(swhid)).result; | ArrayList<SWHID> nodes = (ArrayList) endpoint.visitNodes(new Endpoint.Input(swhid)).result; | ||||
ArrayList<SWHID> expectedNodes = new ArrayList<SWHID>(); | ArrayList<SWHID> expectedNodes = new ArrayList<SWHID>(); | ||||
expectedNodes.add(new SWHID("swh:1:rev:0000000000000000000000000000000000000003")); | expectedNodes.add(new SWHID("swh:1:rev:0000000000000000000000000000000000000003")); | ||||
expectedNodes.add(new SWHID("swh:1:rev:0000000000000000000000000000000000000009")); | expectedNodes.add(new SWHID("swh:1:rev:0000000000000000000000000000000000000009")); | ||||
expectedNodes.add(new SWHID("swh:1:snp:0000000000000000000000000000000000000020")); | expectedNodes.add(new SWHID("swh:1:snp:0000000000000000000000000000000000000020")); | ||||
expectedNodes.add(new SWHID("swh:1:rel:0000000000000000000000000000000000000010")); | expectedNodes.add(new SWHID("swh:1:rel:0000000000000000000000000000000000000010")); | ||||
expectedNodes.add(new SWHID("swh:1:rev:0000000000000000000000000000000000000013")); | expectedNodes.add(new SWHID("swh:1:rev:0000000000000000000000000000000000000013")); | ||||
expectedNodes.add(new SWHID("swh:1:rev:0000000000000000000000000000000000000018")); | expectedNodes.add(new SWHID("swh:1:rev:0000000000000000000000000000000000000018")); | ||||
expectedNodes.add(new SWHID("swh:1:rel:0000000000000000000000000000000000000019")); | expectedNodes.add(new SWHID("swh:1:rel:0000000000000000000000000000000000000019")); | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes, nodes); | GraphTest.assertEqualsAnyOrder(expectedNodes, nodes); | ||||
} | } | ||||
} | } |