1
1
package nu .ndw .nls .routingmapmatcher .singlepoint ;
2
2
3
3
import static nu .ndw .nls .routingmapmatcher .testutil .TestNetworkProvider .CAR ;
4
- import static org .hamcrest .MatcherAssert .assertThat ;
5
- import static org .hamcrest .Matchers .closeTo ;
6
- import static org .hamcrest .Matchers .containsInAnyOrder ;
7
- import static org .hamcrest .Matchers .hasSize ;
8
- import static org .hamcrest .Matchers .is ;
9
- import static org .hamcrest .Matchers .notNullValue ;
10
- import static org .hamcrest .Matchers .nullValue ;
11
- import static org .junit .jupiter .api .Assertions .assertEquals ;
4
+ import static org .assertj .core .api .Assertions .assertThat ;
5
+ import static org .assertj .core .api .Assertions .offset ;
12
6
13
7
import java .util .List ;
14
8
import java .util .Set ;
@@ -68,14 +62,14 @@ void testFraction(String externalId, double x, double y, double expectedFraction
68
62
.id (ID )
69
63
.point (point )
70
64
.build ());
71
- assertThat (singlePointMatch , is ( notNullValue ()) );
72
- assertEquals ( ID , singlePointMatch .getId ());
73
- assertThat (singlePointMatch .getStatus (), is (MatchStatus .MATCH ) );
65
+ assertThat (singlePointMatch ). isNotNull ( );
66
+ assertThat ( singlePointMatch .getId ()). isEqualTo ( ID );
67
+ assertThat (singlePointMatch .getStatus ()). isEqualTo (MatchStatus .MATCH );
74
68
List <CandidateMatch > candidateMatches = getNearestCandidateMatches (singlePointMatch .getCandidateMatches ());
75
- assertThat (candidateMatches , hasSize (1 ) );
69
+ assertThat (candidateMatches ). hasSize (1 );
76
70
assertThatUpstreamAndDownstreamAreNull (candidateMatches );
77
- assertThat (getSnappedPoints (candidateMatches ), hasSize (1 ) );
78
- assertThat (singlePointMatch .getCandidateMatches ().getFirst ().getFraction (), closeTo (expectedFraction , 0.01 ));
71
+ assertThat (getSnappedPoints (candidateMatches )). hasSize (1 );
72
+ assertThat (singlePointMatch .getCandidateMatches ().getFirst ().getFraction ()). isCloseTo (expectedFraction , offset ( 0.01 ));
79
73
}
80
74
81
75
@ SneakyThrows
@@ -89,14 +83,14 @@ void testOneWayMatch() {
89
83
.id (ID )
90
84
.point (point )
91
85
.build ());
92
- assertThat (singlePointMatch , is ( notNullValue ()) );
93
- assertEquals ( ID , singlePointMatch .getId ());
94
- assertThat (singlePointMatch .getStatus (), is (MatchStatus .MATCH ) );
86
+ assertThat (singlePointMatch ). isNotNull ( );
87
+ assertThat ( singlePointMatch .getId ()). isEqualTo ( ID );
88
+ assertThat (singlePointMatch .getStatus ()). isEqualTo (MatchStatus .MATCH );
95
89
List <CandidateMatch > candidateMatches = getNearestCandidateMatches (singlePointMatch .getCandidateMatches ());
96
- assertThat (candidateMatches , hasSize (1 ) );
90
+ assertThat (candidateMatches ). hasSize (1 );
97
91
assertThatUpstreamAndDownstreamAreNull (candidateMatches );
98
- assertThat (getSnappedPoints (candidateMatches ), hasSize (1 ) );
99
- assertThat (singlePointMatch .getReliability (), is (66.96798791959225 ) );
92
+ assertThat (getSnappedPoints (candidateMatches )). hasSize (1 );
93
+ assertThat (singlePointMatch .getReliability ()). isEqualTo (66.96798791959225 );
100
94
}
101
95
102
96
@ SneakyThrows
@@ -110,14 +104,14 @@ void testBidirectionalWayMatch() {
110
104
.id (ID )
111
105
.point (point )
112
106
.build ());
113
- assertThat (singlePointMatch , is ( notNullValue ()) );
114
- assertEquals ( ID , singlePointMatch .getId ());
115
- assertThat (singlePointMatch .getStatus (), is (MatchStatus .MATCH ) );
107
+ assertThat (singlePointMatch ). isNotNull ( );
108
+ assertThat ( singlePointMatch .getId ()). isEqualTo ( ID );
109
+ assertThat (singlePointMatch .getStatus ()). isEqualTo (MatchStatus .MATCH );
116
110
List <CandidateMatch > candidateMatches = getNearestCandidateMatches (singlePointMatch .getCandidateMatches ());
117
- assertThat (candidateMatches , hasSize (2 ) );
111
+ assertThat (candidateMatches ). hasSize (2 );
118
112
assertThatUpstreamAndDownstreamAreNull (candidateMatches );
119
- assertThat (getSnappedPoints (candidateMatches ), hasSize (1 ) );
120
- assertThat (singlePointMatch .getReliability (), is (84.53118547414594 ) );
113
+ assertThat (getSnappedPoints (candidateMatches )). hasSize (1 );
114
+ assertThat (singlePointMatch .getReliability ()). isEqualTo (84.53118547414594 );
121
115
}
122
116
123
117
@ SneakyThrows
@@ -132,14 +126,14 @@ void testBidirectionalWayMatchWithBearingFilter() {
132
126
.point (point )
133
127
.bearingFilter (new BearingFilter (85 , 30 ))
134
128
.build ());
135
- assertThat (singlePointMatch , is ( notNullValue ()) );
136
- assertEquals ( ID , singlePointMatch .getId ());
137
- assertThat (singlePointMatch .getStatus (), is (MatchStatus .MATCH ) );
129
+ assertThat (singlePointMatch ). isNotNull ( );
130
+ assertThat ( singlePointMatch .getId ()). isEqualTo ( ID );
131
+ assertThat (singlePointMatch .getStatus ()). isEqualTo (MatchStatus .MATCH );
138
132
List <CandidateMatch > candidateMatches = getNearestCandidateMatches (singlePointMatch .getCandidateMatches ());
139
- assertThat (candidateMatches , hasSize (1 ) );
133
+ assertThat (candidateMatches ). hasSize (1 );
140
134
assertThatUpstreamAndDownstreamAreNull (candidateMatches );
141
- assertThat (getSnappedPoints (candidateMatches ), hasSize (1 ) );
142
- assertThat (singlePointMatch .getReliability (), is (79.55725120440115 ) );
135
+ assertThat (getSnappedPoints (candidateMatches )). hasSize (1 );
136
+ assertThat (singlePointMatch .getReliability ()). isEqualTo (79.55725120440115 );
143
137
}
144
138
145
139
@ SneakyThrows
@@ -153,14 +147,14 @@ void testNodeMatch() {
153
147
.id (ID )
154
148
.point (point )
155
149
.build ());
156
- assertThat (singlePointMatch , is ( notNullValue ()) );
157
- assertEquals ( ID , singlePointMatch .getId ());
158
- assertThat (singlePointMatch .getStatus (), is (MatchStatus .MATCH ) );
150
+ assertThat (singlePointMatch ). isNotNull ( );
151
+ assertThat ( singlePointMatch .getId ()). isEqualTo ( ID );
152
+ assertThat (singlePointMatch .getStatus ()). isEqualTo (MatchStatus .MATCH );
159
153
List <CandidateMatch > candidateMatches = getNearestCandidateMatches (singlePointMatch .getCandidateMatches ());
160
- assertThat (candidateMatches , hasSize (8 ) );
154
+ assertThat (candidateMatches ). hasSize (8 );
161
155
assertThatUpstreamAndDownstreamAreNull (candidateMatches );
162
- assertThat (getSnappedPoints (candidateMatches ), hasSize (1 ) );
163
- assertThat (singlePointMatch .getReliability (), is (100.0 ) );
156
+ assertThat (getSnappedPoints (candidateMatches )). hasSize (1 );
157
+ assertThat (singlePointMatch .getReliability ()). isEqualTo (100.0 );
164
158
}
165
159
166
160
@ SneakyThrows
@@ -175,14 +169,14 @@ void testNodeMatchWithBearingFilter() {
175
169
.point (point )
176
170
.bearingFilter (new BearingFilter (15 , 30 ))
177
171
.build ());
178
- assertThat (singlePointMatch , is ( notNullValue ()) );
179
- assertEquals ( ID , singlePointMatch .getId ());
180
- assertThat (singlePointMatch .getStatus (), is (MatchStatus .MATCH ) );
172
+ assertThat (singlePointMatch ). isNotNull ( );
173
+ assertThat ( singlePointMatch .getId ()). isEqualTo ( ID );
174
+ assertThat (singlePointMatch .getStatus ()). isEqualTo (MatchStatus .MATCH );
181
175
List <CandidateMatch > candidateMatches = getNearestCandidateMatches (singlePointMatch .getCandidateMatches ());
182
- assertThat (candidateMatches , hasSize (2 ) );
176
+ assertThat (candidateMatches ). hasSize (2 );
183
177
assertThatUpstreamAndDownstreamAreNull (candidateMatches );
184
- assertThat (getSnappedPoints (candidateMatches ), hasSize (1 ) );
185
- assertThat (singlePointMatch .getReliability (), is (97.28721697585911 ) );
178
+ assertThat (getSnappedPoints (candidateMatches )). hasSize (1 );
179
+ assertThat (singlePointMatch .getReliability ()). isEqualTo (97.28721697585911 );
186
180
}
187
181
188
182
@ SneakyThrows
@@ -196,14 +190,14 @@ void testDoubleMatch() {
196
190
.id (ID )
197
191
.point (point )
198
192
.build ());
199
- assertThat (singlePointMatch , is ( notNullValue ()) );
200
- assertEquals ( ID , singlePointMatch .getId ());
201
- assertThat (singlePointMatch .getStatus (), is (MatchStatus .MATCH ) );
193
+ assertThat (singlePointMatch ). isNotNull ( );
194
+ assertThat ( singlePointMatch .getId ()). isEqualTo ( ID );
195
+ assertThat (singlePointMatch .getStatus ()). isEqualTo (MatchStatus .MATCH );
202
196
List <CandidateMatch > candidateMatches = getNearestCandidateMatches (singlePointMatch .getCandidateMatches ());
203
- assertThat (candidateMatches , hasSize (2 ) );
197
+ assertThat (candidateMatches ). hasSize (2 );
204
198
assertThatUpstreamAndDownstreamAreNull (candidateMatches );
205
- assertThat (getSnappedPoints (candidateMatches ), hasSize (2 ) );
206
- assertThat (singlePointMatch .getReliability (), is (95.53279394202733 ) );
199
+ assertThat (getSnappedPoints (candidateMatches )). hasSize (2 );
200
+ assertThat (singlePointMatch .getReliability ()). isEqualTo (95.53279394202733 );
207
201
}
208
202
209
203
@ SneakyThrows
@@ -216,11 +210,11 @@ void testNoMatch() {
216
210
.id (ID )
217
211
.point (point )
218
212
.build ());
219
- assertThat (singlePointMatch , is ( notNullValue ()) );
220
- assertEquals ( ID , singlePointMatch .getId ());
221
- assertThat (singlePointMatch .getStatus (), is (MatchStatus .NO_MATCH ) );
222
- assertThat (singlePointMatch .getCandidateMatches (), hasSize ( 0 ) );
223
- assertThat (singlePointMatch .getReliability (), is (0.0 ) );
213
+ assertThat (singlePointMatch ). isNotNull ( );
214
+ assertThat ( singlePointMatch .getId ()). isEqualTo ( ID );
215
+ assertThat (singlePointMatch .getStatus ()). isEqualTo (MatchStatus .NO_MATCH );
216
+ assertThat (singlePointMatch .getCandidateMatches ()). isEmpty ( );
217
+ assertThat (singlePointMatch .getReliability ()). isEqualTo (0.0 );
224
218
}
225
219
226
220
@ SneakyThrows
@@ -237,32 +231,26 @@ void testUpstreamDownstream() {
237
231
.downstreamIsochrone (30 )
238
232
.downstreamIsochroneUnit (IsochroneUnit .SECONDS )
239
233
.build ());
240
- assertThat (singlePointMatch , is ( notNullValue ()) );
241
- assertEquals ( ID , singlePointMatch .getId ());
242
- assertThat (singlePointMatch .getStatus (), is (MatchStatus .MATCH ) );
234
+ assertThat (singlePointMatch ). isNotNull ( );
235
+ assertThat ( singlePointMatch .getId ()). isEqualTo ( ID );
236
+ assertThat (singlePointMatch .getStatus ()). isEqualTo (MatchStatus .MATCH );
243
237
List <CandidateMatch > candidateMatches = getNearestCandidateMatches (singlePointMatch .getCandidateMatches ());
244
- assertThat (candidateMatches , hasSize (1 ) );
245
- assertThat (getSnappedPoints (candidateMatches ), hasSize (1 ) );
246
- assertThat (singlePointMatch .getReliability (), is (92.4716649970769 ) );
238
+ assertThat (candidateMatches ). hasSize (1 );
239
+ assertThat (getSnappedPoints (candidateMatches )). hasSize (1 );
240
+ assertThat (singlePointMatch .getReliability ()). isEqualTo (92.4716649970769 );
247
241
248
242
SinglePointMatch .CandidateMatch candidateMatch = singlePointMatch .getCandidateMatches ().getFirst ();
249
- assertThat (candidateMatch .getMatchedLinkId (), is (3666958 ) );
243
+ assertThat (candidateMatch .getMatchedLinkId ()). isEqualTo (3666958 );
250
244
251
245
// TODO upstream and downstream shouldn't contain matched segment itself?
252
- assertThat (
253
- candidateMatch .getUpstreamLinkIds (), containsInAnyOrder (3666958 ,
254
- 3666957 , 3666956 , 3666955 , 3667003 , 3667002 , 3667001 , 3667000 , 3666999 , 3666998 , 3666997 ,
255
- 3666996 ,
256
- 3666256 , 3666973 , 3666972 , 3666971 , 3666970 , 3666969 , 3666968 , 3666967 , 3666966 , 3666974 ,
257
- 3667137 ,
258
- 3667136 , 3667135 , 3667134 , 3666244 , 3666243 , 3666242 , 3666241 , 3666240 , 3666223 , 3667125 ,
259
- 3667124 ,
260
- 3667123 , 3667122 , 3667121 , 3667120 ));
261
- assertThat (candidateMatch .getDownstreamLinkIds (), containsInAnyOrder (3666958 ,
262
- 3666098 , 3666099 , 3666100 , 3666101 , 3666102 , 3666103 , 3666104 , 3666105 , 3666106 , 3666107 , 3666108 ,
263
- 3666109 , 3686216 , 3686217 , 3666945 , 3666946 , 3666947 , 3666948 , 3666949 , 3666950 , 3666951 , 3666952 ,
264
- 3666943 , 3666944 , 3666953 , 3666954 , 3666123 , 3666110 , 3666111 , 3666112 , 3666113 , 3666114 , 3666130 ,
265
- 3666115 , 3666116 , 3666117 , 3666118 , 3666119 , 3666120 ));
246
+ assertThat (candidateMatch .getUpstreamLinkIds ()).containsExactlyInAnyOrder (3666958 , 3666957 , 3666956 , 3666955 , 3667003 , 3667002 ,
247
+ 3667001 , 3667000 , 3666999 , 3666998 , 3666997 , 3666996 , 3666256 , 3666973 , 3666972 , 3666971 , 3666970 , 3666969 , 3666968 ,
248
+ 3666967 , 3666966 , 3666974 , 3667137 , 3667136 , 3667135 , 3667134 , 3666244 , 3666243 , 3666242 , 3666241 , 3666240 , 3666223 ,
249
+ 3667125 , 3667124 , 3667123 , 3667122 , 3667121 , 3667120 );
250
+ assertThat (candidateMatch .getDownstreamLinkIds ()).containsExactlyInAnyOrder (3666958 , 3666098 , 3666099 , 3666100 , 3666101 , 3666102 ,
251
+ 3666103 , 3666104 , 3666105 , 3666106 , 3666107 , 3666108 , 3666109 , 3686216 , 3686217 , 3666945 , 3666946 , 3666947 , 3666948 ,
252
+ 3666949 , 3666950 , 3666951 , 3666952 , 3666943 , 3666944 , 3666953 , 3666954 , 3666123 , 3666110 , 3666111 , 3666112 , 3666113 ,
253
+ 3666114 , 3666130 , 3666115 , 3666116 , 3666117 , 3666118 , 3666119 , 3666120 );
266
254
}
267
255
268
256
private List <CandidateMatch > getNearestCandidateMatches (List <CandidateMatch > candidateMatches ) {
@@ -272,8 +260,8 @@ private List<CandidateMatch> getNearestCandidateMatches(List<CandidateMatch> can
272
260
273
261
private void assertThatUpstreamAndDownstreamAreNull (List <CandidateMatch > candidateMatches ) {
274
262
for (SinglePointMatch .CandidateMatch candidateMatch : candidateMatches ) {
275
- assertThat (candidateMatch .getUpstream (), is ( nullValue ()) );
276
- assertThat (candidateMatch .getDownstream (), is ( nullValue ()) );
263
+ assertThat (candidateMatch .getUpstream ()). isNull ( );
264
+ assertThat (candidateMatch .getDownstream ()). isNull ( );
277
265
}
278
266
}
279
267
0 commit comments