Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
justakayy wants to merge4 commits intoTheAlgorithms:master
base:master
Choose a base branch
Loading
fromjustakayy:test/pointtest
Open
Changes fromall commits
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
117 changes: 117 additions & 0 deletionssrc/test/java/com/thealgorithms/geometry/PointTest.java
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
package com.thealgorithms.geometry;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;

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 p = new Point(-3, 5);
assertEquals("(-3, 5)", p.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 pA = new Point(1, 1);
Point pB = new Point(1, -1);
assertTrue(ref.polarOrder().compare(pA, pB) < 0);

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

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

pA = new Point(1, 1);
pB = new Point(2, 2);
assertEquals(0, ref.polarOrder().compare(pA, pB));

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

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

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

pA = new Point(2, 3);
pB = new Point(2, 3);
assertEquals(0, ref.polarOrder().compare(pA, pB));

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

ref = new Point(1, 1);

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

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

pA = new Point(0, 1);
pB = new Point(1, 0);
assertTrue(ref.polarOrder().compare(pA, pB) < 0);
}
}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp