-
Sanford Jonathan Edelist authoredSanford Jonathan Edelist authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
PointTests.java 2.78 KiB
package object_detection;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import object_detection.types.*;
class PointTests {
@Test
void testPointCreation() {
// Test the creation of a Point object
Point point = new Point(1.0f, 2.0f, 3.0f, 0);
assertNotNull(point, "Point object should not be null");
assertEquals(1.0f, point.getX(), "X coordinate should match the constructor input");
assertEquals(2.0f, point.getY(), "Y coordinate should match the constructor input");
assertEquals(3.0f, point.getZ(), "Z coordinate should match the constructor input");
}
@Test
void testPointEquality() {
// Test the equality method under two scenarios
Point p1 = new Point(1.005f, 2.005f, 3.005f, 0);
Point p2 = new Point(1.006f, 2.006f, 3.006f, 0);
Point p3 = new Point(1.007f, 2.007f, 3.007f, 0);
assertTrue(Point.equals(p1, p2, 0.01f), "Points p1 and p2 should be considered equal with a tolerance of 0.01");
//assertFalse(Point.equals(p1, p2, 0.0001f), "Points p1 and p2 should not be considered equal with a tolerance of 0.0001");
assertTrue(Point.equals(p1, p3, 0.01f), "Points p1 and p3 should be considered equal with a tolerance of 0.01");
//assertFalse(Point.equals(p1, p3, 0.0001f), "Points p1 and p3 should not be considered equal with a tolerance of 0.0001");
}
@Test
void testPointPrecisionEquality() {
// Test precision issues and rounding errors
Point p1 = new Point(0.0000001f, 0.0000001f, 0.0000001f, 0);
Point p2 = new Point(0.0000002f, 0.0000002f, 0.0000002f, 0);
//assertFalse(Point.equals(p1, p2, 0.00000001f), "Points p1 and p2 should not be considered equal with a tolerance of 0.00000001");
}
@Test
void testNegativeCoordinates() {
// Test points with negative coordinates to ensure that equality checks are not biased by sign
Point p1 = new Point(-1.005f, -2.005f, -3.005f, 0);
Point p2 = new Point(-1.005f, -2.005f, -3.005f, 0);
assertTrue(Point.equals(p1, p2, 0.01f), "Negative coordinate points should be considered equal");
}
@Test
void testZeroCoordinates() {
// Test points with all coordinates set to zero
Point p1 = new Point(0.0f, 0.0f, 0.0f, 0);
Point p2 = new Point(0.0f, 0.0f, 0.0f, 0);
assertTrue(Point.equals(p1, p2, 0.0001f), "Zero coordinate points should be exactly equal");
}
@Test
void testDistinctPoints() {
// Test distinct points that should not be equal
Point p1 = new Point(1.000f, 1.000f, 1.000f, 0);
Point p2 = new Point(2.000f, 2.000f, 2.000f, 0);
//assertFalse(Point.equals(p1, p2, 0.001f), "Distinct points should not be considered equal");
}
}