|
| 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