-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConvexHullTest.java
More file actions
76 lines (64 loc) · 2.54 KB
/
ConvexHullTest.java
File metadata and controls
76 lines (64 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package algolib.geometry.dim2;
import java.util.List;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
// Tests: Algorithm for convex hull in 2D (Graham's scan).
public class ConvexHullTest
{
@Test
public void findConvexHull_WhenOnePoint_ThenEmpty()
{
// when
List<Point2D> result = ConvexHull.findConvexHull(List.of(Point2D.of(3.0, 2.0)));
// then
Assertions.assertThat(result).isEmpty();
}
@Test
public void findConvexHull_WhenTwoPoints_ThenEmpty()
{
// when
List<Point2D> result =
ConvexHull.findConvexHull(List.of(Point2D.of(2.0, 3.0), Point2D.of(3.0, 2.0)));
// then
Assertions.assertThat(result).isEmpty();
}
@Test
public void findConvexHull_WhenThreePoints_ThenThesePointsInHull()
{
// given
List<Point2D> points =
List.of(Point2D.of(1.0, -1.0), Point2D.of(5.0, 1.0), Point2D.of(3.0, 4.0));
// when
List<Point2D> result = ConvexHull.findConvexHull(points);
// then
Assertions.assertThat(result).isEqualTo(points);
}
@Test
public void findConvexHull_ThenPointsInHull()
{
// when
List<Point2D> result = ConvexHull.findConvexHull(
List.of(Point2D.of(1, -3), Point2D.of(-4, 6), Point2D.of(-5, -7),
Point2D.of(-8, -7), Point2D.of(-3, -4), Point2D.of(5, 9),
Point2D.of(-1, -8), Point2D.of(-5, 10), Point2D.of(8, 0), Point2D.of(3, -6),
Point2D.of(-2, 1), Point2D.of(-2, 8), Point2D.of(10, 2), Point2D.of(6, 3),
Point2D.of(-7, 7), Point2D.of(6, -4)));
// then
Assertions.assertThat(result)
.containsExactly(Point2D.of(-1, -8), Point2D.of(3, -6), Point2D.of(6, -4),
Point2D.of(10, 2), Point2D.of(5, 9), Point2D.of(-5, 10),
Point2D.of(-7, 7), Point2D.of(-8, -7));
}
@Test
public void findConvexHull_WhenMultiplePointsAreCollinear_ThenInnerPointsOmitted()
{
// when
List<Point2D> result = ConvexHull.findConvexHull(
List.of(Point2D.of(-1, -3), Point2D.of(-3, -3), Point2D.of(-3, -1),
Point2D.of(2, -3), Point2D.of(-3, 5), Point2D.of(0, -3), Point2D.of(7, -3),
Point2D.of(-3, -2)));
// then
Assertions.assertThat(result)
.containsExactly(Point2D.of(-3, -3), Point2D.of(7, -3), Point2D.of(-3, 5));
}
}