Changeset View
Changeset View
Standalone View
Standalone View
java/server/src/test/java/org/softwareheritage/graph/WalkTest.java
Show All 11 Lines | |||||
import org.softwareheritage.graph.GraphTest; | import org.softwareheritage.graph.GraphTest; | ||||
import org.softwareheritage.graph.SwhPID; | import org.softwareheritage.graph.SwhPID; | ||||
import org.softwareheritage.graph.SwhPath; | import org.softwareheritage.graph.SwhPath; | ||||
public class WalkTest extends GraphTest { | public class WalkTest extends GraphTest { | ||||
@Test | @Test | ||||
public void forwardRootToLeaf() { | public void forwardRootToLeaf() { | ||||
Graph graph = getGraph(); | Graph graph = getGraph(); | ||||
Endpoint endpoint = new Endpoint(graph, "forward", "*"); | |||||
SwhPID src = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); | SwhPID src = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); | ||||
String dstFmt = "swh:1:cnt:0000000000000000000000000000000000000005"; | String dstFmt = "swh:1:cnt:0000000000000000000000000000000000000005"; | ||||
SwhPath solution1 = | SwhPath solution1 = | ||||
new SwhPath( | new SwhPath( | ||||
"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" | ||||
); | ); | ||||
SwhPath solution2 = | SwhPath solution2 = | ||||
new SwhPath( | new SwhPath( | ||||
"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(new Endpoint.Input(src, dstFmt, "dfs")).result; | Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); | ||||
SwhPath bfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; | 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<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", "*"); | |||||
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(new Endpoint.Input(src, dstFmt, "dfs")).result; | Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); | ||||
SwhPath bfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; | 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(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"); | |||||
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(new Endpoint.Input(src, dstFmt, "dfs")).result; | Endpoint endpoint1 = new Endpoint(graph, "forward", "rev:rev"); | ||||
SwhPath bfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; | 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(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"); | |||||
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(new Endpoint.Input(src, dstFmt, "dfs")).result; | Endpoint endpoint1 = new Endpoint(graph, "backward", "rev:rev"); | ||||
SwhPath bfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; | 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(dfsPath, expectedPath); | ||||
Assert.assertEquals(bfsPath, expectedPath); | Assert.assertEquals(bfsPath, expectedPath); | ||||
} | } | ||||
@Test | @Test | ||||
public void backwardCntToFirstSnp() { | public void backwardCntToFirstSnp() { | ||||
Graph graph = getGraph(); | Graph graph = getGraph(); | ||||
Endpoint endpoint = new Endpoint(graph, "backward", "*"); | |||||
SwhPID src = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001"); | SwhPID src = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001"); | ||||
String dstFmt = "snp"; | String dstFmt = "snp"; | ||||
SwhPath solution1 = | SwhPath solution1 = | ||||
new SwhPath( | new SwhPath( | ||||
"swh:1:cnt:0000000000000000000000000000000000000001", | "swh:1:cnt:0000000000000000000000000000000000000001", | ||||
"swh:1:dir:0000000000000000000000000000000000000002", | "swh:1:dir:0000000000000000000000000000000000000002", | ||||
"swh:1:rev:0000000000000000000000000000000000000003", | "swh:1:rev:0000000000000000000000000000000000000003", | ||||
Show All 20 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(new Endpoint.Input(src, dstFmt, "dfs")).result; | Endpoint endpoint1 = new Endpoint(graph, "backward", "*"); | ||||
SwhPath bfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; | 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<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() { | ||||
Graph graph = getGraph(); | Graph graph = getGraph(); | ||||
Endpoint endpoint = new Endpoint(graph, "forward", "rev:*,dir:*"); | |||||
SwhPID src = new SwhPID("swh:1:rev:0000000000000000000000000000000000000009"); | SwhPID src = new SwhPID("swh:1:rev:0000000000000000000000000000000000000009"); | ||||
String dstFmt = "cnt"; | String dstFmt = "cnt"; | ||||
SwhPath solution1 = | SwhPath solution1 = | ||||
new SwhPath( | new SwhPath( | ||||
"swh:1:rev:0000000000000000000000000000000000000009", | "swh:1:rev:0000000000000000000000000000000000000009", | ||||
"swh:1:dir:0000000000000000000000000000000000000008", | "swh:1:dir:0000000000000000000000000000000000000008", | ||||
"swh:1:cnt:0000000000000000000000000000000000000007" | "swh:1:cnt:0000000000000000000000000000000000000007" | ||||
Show All 21 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(new Endpoint.Input(src, dstFmt, "dfs")).result; | Endpoint endpoint1 = new Endpoint(graph, "forward", "rev:*,dir:*"); | ||||
SwhPath bfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; | 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<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:*"); | |||||
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(new Endpoint.Input(src, dstFmt, "dfs")).result; | Endpoint endpoint1 = new Endpoint(graph, "backward", "dir:dir,dir:rev,rev:*"); | ||||
SwhPath bfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; | 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(dfsPath, expectedPath); | ||||
Assert.assertEquals(bfsPath, expectedPath); | Assert.assertEquals(bfsPath, expectedPath); | ||||
} | } | ||||
} | } |