19
19
*/
20
20
package org .neo4j .gds .beta .pregel .pr ;
21
21
22
+ import org .assertj .core .data .Offset ;
22
23
import org .junit .jupiter .api .BeforeEach ;
23
24
import org .junit .jupiter .api .Test ;
24
25
import org .neo4j .gds .BaseProcTest ;
27
28
import org .neo4j .gds .core .utils .mem .MemoryRange ;
28
29
import org .neo4j .gds .extension .Neo4jGraph ;
29
30
30
- import java .util .List ;
31
31
import java .util .Map ;
32
32
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 ;
34
35
import static org .neo4j .gds .TestSupport .assertCypherMemoryEstimation ;
35
36
import static org .neo4j .gds .beta .pregel .pr .PageRankPregel .PAGE_RANK ;
36
37
@@ -70,24 +71,24 @@ class PageRankPregelProcTest extends BaseProcTest {
70
71
71
72
private static final double RESULT_ERROR = 1e-3 ;
72
73
73
- private List < Map <String , Object > > expected ;
74
+ private Map <Long , Double > expected ;
74
75
75
76
@ BeforeEach
76
77
void setup () throws Exception {
77
78
registerProcedures (GraphProjectProc .class , PageRankPregelStreamProc .class , PageRankPregelMutateProc .class );
78
79
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 )
91
92
);
92
93
}
93
94
@@ -100,7 +101,17 @@ void stream() {
100
101
.addParameter ("maxIterations" , 10 )
101
102
.yields ("nodeId" , "values" );
102
103
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 ());
104
115
}
105
116
106
117
@ Test
@@ -143,6 +154,16 @@ void streamSeeded() {
143
154
.addParameter ("seedProperty" , "value_" + PAGE_RANK )
144
155
.yields ("nodeId" , "values" );
145
156
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 ());
147
168
}
148
169
}
0 commit comments