Changeset View
Changeset View
Standalone View
Standalone View
java/server/src/test/java/org/softwareheritage/graph/WalkTest.java
Show All 33 Lines | SwhPath solution2 = | ||||
"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" | ||||
); | ); | ||||
SwhPath dfsPath = (SwhPath) endpoint.walk(src, dstFmt, "dfs").result; | SwhPath dfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; | ||||
SwhPath bfsPath = (SwhPath) endpoint.walk(src, dstFmt, "bfs").result; | SwhPath bfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; | ||||
List<SwhPath> possibleSolutions = Arrays.asList(solution1, solution2); | List<SwhPath> possibleSolutions = Arrays.asList(solution1, solution2); | ||||
Assert.assertTrue(possibleSolutions.contains(dfsPath)); | Assert.assertTrue(possibleSolutions.contains(dfsPath)); | ||||
Assert.assertTrue(possibleSolutions.contains(bfsPath)); | Assert.assertTrue(possibleSolutions.contains(bfsPath)); | ||||
} | } | ||||
@Test | @Test | ||||
public void forwardLeafToLeaf() { | public void forwardLeafToLeaf() { | ||||
Graph graph = getGraph(); | Graph graph = getGraph(); | ||||
Endpoint endpoint = new Endpoint(graph, "forward", "*"); | Endpoint endpoint = new Endpoint(graph, "forward", "*"); | ||||
SwhPID src = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007"); | SwhPID src = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007"); | ||||
String dstFmt = "cnt"; | String dstFmt = "cnt"; | ||||
SwhPath expectedPath = | SwhPath expectedPath = | ||||
new SwhPath( | new SwhPath( | ||||
"swh:1:cnt:0000000000000000000000000000000000000007" | "swh:1:cnt:0000000000000000000000000000000000000007" | ||||
); | ); | ||||
SwhPath dfsPath = (SwhPath) endpoint.walk(src, dstFmt, "dfs").result; | SwhPath dfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; | ||||
SwhPath bfsPath = (SwhPath) endpoint.walk(src, dstFmt, "bfs").result; | SwhPath bfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; | ||||
Assert.assertEquals(dfsPath, expectedPath); | Assert.assertEquals(dfsPath, expectedPath); | ||||
Assert.assertEquals(bfsPath, expectedPath); | Assert.assertEquals(bfsPath, expectedPath); | ||||
} | } | ||||
@Test | @Test | ||||
public void forwardRevToRev() { | public void forwardRevToRev() { | ||||
Graph graph = getGraph(); | Graph graph = getGraph(); | ||||
Endpoint endpoint = new Endpoint(graph, "forward", "rev:rev"); | Endpoint endpoint = new Endpoint(graph, "forward", "rev:rev"); | ||||
SwhPID src = new SwhPID("swh:1:rev:0000000000000000000000000000000000000018"); | SwhPID src = new SwhPID("swh:1:rev:0000000000000000000000000000000000000018"); | ||||
String dstFmt = "swh:1:rev:0000000000000000000000000000000000000003"; | String dstFmt = "swh:1:rev:0000000000000000000000000000000000000003"; | ||||
SwhPath expectedPath = | SwhPath expectedPath = | ||||
new SwhPath( | new SwhPath( | ||||
"swh:1:rev:0000000000000000000000000000000000000018", | "swh:1:rev:0000000000000000000000000000000000000018", | ||||
"swh:1:rev:0000000000000000000000000000000000000013", | "swh:1:rev:0000000000000000000000000000000000000013", | ||||
"swh:1:rev:0000000000000000000000000000000000000009", | "swh:1:rev:0000000000000000000000000000000000000009", | ||||
"swh:1:rev:0000000000000000000000000000000000000003" | "swh:1:rev:0000000000000000000000000000000000000003" | ||||
); | ); | ||||
SwhPath dfsPath = (SwhPath) endpoint.walk(src, dstFmt, "dfs").result; | SwhPath dfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; | ||||
SwhPath bfsPath = (SwhPath) endpoint.walk(src, dstFmt, "bfs").result; | SwhPath bfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; | ||||
Assert.assertEquals(dfsPath, expectedPath); | Assert.assertEquals(dfsPath, expectedPath); | ||||
Assert.assertEquals(bfsPath, expectedPath); | Assert.assertEquals(bfsPath, expectedPath); | ||||
} | } | ||||
@Test | @Test | ||||
public void backwardRevToRev() { | public void backwardRevToRev() { | ||||
Graph graph = getGraph(); | Graph graph = getGraph(); | ||||
Endpoint endpoint = new Endpoint(graph, "backward", "rev:rev"); | Endpoint endpoint = new Endpoint(graph, "backward", "rev:rev"); | ||||
SwhPID src = new SwhPID("swh:1:rev:0000000000000000000000000000000000000003"); | SwhPID src = new SwhPID("swh:1:rev:0000000000000000000000000000000000000003"); | ||||
String dstFmt = "swh:1:rev:0000000000000000000000000000000000000018"; | String dstFmt = "swh:1:rev:0000000000000000000000000000000000000018"; | ||||
SwhPath expectedPath = | SwhPath expectedPath = | ||||
new SwhPath( | new SwhPath( | ||||
"swh:1:rev:0000000000000000000000000000000000000003", | "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" | ||||
); | ); | ||||
SwhPath dfsPath = (SwhPath) endpoint.walk(src, dstFmt, "dfs").result; | SwhPath dfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; | ||||
SwhPath bfsPath = (SwhPath) endpoint.walk(src, dstFmt, "bfs").result; | SwhPath bfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; | ||||
Assert.assertEquals(dfsPath, expectedPath); | Assert.assertEquals(dfsPath, expectedPath); | ||||
Assert.assertEquals(bfsPath, expectedPath); | Assert.assertEquals(bfsPath, expectedPath); | ||||
} | } | ||||
@Test | @Test | ||||
public void backwardCntToFirstSnp() { | public void backwardCntToFirstSnp() { | ||||
Graph graph = getGraph(); | Graph graph = getGraph(); | ||||
Show All 29 Lines | SwhPath solution4 = | ||||
new SwhPath( | new SwhPath( | ||||
"swh:1:cnt:0000000000000000000000000000000000000001", | "swh:1:cnt:0000000000000000000000000000000000000001", | ||||
"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" | ||||
); | ); | ||||
SwhPath dfsPath = (SwhPath) endpoint.walk(src, dstFmt, "dfs").result; | SwhPath dfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; | ||||
SwhPath bfsPath = (SwhPath) endpoint.walk(src, dstFmt, "bfs").result; | SwhPath bfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; | ||||
List<SwhPath> possibleSolutions = Arrays.asList(solution1, solution2, solution3, solution4); | List<SwhPath> possibleSolutions = Arrays.asList(solution1, solution2, solution3, solution4); | ||||
Assert.assertTrue(possibleSolutions.contains(dfsPath)); | Assert.assertTrue(possibleSolutions.contains(dfsPath)); | ||||
Assert.assertTrue(possibleSolutions.contains(bfsPath)); | Assert.assertTrue(possibleSolutions.contains(bfsPath)); | ||||
} | } | ||||
@Test | @Test | ||||
public void forwardRevToFirstCnt() { | public void forwardRevToFirstCnt() { | ||||
Show All 31 Lines | public void forwardRevToFirstCnt() { | ||||
SwhPath solution5 = | SwhPath solution5 = | ||||
new SwhPath( | new SwhPath( | ||||
"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" | ||||
); | ); | ||||
SwhPath dfsPath = (SwhPath) endpoint.walk(src, dstFmt, "dfs").result; | SwhPath dfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; | ||||
SwhPath bfsPath = (SwhPath) endpoint.walk(src, dstFmt, "bfs").result; | SwhPath bfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; | ||||
List<SwhPath> possibleSolutions = | List<SwhPath> possibleSolutions = | ||||
Arrays.asList(solution1, solution2, solution3, solution4, solution5); | Arrays.asList(solution1, solution2, solution3, solution4, solution5); | ||||
Assert.assertTrue(possibleSolutions.contains(dfsPath)); | Assert.assertTrue(possibleSolutions.contains(dfsPath)); | ||||
Assert.assertTrue(possibleSolutions.contains(bfsPath)); | Assert.assertTrue(possibleSolutions.contains(bfsPath)); | ||||
} | } | ||||
@Test | @Test | ||||
public void backwardDirToFirstRel() { | public void backwardDirToFirstRel() { | ||||
Graph graph = getGraph(); | Graph graph = getGraph(); | ||||
Endpoint endpoint = new Endpoint(graph, "backward", "dir:dir,dir:rev,rev:*"); | Endpoint endpoint = new Endpoint(graph, "backward", "dir:dir,dir:rev,rev:*"); | ||||
SwhPID src = new SwhPID("swh:1:dir:0000000000000000000000000000000000000016"); | SwhPID src = new SwhPID("swh:1:dir:0000000000000000000000000000000000000016"); | ||||
String dstFmt = "rel"; | String dstFmt = "rel"; | ||||
SwhPath expectedPath = | SwhPath expectedPath = | ||||
new SwhPath( | new SwhPath( | ||||
"swh:1:dir:0000000000000000000000000000000000000016", | "swh:1:dir:0000000000000000000000000000000000000016", | ||||
"swh:1:dir:0000000000000000000000000000000000000017", | "swh:1:dir:0000000000000000000000000000000000000017", | ||||
"swh:1:rev:0000000000000000000000000000000000000018", | "swh:1:rev:0000000000000000000000000000000000000018", | ||||
"swh:1:rel:0000000000000000000000000000000000000019" | "swh:1:rel:0000000000000000000000000000000000000019" | ||||
); | ); | ||||
SwhPath dfsPath = (SwhPath) endpoint.walk(src, dstFmt, "dfs").result; | SwhPath dfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; | ||||
SwhPath bfsPath = (SwhPath) endpoint.walk(src, dstFmt, "bfs").result; | SwhPath bfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; | ||||
Assert.assertEquals(dfsPath, expectedPath); | Assert.assertEquals(dfsPath, expectedPath); | ||||
Assert.assertEquals(bfsPath, expectedPath); | Assert.assertEquals(bfsPath, expectedPath); | ||||
} | } | ||||
} | } |