44import org .assertj .core .api .Assertions ;
55import org .junit .jupiter .api .Test ;
66
7- // Tests: Algorithm for convex hull in 2D (Graham's scan) .
7+ // Tests: Algorithms for convex hull in 2D.
88public class ConvexHullTest
99{
10+ // region findAndrewConvexHull
11+
12+ @ Test
13+ public void findAndrewConvexHull_WhenOnePoint_ThenEmpty ()
14+ {
15+ // when
16+ List <Point2D > result = ConvexHull .findAndrewConvexHull (List .of (Point2D .of (3.0 , 2.0 )));
17+
18+ // then
19+ Assertions .assertThat (result ).isEmpty ();
20+ }
21+
22+ @ Test
23+ public void findAndrewConvexHull_WhenTwoPoints_ThenEmpty ()
24+ {
25+ // when
26+ List <Point2D > result = ConvexHull .findAndrewConvexHull (
27+ List .of (Point2D .of (2.0 , 3.0 ), Point2D .of (3.0 , 2.0 )));
28+
29+ // then
30+ Assertions .assertThat (result ).isEmpty ();
31+ }
32+
33+ @ Test
34+ public void findAndrewConvexHull_WhenThreePoints_ThenThesePointsInHull ()
35+ {
36+ // given
37+ List <Point2D > points =
38+ List .of (Point2D .of (1.0 , -1.0 ), Point2D .of (5.0 , 1.0 ), Point2D .of (3.0 , 4.0 ));
39+
40+ // when
41+ List <Point2D > result = ConvexHull .findAndrewConvexHull (points );
42+
43+ // then
44+ Assertions .assertThat (result ).isEqualTo (points );
45+ }
46+
47+ @ Test
48+ public void findAndrewConvexHull_ThenPointsInHull ()
49+ {
50+ // when
51+ List <Point2D > result = ConvexHull .findAndrewConvexHull (
52+ List .of (Point2D .of (1 , -3 ), Point2D .of (-4 , 6 ), Point2D .of (-5 , -7 ),
53+ Point2D .of (-8 , -7 ), Point2D .of (-3 , -4 ), Point2D .of (5 , 9 ),
54+ Point2D .of (-1 , -8 ), Point2D .of (-5 , 10 ), Point2D .of (8 , 0 ), Point2D .of (3 , -6 ),
55+ Point2D .of (-2 , 1 ), Point2D .of (-2 , 8 ), Point2D .of (10 , 2 ), Point2D .of (6 , 3 ),
56+ Point2D .of (-7 , 7 ), Point2D .of (6 , -4 )));
57+
58+ // then
59+ Assertions .assertThat (result )
60+ .containsExactly (Point2D .of (-8 , -7 ), Point2D .of (-1 , -8 ), Point2D .of (3 , -6 ),
61+ Point2D .of (6 , -4 ), Point2D .of (10 , 2 ), Point2D .of (5 , 9 ),
62+ Point2D .of (-5 , 10 ), Point2D .of (-7 , 7 ));
63+ }
64+
1065 @ Test
11- public void findConvexHull_WhenOnePoint_ThenEmpty ()
66+ public void findAndrewConvexHull_WhenMultiplePointsAreCollinear_ThenInnerPointsOmitted ()
1267 {
1368 // when
14- List <Point2D > result = ConvexHull .findConvexHull (List .of (Point2D .of (3.0 , 2.0 )));
69+ List <Point2D > result = ConvexHull .findAndrewConvexHull (
70+ List .of (Point2D .of (-1 , -3 ), Point2D .of (-3 , -3 ), Point2D .of (-3 , -1 ),
71+ Point2D .of (2 , -3 ), Point2D .of (-3 , 5 ), Point2D .of (0 , -3 ), Point2D .of (7 , -3 ),
72+ Point2D .of (-3 , -2 )));
73+
74+ // then
75+ Assertions .assertThat (result )
76+ .containsExactly (Point2D .of (-3 , -3 ), Point2D .of (7 , -3 ), Point2D .of (-3 , 5 ));
77+ }
78+
79+ // endregion
80+ // region findGrahamConvexHull
81+
82+ @ Test
83+ public void findGrahamConvexHull_WhenOnePoint_ThenEmpty ()
84+ {
85+ // when
86+ List <Point2D > result = ConvexHull .findGrahamConvexHull (List .of (Point2D .of (3.0 , 2.0 )));
1587
1688 // then
1789 Assertions .assertThat (result ).isEmpty ();
1890 }
1991
2092 @ Test
21- public void findConvexHull_WhenTwoPoints_ThenEmpty ()
93+ public void findGrahamConvexHull_WhenTwoPoints_ThenEmpty ()
2294 {
2395 // when
24- List <Point2D > result =
25- ConvexHull . findConvexHull ( List .of (Point2D .of (2.0 , 3.0 ), Point2D .of (3.0 , 2.0 )));
96+ List <Point2D > result = ConvexHull . findGrahamConvexHull (
97+ List .of (Point2D .of (2.0 , 3.0 ), Point2D .of (3.0 , 2.0 )));
2698
2799 // then
28100 Assertions .assertThat (result ).isEmpty ();
29101 }
30102
31103 @ Test
32- public void findConvexHull_WhenThreePoints_ThenThesePointsInHull ()
104+ public void findGrahamConvexHull_WhenThreePoints_ThenThesePointsInHull ()
33105 {
34106 // given
35107 List <Point2D > points =
36108 List .of (Point2D .of (1.0 , -1.0 ), Point2D .of (5.0 , 1.0 ), Point2D .of (3.0 , 4.0 ));
37109
38110 // when
39- List <Point2D > result = ConvexHull .findConvexHull (points );
111+ List <Point2D > result = ConvexHull .findGrahamConvexHull (points );
40112
41113 // then
42114 Assertions .assertThat (result ).isEqualTo (points );
43115 }
44116
45117 @ Test
46- public void findConvexHull_ThenPointsInHull ()
118+ public void findGrahamConvexHull_ThenPointsInHull ()
47119 {
48120 // when
49- List <Point2D > result = ConvexHull .findConvexHull (
121+ List <Point2D > result = ConvexHull .findGrahamConvexHull (
50122 List .of (Point2D .of (1 , -3 ), Point2D .of (-4 , 6 ), Point2D .of (-5 , -7 ),
51123 Point2D .of (-8 , -7 ), Point2D .of (-3 , -4 ), Point2D .of (5 , 9 ),
52124 Point2D .of (-1 , -8 ), Point2D .of (-5 , 10 ), Point2D .of (8 , 0 ), Point2D .of (3 , -6 ),
@@ -61,10 +133,10 @@ public void findConvexHull_ThenPointsInHull()
61133 }
62134
63135 @ Test
64- public void findConvexHull_WhenMultiplePointsAreCollinear_ThenInnerPointsOmitted ()
136+ public void findGrahamConvexHull_WhenMultiplePointsAreCollinear_ThenInnerPointsOmitted ()
65137 {
66138 // when
67- List <Point2D > result = ConvexHull .findConvexHull (
139+ List <Point2D > result = ConvexHull .findGrahamConvexHull (
68140 List .of (Point2D .of (-1 , -3 ), Point2D .of (-3 , -3 ), Point2D .of (-3 , -1 ),
69141 Point2D .of (2 , -3 ), Point2D .of (-3 , 5 ), Point2D .of (0 , -3 ), Point2D .of (7 , -3 ),
70142 Point2D .of (-3 , -2 )));
@@ -73,4 +145,6 @@ public void findConvexHull_WhenMultiplePointsAreCollinear_ThenInnerPointsOmitted
73145 Assertions .assertThat (result )
74146 .containsExactly (Point2D .of (-3 , -3 ), Point2D .of (7 , -3 ), Point2D .of (-3 , 5 ));
75147 }
148+
149+ // endregion
76150}
0 commit comments