|
1 | 1 | package com.thealgorithms.geometry; |
2 | | - |
3 | | -import static org.junit.jupiter.api.Assertions.assertEquals; |
4 | | - |
| 2 | +import org.junit.jupiter.api.Test; |
5 | 3 | import java.util.Arrays; |
| 4 | +import java.util.HashSet; |
6 | 5 | import java.util.List; |
7 | | -import org.junit.jupiter.api.Test; |
| 6 | +import java.util.Set; |
| 7 | + |
| 8 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
8 | 9 |
|
9 | 10 | public class ConvexHullTest { |
10 | 11 |
|
11 | 12 | @Test |
12 | | - void testConvexHullRecursive() { |
13 | | - List<Point> points = Arrays.asList(new Point(0, 0), new Point(1, 0), new Point(10, 1)); |
14 | | - List<Point> expected = Arrays.asList(new Point(0, 0), new Point(1, 0), new Point(10, 1)); |
15 | | - assertEquals(expected, ConvexHull.convexHullRecursive(points)); |
16 | | - |
17 | | - points = Arrays.asList(new Point(0, 0), new Point(1, 0), new Point(10, 0)); |
18 | | - expected = Arrays.asList(new Point(0, 0), new Point(10, 0)); |
19 | | - assertEquals(expected, ConvexHull.convexHullRecursive(points)); |
20 | | - |
21 | | - points = Arrays.asList( |
22 | | - new Point(0, 3), |
23 | | - new Point(2, 2), |
24 | | - new Point(1, 1), |
25 | | - new Point(2, 1), |
26 | | - new Point(3, 0), |
27 | | - new Point(0, 0), |
28 | | - new Point(3, 3), |
29 | | - new Point(2, -1), |
30 | | - new Point(2, -4), |
31 | | - new Point(1, -3) |
| 13 | + public void testConvexHull() { |
| 14 | + List<Point> points = |
| 15 | + Arrays.asList(new Point(0, 3), new Point(2, 2), new Point(1, 1), new Point(2, 1), new Point(3, 0), |
| 16 | + new Point(0, 0), new Point(3, 3), new Point(2, -1), new Point(2, -4), new Point(1, -3)); |
| 17 | + |
| 18 | + Set<Point> expected = new HashSet<>( |
| 19 | + Arrays.asList(new Point(2, -4), new Point(1, -3), new Point(0, 0), new Point(3, 0), new Point(0, 3), |
| 20 | + new Point(3, 3)) |
32 | 21 | ); |
33 | 22 |
|
34 | | - // Updated expected hull to match the output of monotone chain |
35 | | - List<Point> expectedHull = Arrays.asList( |
36 | | - new Point(2, -4), |
37 | | - new Point(3, 0), |
38 | | - new Point(3, 3), |
39 | | - new Point(0, 3), |
40 | | - new Point(0, 0), |
41 | | - new Point(1, -3) |
42 | | - ); |
| 23 | + List<Point> hull = ConvexHull.convexHullRecursive(points); |
| 24 | + Set<Point> actual = new HashSet<>(hull); |
43 | 25 |
|
44 | | - assertEquals(expectedHull, ConvexHull.convexHullRecursive(points)); |
| 26 | + assertEquals(expected, actual); |
45 | 27 | } |
46 | 28 | } |
0 commit comments