7
7
import java .util .*;
8
8
import java .util .function .Function ;
9
9
import java .util .stream .Collectors ;
10
+ import java .util .stream .IntStream ;
10
11
11
12
import static java .util .Collections .emptyList ;
12
13
import static org .assertj .core .api .Assertions .assertThat ;
13
14
import static org .bk .ass .query .Distances .EUCLIDEAN_DISTANCE ;
14
15
15
16
class PositionQueriesTest {
16
- private static Collection <Position > positions ;
17
+ private static List <Position > positions ;
17
18
18
19
@ BeforeAll
19
20
static void setup () {
@@ -26,18 +27,35 @@ static void setup() {
26
27
27
28
@ Test
28
29
void shouldFindNearest () {
30
+ for (int i = 3 ; i < positions .size (); i = i * 14 / 10 ) {
31
+ // GIVEN
32
+ List <Position > testList = PositionQueriesTest .positions .subList (0 , i );
33
+ PositionQueries <Position > tree = new PositionQueries <>(testList , Function .identity ());
34
+
35
+ // WHEN
36
+ Position nearest = tree .nearest (500 , 500 );
37
+
38
+ // THEN
39
+ Position actualNearest =
40
+ testList .stream ()
41
+ .min (Comparator .comparingInt (a -> EUCLIDEAN_DISTANCE .distance (a .x , a .y , 500 , 500 )))
42
+ .orElseThrow (RuntimeException ::new );
43
+ assertThat (nearest ).isEqualTo (actualNearest );
44
+ }
45
+ }
46
+
47
+ @ Test
48
+ void shouldPivotMatchingToOneSide () {
29
49
// GIVEN
50
+ List <Position > positions =
51
+ IntStream .range (0 , 30 ).mapToObj (it -> new Position (0 , it )).collect (Collectors .toList ());
30
52
PositionQueries <Position > tree = new PositionQueries <>(positions , Function .identity ());
31
53
32
54
// WHEN
33
- Position nearest = tree .nearest ( 500 , 500 );
55
+ Collection < Position > result = tree .inArea ( 0 , 0 , 0 , 150 );
34
56
35
57
// THEN
36
- Position actualNearest =
37
- positions .stream ()
38
- .min (Comparator .comparingInt (a -> EUCLIDEAN_DISTANCE .distance (a .x , a .y , 500 , 500 )))
39
- .orElseThrow (RuntimeException ::new );
40
- assertThat (nearest ).isEqualTo (actualNearest );
58
+ assertThat (result ).containsExactlyInAnyOrderElementsOf (positions );
41
59
}
42
60
43
61
@ Test
0 commit comments