1919 */
2020package org .neo4j .gds .beta .pregel .pr ;
2121
22+ import org .assertj .core .data .Offset ;
2223import org .junit .jupiter .api .BeforeEach ;
2324import org .junit .jupiter .api .Test ;
2425import org .neo4j .gds .BaseProcTest ;
2728import org .neo4j .gds .core .utils .mem .MemoryRange ;
2829import org .neo4j .gds .extension .Neo4jGraph ;
2930
30- import java .util .List ;
3131import java .util .Map ;
3232
33- import static org .hamcrest .Matchers .closeTo ;
33+ import static org .assertj .core .api .Assertions .assertThat ;
34+ import static org .assertj .core .api .InstanceOfAssertFactories .DOUBLE ;
3435import static org .neo4j .gds .TestSupport .assertCypherMemoryEstimation ;
3536import static org .neo4j .gds .beta .pregel .pr .PageRankPregel .PAGE_RANK ;
3637
@@ -70,24 +71,24 @@ class PageRankPregelProcTest extends BaseProcTest {
7071
7172 private static final double RESULT_ERROR = 1e-3 ;
7273
73- private List < Map <String , Object > > expected ;
74+ private Map <Long , Double > expected ;
7475
7576 @ BeforeEach
7677 void setup () throws Exception {
7778 registerProcedures (GraphProjectProc .class , PageRankPregelStreamProc .class , PageRankPregelMutateProc .class );
7879
79- expected = List . of (
80- Map .of ( "nodeId" , idFunction .of ("a" ), "score" , closeTo ( 0.0276D , RESULT_ERROR ) ),
81- Map .of ( "nodeId" , idFunction .of ("b" ), "score" , closeTo ( 0.3483D , RESULT_ERROR ) ),
82- Map .of ( "nodeId" , idFunction .of ("c" ), "score" , closeTo ( 0.2650D , RESULT_ERROR ) ),
83- Map .of ( "nodeId" , idFunction .of ("d" ), "score" , closeTo ( 0.0330D , RESULT_ERROR ) ),
84- Map .of ( "nodeId" , idFunction .of ("e" ), "score" , closeTo ( 0.0682D , RESULT_ERROR ) ),
85- Map .of ( "nodeId" , idFunction .of ("f" ), "score" , closeTo ( 0.0330D , RESULT_ERROR ) ),
86- Map .of ( "nodeId" , idFunction .of ("g" ), "score" , closeTo ( 0.0136D , RESULT_ERROR ) ),
87- Map .of ( "nodeId" , idFunction .of ("h" ), "score" , closeTo ( 0.0136D , RESULT_ERROR ) ),
88- Map .of ( "nodeId" , idFunction .of ("i" ), "score" , closeTo ( 0.0136D , RESULT_ERROR ) ),
89- Map .of ( "nodeId" , idFunction .of ("j" ), "score" , closeTo ( 0.0136D , RESULT_ERROR ) ),
90- Map .of ( "nodeId" , idFunction .of ("k" ), "score" , closeTo ( 0.0136D , RESULT_ERROR ) )
80+ expected = Map . ofEntries (
81+ Map .entry ( idFunction .of ("a" ), 0.0276D ),
82+ Map .entry ( idFunction .of ("b" ), 0.3483D ),
83+ Map .entry ( idFunction .of ("c" ), 0.2650D ),
84+ Map .entry ( idFunction .of ("d" ), 0.0330D ),
85+ Map .entry ( idFunction .of ("e" ), 0.0682D ),
86+ Map .entry ( idFunction .of ("f" ), 0.0330D ),
87+ Map .entry ( idFunction .of ("g" ), 0.0136D ),
88+ Map .entry ( idFunction .of ("h" ), 0.0136D ),
89+ Map .entry ( idFunction .of ("i" ), 0.0136D ),
90+ Map .entry ( idFunction .of ("j" ), 0.0136D ),
91+ Map .entry ( idFunction .of ("k" ), 0.0136D )
9192 );
9293 }
9394
@@ -100,7 +101,17 @@ void stream() {
100101 .addParameter ("maxIterations" , 10 )
101102 .yields ("nodeId" , "values" );
102103
103- assertCypherResult (query + " RETURN nodeId, values.pagerank AS score" , expected );
104+ var rowCount = runQueryWithRowConsumer (
105+ query + " RETURN nodeId as nodeId, values.pagerank AS score" ,
106+ resultRow -> {
107+ var nodeId = resultRow .getNumber ("nodeId" ).longValue ();
108+ var expectedScore = expected .get (nodeId );
109+ assertThat (resultRow .getNumber ("score" ))
110+ .asInstanceOf (DOUBLE ).isCloseTo (expectedScore , Offset .offset (RESULT_ERROR ));
111+ }
112+ );
113+
114+ assertThat (rowCount ).isEqualTo (expected .size ());
104115 }
105116
106117 @ Test
@@ -143,6 +154,16 @@ void streamSeeded() {
143154 .addParameter ("seedProperty" , "value_" + PAGE_RANK )
144155 .yields ("nodeId" , "values" );
145156
146- assertCypherResult (query + " RETURN nodeId, values.pagerank AS score" , expected );
157+ var rowCount = runQueryWithRowConsumer (
158+ query + " RETURN nodeId, values.pagerank AS score" ,
159+ resultRow -> {
160+ var nodeId = resultRow .getNumber ("nodeId" ).longValue ();
161+ var expectedScore = expected .get (nodeId );
162+ assertThat (resultRow .getNumber ("score" ))
163+ .asInstanceOf (DOUBLE ).isCloseTo (expectedScore , Offset .offset (RESULT_ERROR ));
164+ }
165+ );
166+
167+ assertThat (rowCount ).isEqualTo (expected .size ());
147168 }
148169}
0 commit comments