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.jupiter.api.Assertions; | import org.junit.jupiter.api.Assertions; | ||||
import org.junit.jupiter.api.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(); | SwhBidirectionalGraph 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"; | ||||
SwhPath solution1 = new SwhPath("swh:1:snp:0000000000000000000000000000000000000020", | SwhPath solution1 = new SwhPath("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"); | ||||
Show All 11 Lines | public void forwardRootToLeaf() { | ||||
List<SwhPath> possibleSolutions = Arrays.asList(solution1, solution2); | List<SwhPath> possibleSolutions = Arrays.asList(solution1, solution2); | ||||
Assertions.assertTrue(possibleSolutions.contains(dfsPath)); | Assertions.assertTrue(possibleSolutions.contains(dfsPath)); | ||||
Assertions.assertTrue(possibleSolutions.contains(bfsPath)); | Assertions.assertTrue(possibleSolutions.contains(bfsPath)); | ||||
} | } | ||||
@Test | @Test | ||||
public void forwardLeafToLeaf() { | public void forwardLeafToLeaf() { | ||||
Graph graph = getGraph(); | SwhBidirectionalGraph 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 = new SwhPath("swh:1:cnt:0000000000000000000000000000000000000007"); | SwhPath expectedPath = new SwhPath("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; | ||||
Assertions.assertEquals(dfsPath, expectedPath); | Assertions.assertEquals(dfsPath, expectedPath); | ||||
Assertions.assertEquals(bfsPath, expectedPath); | Assertions.assertEquals(bfsPath, expectedPath); | ||||
} | } | ||||
@Test | @Test | ||||
public void forwardRevToRev() { | public void forwardRevToRev() { | ||||
Graph graph = getGraph(); | SwhBidirectionalGraph 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 = new SwhPath("swh:1:rev:0000000000000000000000000000000000000018", | SwhPath expectedPath = new SwhPath("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; | ||||
Assertions.assertEquals(dfsPath, expectedPath); | Assertions.assertEquals(dfsPath, expectedPath); | ||||
Assertions.assertEquals(bfsPath, expectedPath); | Assertions.assertEquals(bfsPath, expectedPath); | ||||
} | } | ||||
@Test | @Test | ||||
public void backwardRevToRev() { | public void backwardRevToRev() { | ||||
Graph graph = getGraph(); | SwhBidirectionalGraph 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 = new SwhPath("swh:1:rev:0000000000000000000000000000000000000003", | SwhPath expectedPath = 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"); | ||||
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; | ||||
Assertions.assertEquals(dfsPath, expectedPath); | Assertions.assertEquals(dfsPath, expectedPath); | ||||
Assertions.assertEquals(bfsPath, expectedPath); | Assertions.assertEquals(bfsPath, expectedPath); | ||||
} | } | ||||
@Test | @Test | ||||
public void backwardCntToFirstSnp() { | public void backwardCntToFirstSnp() { | ||||
Graph graph = getGraph(); | SwhBidirectionalGraph graph = getGraph(); | ||||
SWHID src = new SWHID("swh:1:cnt:0000000000000000000000000000000000000001"); | SWHID src = new SWHID("swh:1:cnt:0000000000000000000000000000000000000001"); | ||||
String dstFmt = "snp"; | String dstFmt = "snp"; | ||||
SwhPath solution1 = new SwhPath("swh:1:cnt:0000000000000000000000000000000000000001", | SwhPath solution1 = new SwhPath("swh:1:cnt:0000000000000000000000000000000000000001", | ||||
"swh:1:dir:0000000000000000000000000000000000000002", | "swh:1:dir:0000000000000000000000000000000000000002", | ||||
"swh:1:rev:0000000000000000000000000000000000000003", | "swh:1:rev:0000000000000000000000000000000000000003", | ||||
"swh:1:rev:0000000000000000000000000000000000000009", | "swh:1:rev:0000000000000000000000000000000000000009", | ||||
"swh:1:snp:0000000000000000000000000000000000000020"); | "swh:1:snp:0000000000000000000000000000000000000020"); | ||||
Show All 20 Lines | public void backwardCntToFirstSnp() { | ||||
List<SwhPath> possibleSolutions = Arrays.asList(solution1, solution2, solution3, solution4); | List<SwhPath> possibleSolutions = Arrays.asList(solution1, solution2, solution3, solution4); | ||||
Assertions.assertTrue(possibleSolutions.contains(dfsPath)); | Assertions.assertTrue(possibleSolutions.contains(dfsPath)); | ||||
Assertions.assertTrue(possibleSolutions.contains(bfsPath)); | Assertions.assertTrue(possibleSolutions.contains(bfsPath)); | ||||
} | } | ||||
@Test | @Test | ||||
public void forwardRevToFirstCnt() { | public void forwardRevToFirstCnt() { | ||||
Graph graph = getGraph(); | SwhBidirectionalGraph graph = getGraph(); | ||||
SWHID src = new SWHID("swh:1:rev:0000000000000000000000000000000000000009"); | SWHID src = new SWHID("swh:1:rev:0000000000000000000000000000000000000009"); | ||||
String dstFmt = "cnt"; | String dstFmt = "cnt"; | ||||
SwhPath solution1 = new SwhPath("swh:1:rev:0000000000000000000000000000000000000009", | SwhPath solution1 = new SwhPath("swh:1:rev:0000000000000000000000000000000000000009", | ||||
"swh:1:dir:0000000000000000000000000000000000000008", | "swh:1:dir:0000000000000000000000000000000000000008", | ||||
"swh:1:cnt:0000000000000000000000000000000000000007"); | "swh:1:cnt:0000000000000000000000000000000000000007"); | ||||
SwhPath solution2 = new SwhPath("swh:1:rev:0000000000000000000000000000000000000009", | SwhPath solution2 = new SwhPath("swh:1:rev:0000000000000000000000000000000000000009", | ||||
"swh:1:dir:0000000000000000000000000000000000000008", | "swh:1:dir:0000000000000000000000000000000000000008", | ||||
Show All 18 Lines | public void forwardRevToFirstCnt() { | ||||
List<SwhPath> possibleSolutions = Arrays.asList(solution1, solution2, solution3, solution4, solution5); | List<SwhPath> possibleSolutions = Arrays.asList(solution1, solution2, solution3, solution4, solution5); | ||||
Assertions.assertTrue(possibleSolutions.contains(dfsPath)); | Assertions.assertTrue(possibleSolutions.contains(dfsPath)); | ||||
Assertions.assertTrue(possibleSolutions.contains(bfsPath)); | Assertions.assertTrue(possibleSolutions.contains(bfsPath)); | ||||
} | } | ||||
@Test | @Test | ||||
public void backwardDirToFirstRel() { | public void backwardDirToFirstRel() { | ||||
Graph graph = getGraph(); | SwhBidirectionalGraph 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 = new SwhPath("swh:1:dir:0000000000000000000000000000000000000016", | SwhPath expectedPath = new SwhPath("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"); | ||||
Show All 9 Lines |