Skip to content
This repository has been archived by the owner on Apr 22, 2020. It is now read-only.

Commit

Permalink
default value for weight property for shortest path is null, making i…
Browse files Browse the repository at this point in the history
…t optional (#868)
  • Loading branch information
mneedham authored and jexp committed Apr 2, 2019
1 parent c9574ab commit 2806408
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
4 changes: 2 additions & 2 deletions algo/src/main/java/org/neo4j/graphalgo/ShortestPathProc.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class ShortestPathProc {
public Stream<ShortestPathDijkstra.Result> dijkstraStream(
@Name("startNode") Node startNode,
@Name("endNode") Node endNode,
@Name("propertyName") String propertyName,
@Name(value = "propertyName", defaultValue = "null") String propertyName,
@Name(value = "config", defaultValue = "{}")
Map<String, Object> config) {

Expand Down Expand Up @@ -121,7 +121,7 @@ public Stream<ShortestPathDijkstra.Result> dijkstraStream(
public Stream<DijkstraResult> dijkstra(
@Name("startNode") Node startNode,
@Name("endNode") Node endNode,
@Name("propertyName") String propertyName,
@Name(value = "propertyName", defaultValue="null") String propertyName,
@Name(value = "config", defaultValue = "{}")
Map<String, Object> config) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,54 @@ public static Collection<Object[]> data() {
@Parameterized.Parameter
public String graphImpl;

@Test
public void noWeightStream() throws Exception {
PathConsumer consumer = mock(PathConsumer.class);
DB.execute(
"MATCH (start:Node{type:'start'}), (end:Node{type:'end'}) " +
"CALL algo.shortestPath.stream(start, end) " +
"YIELD nodeId, cost RETURN nodeId, cost")
.accept((Result.ResultVisitor<Exception>) row -> {
consumer.accept((Long) row.getNumber("nodeId"), (Double) row.getNumber("cost"));
return true;
});
verify(consumer, times(2)).accept(anyLong(), anyDouble());
verify(consumer, times(1)).accept(anyLong(), eq(0.0));
verify(consumer, times(1)).accept(anyLong(), eq(1.0));
}

@Test
public void noWeightWrite() throws Exception {
DB.execute(
"MATCH (start:Node{type:'start'}), (end:Node{type:'end'}) " +
"CALL algo.shortestPath(start, end) " +
"YIELD loadMillis, evalMillis, writeMillis, nodeCount, totalCost\n" +
"RETURN loadMillis, evalMillis, writeMillis, nodeCount, totalCost")
.accept((Result.ResultVisitor<Exception>) row -> {
assertEquals(1.0, (Double) row.getNumber("totalCost"), 0.01);
assertEquals(2L, row.getNumber("nodeCount"));
assertNotEquals(-1L, row.getNumber("loadMillis"));
assertNotEquals(-1L, row.getNumber("evalMillis"));
assertNotEquals(-1L, row.getNumber("writeMillis"));
return false;
});

final StepConsumer mock = mock(StepConsumer.class);

DB.execute("MATCH (n) WHERE exists(n.sssp) RETURN id(n) as id, n.sssp as sssp")
.accept(row -> {
mock.accept(
row.getNumber("id").longValue(),
row.getNumber("sssp").intValue());
return true;
});

verify(mock, times(2)).accept(anyLong(), anyInt());

verify(mock, times(1)).accept(anyLong(), eq(0));
verify(mock, times(1)).accept(anyLong(), eq(1));
}

@Test
public void testDijkstraStream() throws Exception {
PathConsumer consumer = mock(PathConsumer.class);
Expand Down

0 comments on commit 2806408

Please sign in to comment.