Changeset View
Changeset View
Standalone View
Standalone View
java/server/src/test/java/org/softwareheritage/graph/VisitTest.java
Show All 20 Lines | for (SwhPath path : paths) { | ||||
} | } | ||||
} | } | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes, nodes); | GraphTest.assertEqualsAnyOrder(expectedNodes, nodes); | ||||
} | } | ||||
@Test | @Test | ||||
public void forwardFromRoot() { | public void forwardFromRoot() { | ||||
Graph graph = getGraph(); | Graph graph = getGraph(); | ||||
SwhId swhId = new SwhId("swh:1:snp:0000000000000000000000000000000000000020"); | SwhId swhId = new SwhId("swh:1:ori:0000000000000000000000000000000000000021"); | ||||
Endpoint endpoint = new Endpoint(graph, "forward", "*"); | Endpoint endpoint = new Endpoint(graph, "forward", "*"); | ||||
ArrayList<SwhPath> paths = endpoint.visitPaths(swhId); | ArrayList<SwhPath> paths = endpoint.visitPaths(swhId); | ||||
ArrayList<SwhId> nodes = endpoint.visitNodes(swhId); | ArrayList<SwhId> nodes = endpoint.visitNodes(swhId); | ||||
ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ||||
expectedPaths.add( | expectedPaths.add( | ||||
new SwhPath( | new SwhPath( | ||||
"swh:1:ori:0000000000000000000000000000000000000021", | |||||
"swh:1:snp:0000000000000000000000000000000000000020", | "swh:1:snp:0000000000000000000000000000000000000020", | ||||
"swh:1:rev:0000000000000000000000000000000000000009", | "swh:1:rev:0000000000000000000000000000000000000009", | ||||
"swh:1:dir:0000000000000000000000000000000000000008", | "swh:1:dir:0000000000000000000000000000000000000008", | ||||
"swh:1:cnt:0000000000000000000000000000000000000007" | "swh:1:cnt:0000000000000000000000000000000000000007" | ||||
)); | )); | ||||
expectedPaths.add( | expectedPaths.add( | ||||
new SwhPath( | new SwhPath( | ||||
"swh:1:ori:0000000000000000000000000000000000000021", | |||||
"swh:1:snp:0000000000000000000000000000000000000020", | "swh:1:snp:0000000000000000000000000000000000000020", | ||||
"swh:1:rev:0000000000000000000000000000000000000009", | "swh:1:rev:0000000000000000000000000000000000000009", | ||||
"swh:1:dir:0000000000000000000000000000000000000008", | "swh:1:dir:0000000000000000000000000000000000000008", | ||||
"swh:1:cnt:0000000000000000000000000000000000000001" | "swh:1:cnt:0000000000000000000000000000000000000001" | ||||
)); | )); | ||||
expectedPaths.add( | expectedPaths.add( | ||||
new SwhPath( | new SwhPath( | ||||
"swh:1:ori:0000000000000000000000000000000000000021", | |||||
"swh:1:snp:0000000000000000000000000000000000000020", | "swh:1:snp:0000000000000000000000000000000000000020", | ||||
"swh:1:rev:0000000000000000000000000000000000000009", | "swh:1:rev:0000000000000000000000000000000000000009", | ||||
"swh:1:dir:0000000000000000000000000000000000000008", | "swh:1:dir:0000000000000000000000000000000000000008", | ||||
"swh:1:dir:0000000000000000000000000000000000000006", | "swh:1:dir:0000000000000000000000000000000000000006", | ||||
"swh:1:cnt:0000000000000000000000000000000000000004" | "swh:1:cnt:0000000000000000000000000000000000000004" | ||||
)); | )); | ||||
expectedPaths.add( | expectedPaths.add( | ||||
new SwhPath( | new SwhPath( | ||||
"swh:1:ori:0000000000000000000000000000000000000021", | |||||
"swh:1:snp:0000000000000000000000000000000000000020", | "swh:1:snp:0000000000000000000000000000000000000020", | ||||
"swh:1:rev:0000000000000000000000000000000000000009", | "swh:1:rev:0000000000000000000000000000000000000009", | ||||
"swh:1:dir:0000000000000000000000000000000000000008", | "swh:1:dir:0000000000000000000000000000000000000008", | ||||
"swh:1:dir:0000000000000000000000000000000000000006", | "swh:1:dir:0000000000000000000000000000000000000006", | ||||
"swh:1:cnt:0000000000000000000000000000000000000005" | "swh:1:cnt:0000000000000000000000000000000000000005" | ||||
)); | )); | ||||
expectedPaths.add( | expectedPaths.add( | ||||
new SwhPath( | new SwhPath( | ||||
"swh:1:ori:0000000000000000000000000000000000000021", | |||||
"swh:1:snp:0000000000000000000000000000000000000020", | "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", | ||||
"swh:1:cnt:0000000000000000000000000000000000000001" | "swh:1:cnt:0000000000000000000000000000000000000001" | ||||
)); | )); | ||||
expectedPaths.add( | expectedPaths.add( | ||||
new SwhPath( | new SwhPath( | ||||
"swh:1:ori:0000000000000000000000000000000000000021", | |||||
"swh:1:snp:0000000000000000000000000000000000000020", | "swh:1:snp:0000000000000000000000000000000000000020", | ||||
"swh:1:rel:0000000000000000000000000000000000000010", | "swh:1:rel:0000000000000000000000000000000000000010", | ||||
"swh:1:rev:0000000000000000000000000000000000000009", | "swh:1:rev:0000000000000000000000000000000000000009", | ||||
"swh:1:dir:0000000000000000000000000000000000000008", | "swh:1:dir:0000000000000000000000000000000000000008", | ||||
"swh:1:cnt:0000000000000000000000000000000000000007" | "swh:1:cnt:0000000000000000000000000000000000000007" | ||||
)); | )); | ||||
expectedPaths.add( | expectedPaths.add( | ||||
new SwhPath( | new SwhPath( | ||||
"swh:1:ori:0000000000000000000000000000000000000021", | |||||
"swh:1:snp:0000000000000000000000000000000000000020", | "swh:1:snp:0000000000000000000000000000000000000020", | ||||
"swh:1:rel:0000000000000000000000000000000000000010", | "swh:1:rel:0000000000000000000000000000000000000010", | ||||
"swh:1:rev:0000000000000000000000000000000000000009", | "swh:1:rev:0000000000000000000000000000000000000009", | ||||
"swh:1:dir:0000000000000000000000000000000000000008", | "swh:1:dir:0000000000000000000000000000000000000008", | ||||
"swh:1:cnt:0000000000000000000000000000000000000001" | "swh:1:cnt:0000000000000000000000000000000000000001" | ||||
)); | )); | ||||
expectedPaths.add( | expectedPaths.add( | ||||
new SwhPath( | new SwhPath( | ||||
"swh:1:ori:0000000000000000000000000000000000000021", | |||||
"swh:1:snp:0000000000000000000000000000000000000020", | "swh:1:snp:0000000000000000000000000000000000000020", | ||||
"swh:1:rel:0000000000000000000000000000000000000010", | "swh:1:rel:0000000000000000000000000000000000000010", | ||||
"swh:1:rev:0000000000000000000000000000000000000009", | "swh:1:rev:0000000000000000000000000000000000000009", | ||||
"swh:1:dir:0000000000000000000000000000000000000008", | "swh:1:dir:0000000000000000000000000000000000000008", | ||||
"swh:1:dir:0000000000000000000000000000000000000006", | "swh:1:dir:0000000000000000000000000000000000000006", | ||||
"swh:1:cnt:0000000000000000000000000000000000000004" | "swh:1:cnt:0000000000000000000000000000000000000004" | ||||
)); | )); | ||||
expectedPaths.add( | expectedPaths.add( | ||||
new SwhPath( | new SwhPath( | ||||
"swh:1:ori:0000000000000000000000000000000000000021", | |||||
"swh:1:snp:0000000000000000000000000000000000000020", | "swh:1:snp:0000000000000000000000000000000000000020", | ||||
"swh:1:rel:0000000000000000000000000000000000000010", | "swh:1:rel:0000000000000000000000000000000000000010", | ||||
"swh:1:rev:0000000000000000000000000000000000000009", | "swh:1:rev:0000000000000000000000000000000000000009", | ||||
"swh:1:dir:0000000000000000000000000000000000000008", | "swh:1:dir:0000000000000000000000000000000000000008", | ||||
"swh:1:dir:0000000000000000000000000000000000000006", | "swh:1:dir:0000000000000000000000000000000000000006", | ||||
"swh:1:cnt:0000000000000000000000000000000000000005" | "swh:1:cnt:0000000000000000000000000000000000000005" | ||||
)); | )); | ||||
expectedPaths.add( | expectedPaths.add( | ||||
new SwhPath( | new SwhPath( | ||||
"swh:1:ori:0000000000000000000000000000000000000021", | |||||
"swh:1:snp:0000000000000000000000000000000000000020", | "swh:1:snp:0000000000000000000000000000000000000020", | ||||
"swh:1:rel:0000000000000000000000000000000000000010", | "swh:1:rel:0000000000000000000000000000000000000010", | ||||
"swh:1:rev:0000000000000000000000000000000000000009", | "swh:1:rev:0000000000000000000000000000000000000009", | ||||
"swh:1:rev:0000000000000000000000000000000000000003", | "swh:1:rev:0000000000000000000000000000000000000003", | ||||
"swh:1:dir:0000000000000000000000000000000000000002", | "swh:1:dir:0000000000000000000000000000000000000002", | ||||
"swh:1:cnt:0000000000000000000000000000000000000001" | "swh:1:cnt:0000000000000000000000000000000000000001" | ||||
)); | )); | ||||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | public void forwardFromLeaf() { | ||||
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(); | Graph graph = getGraph(); | ||||
SwhId swhId = new SwhId("swh:1:snp:0000000000000000000000000000000000000020"); | SwhId swhId = new SwhId("swh:1:ori:0000000000000000000000000000000000000021"); | ||||
Endpoint endpoint = new Endpoint(graph, "backward", "*"); | Endpoint endpoint = new Endpoint(graph, "backward", "*"); | ||||
ArrayList<SwhPath> paths = endpoint.visitPaths(swhId); | ArrayList<SwhPath> paths = endpoint.visitPaths(swhId); | ||||
ArrayList<SwhId> nodes = endpoint.visitNodes(swhId); | ArrayList<SwhId> nodes = endpoint.visitNodes(swhId); | ||||
ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ArrayList<SwhPath> expectedPaths = new ArrayList<SwhPath>(); | ||||
expectedPaths.add( | expectedPaths.add( | ||||
new SwhPath( | new SwhPath( | ||||
"swh:1:snp:0000000000000000000000000000000000000020" | "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() { | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | expectedPaths.add( | ||||
"swh:1:rel:0000000000000000000000000000000000000019" | "swh:1:rel:0000000000000000000000000000000000000019" | ||||
)); | )); | ||||
expectedPaths.add( | expectedPaths.add( | ||||
new SwhPath( | new SwhPath( | ||||
"swh:1:cnt:0000000000000000000000000000000000000004", | "swh:1:cnt:0000000000000000000000000000000000000004", | ||||
"swh:1:dir:0000000000000000000000000000000000000006", | "swh:1:dir:0000000000000000000000000000000000000006", | ||||
"swh:1:dir:0000000000000000000000000000000000000008", | "swh:1:dir:0000000000000000000000000000000000000008", | ||||
"swh:1:rev:0000000000000000000000000000000000000009", | "swh:1:rev:0000000000000000000000000000000000000009", | ||||
"swh:1:snp:0000000000000000000000000000000000000020" | "swh:1:snp:0000000000000000000000000000000000000020", | ||||
"swh:1:ori:0000000000000000000000000000000000000021" | |||||
)); | )); | ||||
expectedPaths.add( | expectedPaths.add( | ||||
new SwhPath( | new SwhPath( | ||||
"swh:1:cnt:0000000000000000000000000000000000000004", | "swh:1:cnt:0000000000000000000000000000000000000004", | ||||
"swh:1:dir:0000000000000000000000000000000000000006", | "swh:1:dir:0000000000000000000000000000000000000006", | ||||
"swh:1:dir:0000000000000000000000000000000000000008", | "swh:1:dir:0000000000000000000000000000000000000008", | ||||
"swh:1:rev:0000000000000000000000000000000000000009", | "swh:1:rev:0000000000000000000000000000000000000009", | ||||
"swh:1:rel:0000000000000000000000000000000000000010", | "swh:1:rel:0000000000000000000000000000000000000010", | ||||
"swh:1:snp:0000000000000000000000000000000000000020" | "swh:1:snp:0000000000000000000000000000000000000020", | ||||
"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() { | ||||
▲ Show 20 Lines • Show All 198 Lines • ▼ Show 20 Lines | public void backwardRevToRevRevToRel() { | ||||
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(); | Graph graph = getGraph(); | ||||
SwhId swhId = new SwhId("swh:1:snp:0000000000000000000000000000000000000020"); | SwhId swhId = new SwhId("swh:1:ori:0000000000000000000000000000000000000021"); | ||||
Endpoint endpoint = new Endpoint(graph, "forward", "*"); | Endpoint endpoint = new Endpoint(graph, "forward", "*"); | ||||
ArrayList<SwhId> nodes = endpoint.visitNodes(swhId); | ArrayList<SwhId> nodes = endpoint.visitNodes(swhId); | ||||
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: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")); | ||||
Show All 26 Lines |