Skip to content

Commit 4af8a55

Browse files
Make ClosenessCentralityStreamProcTest order indifferent
1 parent 8d35c8c commit 4af8a55

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

proc/centrality/src/test/java/org/neo4j/gds/closeness/ClosenessCentralityStreamProcTest.java

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020
package org.neo4j.gds.closeness;
2121

22-
import org.hamcrest.Matchers;
22+
import org.assertj.core.data.Offset;
2323
import org.junit.jupiter.api.BeforeEach;
2424
import org.junit.jupiter.api.Test;
2525
import org.neo4j.gds.BaseProcTest;
@@ -30,9 +30,11 @@
3030
import org.neo4j.gds.extension.Inject;
3131
import org.neo4j.gds.extension.Neo4jGraph;
3232

33-
import java.util.List;
3433
import java.util.Map;
3534

35+
import static java.util.Map.entry;
36+
import static org.assertj.core.api.Assertions.assertThat;
37+
3638
class ClosenessCentralityStreamProcTest extends BaseProcTest {
3739

3840
@Neo4jGraph
@@ -86,7 +88,7 @@ class ClosenessCentralityStreamProcTest extends BaseProcTest {
8688
@Inject
8789
private IdFunction idFunction;
8890

89-
private List<Map<String, Object>> expectedCentralityResult;
91+
private Map<Long, Double> expectedCentralityResult;
9092

9193
@BeforeEach
9294
void setupGraph() throws Exception {
@@ -95,19 +97,20 @@ void setupGraph() throws Exception {
9597
GraphProjectProc.class
9698
);
9799

98-
expectedCentralityResult = List.of(
99-
Map.of("nodeId", idFunction.of("n0"), "score", Matchers.closeTo(1.0, 0.01)),
100-
Map.of("nodeId", idFunction.of("n1"), "score", Matchers.closeTo(0.588, 0.01)),
101-
Map.of("nodeId", idFunction.of("n2"), "score", Matchers.closeTo(0.588, 0.01)),
102-
Map.of("nodeId", idFunction.of("n3"), "score", Matchers.closeTo(0.588, 0.01)),
103-
Map.of("nodeId", idFunction.of("n4"), "score", Matchers.closeTo(0.588, 0.01)),
104-
Map.of("nodeId", idFunction.of("n5"), "score", Matchers.closeTo(0.588, 0.01)),
105-
Map.of("nodeId", idFunction.of("n6"), "score", Matchers.closeTo(0.588, 0.01)),
106-
Map.of("nodeId", idFunction.of("n7"), "score", Matchers.closeTo(0.588, 0.01)),
107-
Map.of("nodeId", idFunction.of("n8"), "score", Matchers.closeTo(0.588, 0.01)),
108-
Map.of("nodeId", idFunction.of("n9"), "score", Matchers.closeTo(0.588, 0.01)),
109-
Map.of("nodeId", idFunction.of("n10"), "score", Matchers.closeTo(0.588, 0.01))
100+
expectedCentralityResult = Map.ofEntries(
101+
entry(idFunction.of("n0"), 1.0),
102+
entry(idFunction.of("n1"), 0.588),
103+
entry(idFunction.of("n2"), 0.588),
104+
entry(idFunction.of("n3"), 0.588),
105+
entry(idFunction.of("n4"), 0.588),
106+
entry(idFunction.of("n5"), 0.588),
107+
entry(idFunction.of("n6"), 0.588),
108+
entry(idFunction.of("n7"), 0.588),
109+
entry(idFunction.of("n8"), 0.588),
110+
entry(idFunction.of("n9"), 0.588),
111+
entry(idFunction.of("n10"), 0.588)
110112
);
113+
111114
loadCompleteGraph(DEFAULT_GRAPH_NAME, Orientation.UNDIRECTED);
112115
}
113116

@@ -118,7 +121,13 @@ void shouldStream() {
118121
.streamMode()
119122
.yields("nodeId", "score");
120123

121-
assertCypherResult(query, expectedCentralityResult);
124+
var rowCount = runQueryWithRowConsumer(query, row -> {
125+
var nodeId = row.getNumber("nodeId").longValue();
126+
var property = row.getNumber("score").doubleValue();
127+
assertThat(expectedCentralityResult.get(nodeId)).isCloseTo(property, Offset.offset(0.01));
128+
}
129+
);
130+
assertThat(rowCount).isEqualTo(11);
122131
}
123132

124133
}

0 commit comments

Comments
 (0)