Skip to content

Commit ad92943

Browse files
Rewrite test
Co-authored-by: Veselin Nikolov <veselin.nikolov@neotechnology.com>
1 parent e9d8b9c commit ad92943

File tree

2 files changed

+104
-103
lines changed

2 files changed

+104
-103
lines changed

proc/path-finding/src/test/java/org/neo4j/gds/paths/sourcetarget/ShortestPathYensProc2Test.java

Lines changed: 0 additions & 103 deletions
This file was deleted.
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Neo4j is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
package org.neo4j.gds.paths.sourcetarget;
21+
22+
import org.junit.jupiter.api.BeforeEach;
23+
import org.junit.jupiter.params.ParameterizedTest;
24+
import org.junit.jupiter.params.provider.ValueSource;
25+
import org.neo4j.gds.BaseProcTest;
26+
import org.neo4j.gds.catalog.GraphProjectProc;
27+
import org.neo4j.gds.extension.Neo4jGraph;
28+
29+
import java.util.Collection;
30+
import java.util.HashSet;
31+
import java.util.List;
32+
33+
import static org.assertj.core.api.Assertions.assertThat;
34+
35+
class YensTestWithDifferentProjections extends BaseProcTest {
36+
37+
@Neo4jGraph
38+
private static final String DB_CYPHER =
39+
"CREATE (a:CITY), " +
40+
"(b:CITY), " +
41+
"(c:CITY), " +
42+
"(d:CITY), " +
43+
"(e:CITY), " +
44+
"(f:CITY), " +
45+
"(a)-[:ROAD]->(b), " +
46+
"(a)-[:ROAD]->(b), " +
47+
"(b)-[:ROAD]->(c), " +
48+
"(b)-[:ROAD]->(d), " +
49+
"(c)-[:ROAD]->(f), " +
50+
"(d)-[:ROAD]->(e), " +
51+
"(e)-[:ROAD]->(c), " +
52+
"(e)-[:ROAD]->(f), " +
53+
"(a)-[:PATH]->(b), " +
54+
"(d)-[:PATH]->(e), " +
55+
"(d)-[:PATH]->(e)";
56+
57+
@BeforeEach
58+
void setup() throws Exception {
59+
registerProcedures(
60+
ShortestPathYensStreamProc.class,
61+
GraphProjectProc.class
62+
);
63+
}
64+
65+
66+
@ParameterizedTest
67+
@ValueSource(strings = {
68+
"CALL gds.graph.project('g', '*', {TYPE: {type: '*', aggregation: 'SINGLE'}})",
69+
"CALL gds.graph.project.cypher('g', 'MATCH (n) RETURN id(n) AS id', 'MATCH (n)-[r]->(m) RETURN DISTINCT id(n) AS source, id(m) AS target')"
70+
})
71+
void shouldWorkWithDifferentProjections(String projectionQuery) {
72+
73+
runQuery(projectionQuery);
74+
String yensQuery = "MATCH (source), (target) " +
75+
"WHERE id(source)=0 AND id(target)=5 " +
76+
"CALL gds.shortestPath.yens.stream(" +
77+
" 'g', " +
78+
" {sourceNode:source, targetNode:target, k:3} " +
79+
") " +
80+
"YIELD nodeIds RETURN nodeIds ";
81+
82+
Collection<long[]> encounteredPaths = new HashSet<>();
83+
runQuery(yensQuery, result -> {
84+
assertThat(result.columns()).containsExactlyInAnyOrder("nodeIds");
85+
86+
while (result.hasNext()) {
87+
var next = result.next();
88+
var currentPath = (List<Long>) next.get("nodeIds");
89+
long[] pathToArray = currentPath.stream().mapToLong(l -> l).toArray();
90+
encounteredPaths.add(pathToArray);
91+
}
92+
93+
return true;
94+
});
95+
96+
assertThat(encounteredPaths).containsExactlyInAnyOrder(
97+
new long[]{0l, 1l, 3l, 4l, 2l, 5l},
98+
new long[]{0l, 1l, 3l, 4l, 5l},
99+
new long[]{0l, 1l, 2l, 5l}
100+
);
101+
}
102+
103+
}
104+

0 commit comments

Comments
 (0)