Changeset View
Changeset View
Standalone View
Standalone View
java/src/test/java/org/softwareheritage/graph/WalkTest.java
package org.softwareheritage.graph; | package org.softwareheritage.graph; | ||||
import java.util.Arrays; | import java.util.Arrays; | ||||
import java.util.List; | import java.util.List; | ||||
import org.junit.Assert; | import org.junit.jupiter.api.Assertions; | ||||
import org.junit.Test; | import org.junit.jupiter.api.Test; | ||||
import org.softwareheritage.graph.server.Endpoint; | import org.softwareheritage.graph.server.Endpoint; | ||||
public class WalkTest extends GraphTest { | public class WalkTest extends GraphTest { | ||||
@Test | @Test | ||||
public void forwardRootToLeaf() { | public void forwardRootToLeaf() { | ||||
Graph graph = getGraph(); | Graph graph = getGraph(); | ||||
SWHID src = new SWHID("swh:1:snp:0000000000000000000000000000000000000020"); | SWHID src = new SWHID("swh:1:snp:0000000000000000000000000000000000000020"); | ||||
String dstFmt = "swh:1:cnt:0000000000000000000000000000000000000005"; | String dstFmt = "swh:1:cnt:0000000000000000000000000000000000000005"; | ||||
Show All 17 Lines | public void forwardRootToLeaf() { | ||||
); | ); | ||||
Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); | Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); | ||||
SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; | SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; | ||||
Endpoint endpoint2 = new Endpoint(graph, "forward", "*"); | Endpoint endpoint2 = new Endpoint(graph, "forward", "*"); | ||||
SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; | 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)); | Assertions.assertTrue(possibleSolutions.contains(dfsPath)); | ||||
Assert.assertTrue(possibleSolutions.contains(bfsPath)); | Assertions.assertTrue(possibleSolutions.contains(bfsPath)); | ||||
} | } | ||||
@Test | @Test | ||||
public void forwardLeafToLeaf() { | public void forwardLeafToLeaf() { | ||||
Graph graph = getGraph(); | Graph graph = getGraph(); | ||||
SWHID src = new SWHID("swh:1:cnt:0000000000000000000000000000000000000007"); | SWHID src = new SWHID("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" | ||||
); | ); | ||||
Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); | Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); | ||||
SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; | SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; | ||||
Endpoint endpoint2 = new Endpoint(graph, "forward", "*"); | Endpoint endpoint2 = new Endpoint(graph, "forward", "*"); | ||||
SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; | SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; | ||||
Assert.assertEquals(dfsPath, expectedPath); | Assertions.assertEquals(dfsPath, expectedPath); | ||||
Assert.assertEquals(bfsPath, expectedPath); | Assertions.assertEquals(bfsPath, expectedPath); | ||||
} | } | ||||
@Test | @Test | ||||
public void forwardRevToRev() { | public void forwardRevToRev() { | ||||
Graph graph = getGraph(); | Graph graph = getGraph(); | ||||
SWHID src = new SWHID("swh:1:rev:0000000000000000000000000000000000000018"); | SWHID src = new SWHID("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" | ||||
); | ); | ||||
Endpoint endpoint1 = new Endpoint(graph, "forward", "rev:rev"); | Endpoint endpoint1 = new Endpoint(graph, "forward", "rev:rev"); | ||||
SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; | SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; | ||||
Endpoint endpoint2 = new Endpoint(graph, "forward", "rev:rev"); | Endpoint endpoint2 = new Endpoint(graph, "forward", "rev:rev"); | ||||
SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; | SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; | ||||
Assert.assertEquals(dfsPath, expectedPath); | Assertions.assertEquals(dfsPath, expectedPath); | ||||
Assert.assertEquals(bfsPath, expectedPath); | Assertions.assertEquals(bfsPath, expectedPath); | ||||
} | } | ||||
@Test | @Test | ||||
public void backwardRevToRev() { | public void backwardRevToRev() { | ||||
Graph graph = getGraph(); | Graph graph = getGraph(); | ||||
SWHID src = new SWHID("swh:1:rev:0000000000000000000000000000000000000003"); | SWHID src = new SWHID("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" | ||||
); | ); | ||||
Endpoint endpoint1 = new Endpoint(graph, "backward", "rev:rev"); | Endpoint endpoint1 = new Endpoint(graph, "backward", "rev:rev"); | ||||
SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; | SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; | ||||
Endpoint endpoint2 = new Endpoint(graph, "backward", "rev:rev"); | Endpoint endpoint2 = new Endpoint(graph, "backward", "rev:rev"); | ||||
SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; | SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; | ||||
Assert.assertEquals(dfsPath, expectedPath); | Assertions.assertEquals(dfsPath, expectedPath); | ||||
Assert.assertEquals(bfsPath, expectedPath); | Assertions.assertEquals(bfsPath, expectedPath); | ||||
} | } | ||||
@Test | @Test | ||||
public void backwardCntToFirstSnp() { | public void backwardCntToFirstSnp() { | ||||
Graph graph = getGraph(); | Graph graph = getGraph(); | ||||
SWHID src = new SWHID("swh:1:cnt:0000000000000000000000000000000000000001"); | SWHID src = new SWHID("swh:1:cnt:0000000000000000000000000000000000000001"); | ||||
String dstFmt = "snp"; | String dstFmt = "snp"; | ||||
Show All 31 Lines | public void backwardCntToFirstSnp() { | ||||
); | ); | ||||
Endpoint endpoint1 = new Endpoint(graph, "backward", "*"); | Endpoint endpoint1 = new Endpoint(graph, "backward", "*"); | ||||
SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; | SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; | ||||
Endpoint endpoint2 = new Endpoint(graph, "backward", "*"); | Endpoint endpoint2 = new Endpoint(graph, "backward", "*"); | ||||
SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; | 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)); | Assertions.assertTrue(possibleSolutions.contains(dfsPath)); | ||||
Assert.assertTrue(possibleSolutions.contains(bfsPath)); | Assertions.assertTrue(possibleSolutions.contains(bfsPath)); | ||||
} | } | ||||
@Test | @Test | ||||
public void forwardRevToFirstCnt() { | public void forwardRevToFirstCnt() { | ||||
Graph graph = getGraph(); | Graph graph = getGraph(); | ||||
SWHID src = new SWHID("swh:1:rev:0000000000000000000000000000000000000009"); | SWHID src = new SWHID("swh:1:rev:0000000000000000000000000000000000000009"); | ||||
String dstFmt = "cnt"; | String dstFmt = "cnt"; | ||||
Show All 33 Lines | public void forwardRevToFirstCnt() { | ||||
Endpoint endpoint1 = new Endpoint(graph, "forward", "rev:*,dir:*"); | Endpoint endpoint1 = new Endpoint(graph, "forward", "rev:*,dir:*"); | ||||
SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; | SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; | ||||
Endpoint endpoint2 = new Endpoint(graph, "forward", "rev:*,dir:*"); | Endpoint endpoint2 = new Endpoint(graph, "forward", "rev:*,dir:*"); | ||||
SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; | 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)); | Assertions.assertTrue(possibleSolutions.contains(dfsPath)); | ||||
Assert.assertTrue(possibleSolutions.contains(bfsPath)); | Assertions.assertTrue(possibleSolutions.contains(bfsPath)); | ||||
} | } | ||||
@Test | @Test | ||||
public void backwardDirToFirstRel() { | public void backwardDirToFirstRel() { | ||||
Graph graph = getGraph(); | Graph graph = getGraph(); | ||||
SWHID src = new SWHID("swh:1:dir:0000000000000000000000000000000000000016"); | SWHID src = new SWHID("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" | ||||
); | ); | ||||
Endpoint endpoint1 = new Endpoint(graph, "backward", "dir:dir,dir:rev,rev:*"); | Endpoint endpoint1 = new Endpoint(graph, "backward", "dir:dir,dir:rev,rev:*"); | ||||
SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; | SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; | ||||
Endpoint endpoint2 = new Endpoint(graph, "backward", "dir:dir,dir:rev,rev:*"); | Endpoint endpoint2 = new Endpoint(graph, "backward", "dir:dir,dir:rev,rev:*"); | ||||
SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; | SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; | ||||
Assert.assertEquals(dfsPath, expectedPath); | Assertions.assertEquals(dfsPath, expectedPath); | ||||
Assert.assertEquals(bfsPath, expectedPath); | Assertions.assertEquals(bfsPath, expectedPath); | ||||
} | } | ||||
} | } |