Differential D1850 Diff 6225 java/server/src/test/java/org/softwareheritage/graph/NeighborsTest.java
Changeset View
Changeset View
Standalone View
Standalone View
java/server/src/test/java/org/softwareheritage/graph/NeighborsTest.java
Show All 13 Lines | |||||
public class NeighborsTest extends GraphTest { | public class NeighborsTest extends GraphTest { | ||||
@Test | @Test | ||||
public void zeroNeighbor() { | public void zeroNeighbor() { | ||||
Graph graph = getGraph(); | Graph graph = getGraph(); | ||||
ArrayList<SwhPID> expectedNodes = new ArrayList<>(); | ArrayList<SwhPID> expectedNodes = new ArrayList<>(); | ||||
SwhPID src1 = new SwhPID("swh:1:ori:0000000000000000000000000000000000000021"); | SwhPID src1 = new SwhPID("swh:1:ori:0000000000000000000000000000000000000021"); | ||||
Endpoint endpoint1 = new Endpoint(graph, "backward", "*"); | Endpoint endpoint1 = new Endpoint(graph, "backward", "*"); | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes, (ArrayList) endpoint1.neighbors(src1).result); | ArrayList<SwhPID> actuals1 = (ArrayList) endpoint1.neighbors(new Endpoint.Input(src1)).result; | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes, actuals1); | |||||
SwhPID src2 = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004"); | SwhPID src2 = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004"); | ||||
Endpoint endpoint2 = new Endpoint(graph, "forward", "*"); | Endpoint endpoint2 = new Endpoint(graph, "forward", "*"); | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes, (ArrayList) endpoint2.neighbors(src2).result); | ArrayList<SwhPID> actuals2 = (ArrayList) endpoint2.neighbors(new Endpoint.Input(src2)).result; | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes, actuals2); | |||||
SwhPID src3 = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000015"); | SwhPID src3 = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000015"); | ||||
Endpoint endpoint3 = new Endpoint(graph, "forward", "*"); | Endpoint endpoint3 = new Endpoint(graph, "forward", "*"); | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes, (ArrayList) endpoint3.neighbors(src3).result); | ArrayList<SwhPID> actuals3 = (ArrayList) endpoint3.neighbors(new Endpoint.Input(src3)).result; | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes, actuals3); | |||||
SwhPID src4 = new SwhPID("swh:1:rel:0000000000000000000000000000000000000019"); | SwhPID src4 = new SwhPID("swh:1:rel:0000000000000000000000000000000000000019"); | ||||
Endpoint endpoint4 = new Endpoint(graph, "backward", "*"); | Endpoint endpoint4 = new Endpoint(graph, "backward", "*"); | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes, (ArrayList) endpoint4.neighbors(src4).result); | ArrayList<SwhPID> actuals4 = (ArrayList) endpoint4.neighbors(new Endpoint.Input(src4)).result; | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes, actuals4); | |||||
SwhPID src5 = new SwhPID("swh:1:dir:0000000000000000000000000000000000000008"); | SwhPID src5 = new SwhPID("swh:1:dir:0000000000000000000000000000000000000008"); | ||||
Endpoint endpoint5 = new Endpoint(graph, "forward", "snp:*,rev:*,rel:*"); | Endpoint endpoint5 = new Endpoint(graph, "forward", "snp:*,rev:*,rel:*"); | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes, (ArrayList) endpoint5.neighbors(src5).result); | ArrayList<SwhPID> actuals5 = (ArrayList) endpoint5.neighbors(new Endpoint.Input(src5)).result; | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes, actuals5); | |||||
} | } | ||||
@Test | @Test | ||||
public void oneNeighbor() { | public void oneNeighbor() { | ||||
Graph graph = getGraph(); | Graph graph = getGraph(); | ||||
SwhPID src1 = new SwhPID("swh:1:rev:0000000000000000000000000000000000000003"); | SwhPID src1 = new SwhPID("swh:1:rev:0000000000000000000000000000000000000003"); | ||||
Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); | Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); | ||||
ArrayList<SwhPID> expectedNodes1 = new ArrayList<>(); | ArrayList<SwhPID> expectedNodes1 = new ArrayList<>(); | ||||
expectedNodes1.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000002")); | expectedNodes1.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000002")); | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes1, (ArrayList) endpoint1.neighbors(src1).result); | ArrayList<SwhPID> actuals1 = (ArrayList) endpoint1.neighbors(new Endpoint.Input(src1)).result; | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes1, actuals1); | |||||
SwhPID src2 = new SwhPID("swh:1:dir:0000000000000000000000000000000000000017"); | SwhPID src2 = new SwhPID("swh:1:dir:0000000000000000000000000000000000000017"); | ||||
Endpoint endpoint2 = new Endpoint(graph, "forward", "dir:cnt"); | Endpoint endpoint2 = new Endpoint(graph, "forward", "dir:cnt"); | ||||
ArrayList<SwhPID> expectedNodes2 = new ArrayList<>(); | ArrayList<SwhPID> expectedNodes2 = new ArrayList<>(); | ||||
expectedNodes2.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000014")); | expectedNodes2.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000014")); | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes2, (ArrayList) endpoint2.neighbors(src2).result); | ArrayList<SwhPID> actuals2 = (ArrayList) endpoint2.neighbors(new Endpoint.Input(src2)).result; | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes2, actuals2); | |||||
SwhPID src3 = new SwhPID("swh:1:dir:0000000000000000000000000000000000000012"); | SwhPID src3 = new SwhPID("swh:1:dir:0000000000000000000000000000000000000012"); | ||||
Endpoint endpoint3 = new Endpoint(graph, "backward", "*"); | Endpoint endpoint3 = new Endpoint(graph, "backward", "*"); | ||||
ArrayList<SwhPID> expectedNodes3 = new ArrayList<>(); | ArrayList<SwhPID> expectedNodes3 = new ArrayList<>(); | ||||
expectedNodes3.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000013")); | expectedNodes3.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000013")); | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes3, (ArrayList) endpoint3.neighbors(src3).result); | ArrayList<SwhPID> actuals3 = (ArrayList) endpoint3.neighbors(new Endpoint.Input(src3)).result; | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes3, actuals3); | |||||
SwhPID src4 = new SwhPID("swh:1:rev:0000000000000000000000000000000000000009"); | SwhPID src4 = new SwhPID("swh:1:rev:0000000000000000000000000000000000000009"); | ||||
Endpoint endpoint4 = new Endpoint(graph, "backward", "rev:rev"); | Endpoint endpoint4 = new Endpoint(graph, "backward", "rev:rev"); | ||||
ArrayList<SwhPID> expectedNodes4 = new ArrayList<>(); | ArrayList<SwhPID> expectedNodes4 = new ArrayList<>(); | ||||
expectedNodes4.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000013")); | expectedNodes4.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000013")); | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes4, (ArrayList) endpoint4.neighbors(src4).result); | ArrayList<SwhPID> actuals4 = (ArrayList) endpoint4.neighbors(new Endpoint.Input(src4)).result; | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes4, actuals4); | |||||
SwhPID src5 = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); | SwhPID src5 = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); | ||||
Endpoint endpoint5 = new Endpoint(graph, "backward", "*"); | Endpoint endpoint5 = new Endpoint(graph, "backward", "*"); | ||||
ArrayList<SwhPID> expectedNodes5 = new ArrayList<>(); | ArrayList<SwhPID> expectedNodes5 = new ArrayList<>(); | ||||
expectedNodes5.add(new SwhPID("swh:1:ori:0000000000000000000000000000000000000021")); | expectedNodes5.add(new SwhPID("swh:1:ori:0000000000000000000000000000000000000021")); | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes5, (ArrayList) endpoint5.neighbors(src5).result); | ArrayList<SwhPID> actuals5 = (ArrayList) endpoint5.neighbors(new Endpoint.Input(src5)).result; | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes5, actuals5); | |||||
} | } | ||||
@Test | @Test | ||||
public void twoNeighbors() { | public void twoNeighbors() { | ||||
Graph graph = getGraph(); | Graph graph = getGraph(); | ||||
SwhPID src1 = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); | SwhPID src1 = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); | ||||
Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); | Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); | ||||
ArrayList<SwhPID> expectedNodes1 = new ArrayList<>(); | ArrayList<SwhPID> expectedNodes1 = new ArrayList<>(); | ||||
expectedNodes1.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000010")); | expectedNodes1.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000010")); | ||||
expectedNodes1.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000009")); | expectedNodes1.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000009")); | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes1, (ArrayList) endpoint1.neighbors(src1).result); | ArrayList<SwhPID> actuals1 = (ArrayList) endpoint1.neighbors(new Endpoint.Input(src1)).result; | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes1, actuals1); | |||||
SwhPID src2 = new SwhPID("swh:1:dir:0000000000000000000000000000000000000008"); | SwhPID src2 = new SwhPID("swh:1:dir:0000000000000000000000000000000000000008"); | ||||
Endpoint endpoint2 = new Endpoint(graph, "forward", "dir:cnt"); | Endpoint endpoint2 = new Endpoint(graph, "forward", "dir:cnt"); | ||||
ArrayList<SwhPID> expectedNodes2 = new ArrayList<>(); | ArrayList<SwhPID> expectedNodes2 = new ArrayList<>(); | ||||
expectedNodes2.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001")); | expectedNodes2.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001")); | ||||
expectedNodes2.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007")); | expectedNodes2.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007")); | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes2, (ArrayList) endpoint2.neighbors(src2).result); | ArrayList<SwhPID> actuals2 = (ArrayList) endpoint2.neighbors(new Endpoint.Input(src2)).result; | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes2, actuals2); | |||||
SwhPID src3 = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001"); | SwhPID src3 = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001"); | ||||
Endpoint endpoint3 = new Endpoint(graph, "backward", "*"); | Endpoint endpoint3 = new Endpoint(graph, "backward", "*"); | ||||
ArrayList<SwhPID> expectedNodes3 = new ArrayList<>(); | ArrayList<SwhPID> expectedNodes3 = new ArrayList<>(); | ||||
expectedNodes3.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000008")); | expectedNodes3.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000008")); | ||||
expectedNodes3.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000002")); | expectedNodes3.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000002")); | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes3, (ArrayList) endpoint3.neighbors(src3).result); | ArrayList<SwhPID> actuals3 = (ArrayList) endpoint3.neighbors(new Endpoint.Input(src3)).result; | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes3, actuals3); | |||||
SwhPID src4 = new SwhPID("swh:1:rev:0000000000000000000000000000000000000009"); | SwhPID src4 = new SwhPID("swh:1:rev:0000000000000000000000000000000000000009"); | ||||
Endpoint endpoint4 = new Endpoint(graph, "backward", "rev:snp,rev:rel"); | Endpoint endpoint4 = new Endpoint(graph, "backward", "rev:snp,rev:rel"); | ||||
ArrayList<SwhPID> expectedNodes4 = new ArrayList<>(); | ArrayList<SwhPID> expectedNodes4 = new ArrayList<>(); | ||||
expectedNodes4.add(new SwhPID("swh:1:snp:0000000000000000000000000000000000000020")); | expectedNodes4.add(new SwhPID("swh:1:snp:0000000000000000000000000000000000000020")); | ||||
expectedNodes4.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000010")); | expectedNodes4.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000010")); | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes4, (ArrayList) endpoint4.neighbors(src4).result); | ArrayList<SwhPID> actuals4 = (ArrayList) endpoint4.neighbors(new Endpoint.Input(src4)).result; | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes4, actuals4); | |||||
} | } | ||||
@Test | @Test | ||||
public void threeNeighbors() { | public void threeNeighbors() { | ||||
Graph graph = getGraph(); | Graph graph = getGraph(); | ||||
SwhPID src1 = new SwhPID("swh:1:dir:0000000000000000000000000000000000000008"); | SwhPID src1 = new SwhPID("swh:1:dir:0000000000000000000000000000000000000008"); | ||||
Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); | Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); | ||||
ArrayList<SwhPID> expectedNodes1 = new ArrayList<>(); | ArrayList<SwhPID> expectedNodes1 = new ArrayList<>(); | ||||
expectedNodes1.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000006")); | expectedNodes1.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000006")); | ||||
expectedNodes1.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001")); | expectedNodes1.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001")); | ||||
expectedNodes1.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007")); | expectedNodes1.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007")); | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes1, (ArrayList) endpoint1.neighbors(src1).result); | ArrayList<SwhPID> actuals1 = (ArrayList) endpoint1.neighbors(new Endpoint.Input(src1)).result; | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes1, actuals1); | |||||
SwhPID src2 = new SwhPID("swh:1:rev:0000000000000000000000000000000000000009"); | SwhPID src2 = new SwhPID("swh:1:rev:0000000000000000000000000000000000000009"); | ||||
Endpoint endpoint2 = new Endpoint(graph, "backward", "*"); | Endpoint endpoint2 = new Endpoint(graph, "backward", "*"); | ||||
ArrayList<SwhPID> expectedNodes2 = new ArrayList<>(); | ArrayList<SwhPID> expectedNodes2 = new ArrayList<>(); | ||||
expectedNodes2.add(new SwhPID("swh:1:snp:0000000000000000000000000000000000000020")); | expectedNodes2.add(new SwhPID("swh:1:snp:0000000000000000000000000000000000000020")); | ||||
expectedNodes2.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000010")); | expectedNodes2.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000010")); | ||||
expectedNodes2.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000013")); | expectedNodes2.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000013")); | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes2, (ArrayList) endpoint2.neighbors(src2).result); | ArrayList<SwhPID> actuals2 = (ArrayList) endpoint2.neighbors(new Endpoint.Input(src2)).result; | ||||
GraphTest.assertEqualsAnyOrder(expectedNodes2, actuals2); | |||||
} | } | ||||
} | } |