Skip to content

Commit fa2fedb

Browse files
authored
Add regression tests for convexHullRecursive interior-point bug
1 parent ee6c854 commit fa2fedb

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

‎src/test/java/com/thealgorithms/geometry/ConvexHullTest.java‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,23 @@ void testRecursiveHullForCoverage() {
135135
assertEquals(expectedCollinear, resultCollinear, "Should correctly handle collinear points on the hull edge");
136136
assertTrue(isCounterClockwise(resultCollinear), "The result of the collinear test should be in counter-clockwise order");
137137
}
138+
@Test
139+
void testConvexHullRecursiveExcludesInteriorPoints() {
140+
// (1,8) is strictly inside the hull of the other four points.
141+
List<Point> points = new ArrayList<>(List.of(new Point(1, 5), new Point(1, 8), new Point(2, 9), new Point(0, 10), new Point(4, 19)));
142+
List<Point> expected = List.of(new Point(1, 5), new Point(2, 9), new Point(4, 19), new Point(0, 10));
143+
assertEquals(expected, ConvexHull.convexHullRecursive(points));
144+
145+
// (7,2) and (8,3) are strictly inside the triangle (4,0), (11,3), (3,10).
146+
List<Point> points2 = new ArrayList<>(List.of(new Point(4, 0), new Point(7, 2), new Point(8, 3), new Point(11, 3), new Point(3, 10)));
147+
List<Point> expected2 = List.of(new Point(4, 0), new Point(11, 3), new Point(3, 10));
148+
assertEquals(expected2, ConvexHull.convexHullRecursive(points2));
149+
}
150+
151+
@Test
152+
void testConvexHullRecursiveDuplicatePoints() {
153+
List<Point> points = new ArrayList<>(List.of(new Point(5, 5), new Point(5, 5)));
154+
List<Point> expected = List.of(new Point(5, 5));
155+
assertEquals(expected, ConvexHull.convexHullRecursive(points));
156+
}
138157
}

0 commit comments

Comments
 (0)