Skip to content

test: PointTest.java #HSFDPMUW #6391

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 20, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
test: added Tests for Point.java
  • Loading branch information
Aaron committed Jul 14, 2025
commit e2023a80c8067cb2c70ff1edd0cbb90f6ebb08d2
116 changes: 116 additions & 0 deletions src/test/java/com/thealgorithms/geometry/PointTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package com.thealgorithms.geometry;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

public class PointTest {

@Test
void testCompareTo() {
Point p1 = new Point (1, 2);
Point p2 = new Point(5, -1);
Point p3 = new Point(3, 9);
Point p4 = new Point(3, 9);
assertEquals(1,p1.compareTo(p2));
assertEquals(-1,p2.compareTo(p3));
assertEquals(0,p3.compareTo(p4));
}

@Test
void testToString() {
Point p1 = new Point (-3, 5);
assertEquals("(-3, 5)",p1.toString());
}


@Test
void testPolarOrder() {
Point p = new Point(0,0);
assertNotNull(p.polarOrder());
}

@Test
void testOrientation() {
// setup points
Point pA = new Point(0, 0);
Point pB = new Point(1, 0);
Point pC = new Point(1, 1);

// test for left curve
assertEquals(1, Point.orientation(pA, pB, pC));

//test for right curve
pB = new Point(0, 1);
assertEquals(-1, Point.orientation(pA, pB, pC));

//test for left curve
pC = new Point(-1, 1);
assertEquals(1, Point.orientation(pA, pB, pC));

//test for right curve
pB = new Point(1,0);
pC = new Point(1,-1);
assertEquals(-1, Point.orientation(pA, pB, pC));

//test for collinearity
pB = new Point(1, 1);
pC = new Point(2, 2);
assertEquals(0, Point.orientation(pA, pB, pC));
}

@Test
void testPolarOrderCompare() {
Point ref = new Point(0,0);

Point p1 = new Point(1,1);
Point p2 = new Point(1,-1);
assertTrue(ref.polarOrder().compare(p1, p2) < 0);

p1 = new Point(3,0);
p2 = new Point(2,0);
assertTrue(ref.polarOrder().compare(p1, p2) < 0);

p1 = new Point(0,1);
p2 = new Point(-1,1);
assertTrue(ref.polarOrder().compare(p1, p2) < 0);

p1 = new Point(1,1);
p2 = new Point(2,2);
assertEquals(0, ref.polarOrder().compare(p1, p2));

p1 = new Point(1,2);
p2 = new Point(2,1);
assertTrue(ref.polarOrder().compare(p1, p2) > 0);

p1 = new Point(2,1);
p2 = new Point(1,2);
assertTrue(ref.polarOrder().compare(p1, p2) < 0);

p1 = new Point(-1,0);
p2 = new Point(-2,0);
assertTrue(ref.polarOrder().compare(p1, p2) < 0);

p1 = new Point(2,3);
p2 = new Point(2,3);
assertEquals(0, ref.polarOrder().compare(p1, p2));

p1 = new Point(0,1);
p2 = new Point(0,-1);
assertTrue(ref.polarOrder().compare(p1, p2) < 0);

ref = new Point(1,1);

p1 = new Point(1,2);
p2 = new Point(2,2);
assertTrue(ref.polarOrder().compare(p1, p2) > 0);

p1 = new Point(2,1);
p2 = new Point(2,0);
assertTrue(ref.polarOrder().compare(p1, p2) < 0);

p1 = new Point(0,1);
p2 = new Point(1,0);
assertTrue(ref.polarOrder().compare(p1, p2) < 0);
}
}
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy