Skip to content

Commit da3a8c6

Browse files
Create LineIntersectionTest.java
1 parent b0ae74e commit da3a8c6

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.thealgorithms.geometry;
2+
3+
import org.junit.jupiter.api.Test;
4+
import static org.junit.jupiter.api.Assertions.*;
5+
6+
public class LineIntersectionTest {
7+
8+
@Test
9+
void testIntersectingSegments() {
10+
LineIntersection.Point p1 = new LineIntersection.Point(1, 1);
11+
LineIntersection.Point q1 = new LineIntersection.Point(4, 4);
12+
LineIntersection.Point p2 = new LineIntersection.Point(1, 4);
13+
LineIntersection.Point q2 = new LineIntersection.Point(4, 1);
14+
assertTrue(LineIntersection.doIntersect(p1, q1, p2, q2));
15+
}
16+
17+
@Test
18+
void testNonIntersectingSegments() {
19+
LineIntersection.Point p1 = new LineIntersection.Point(1, 1);
20+
LineIntersection.Point q1 = new LineIntersection.Point(2, 2);
21+
LineIntersection.Point p2 = new LineIntersection.Point(3, 3);
22+
LineIntersection.Point q2 = new LineIntersection.Point(4, 4);
23+
assertFalse(LineIntersection.doIntersect(p1, q1, p2, q2));
24+
}
25+
26+
@Test
27+
void testCollinearOverlappingSegments() {
28+
LineIntersection.Point p1 = new LineIntersection.Point(1, 1);
29+
LineIntersection.Point q1 = new LineIntersection.Point(5, 5);
30+
LineIntersection.Point p2 = new LineIntersection.Point(2, 2);
31+
LineIntersection.Point q2 = new LineIntersection.Point(6, 6);
32+
assertTrue(LineIntersection.doIntersect(p1, q1, p2, q2));
33+
}
34+
}

0 commit comments

Comments
 (0)