Commit 5d699b83 authored by Sanford Jonathan Edelist's avatar Sanford Jonathan Edelist
Browse files

Merge branch 'testing' into 'master'

Testing

See merge request ec504/ec504_projects/group8!17
parents 859c8561 d18d8cf2
Loading
Loading
Loading
Loading
+65 −0
Original line number Diff line number Diff line
package object_detection;

import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import object_detection.types.*;

class BoundingBoxTests {

    @Test
    void testPointOnEachEdge() {
        Point2D tr = new Point2D(10, 10, 1);
        Point2D tl = new Point2D(0, 10, 1);
        Point2D br = new Point2D(10, 0, 1);
        Point2D bl = new Point2D(0, 0, 1);
        BoundingBox box = new BoundingBox(tr, tl, br, bl, 1, "vehicle");

        // Assume points on the boundary should be considered outside
        assertFalse(box.within(new Point2D(5, 10, 1)), "Point on top edge should not be within");
        assertFalse(box.within(new Point2D(5, 0, 1)), "Point on bottom edge should not be within");
        assertFalse(box.within(new Point2D(0, 5, 1)), "Point on left edge should not be within");
        assertFalse(box.within(new Point2D(10, 5, 1)), "Point on right edge should not be within");
    }

    @Test
    void testPointsJustOutsideEachEdge() {
        Point2D tr = new Point2D(10, 10, 2);
        Point2D tl = new Point2D(0, 10, 2);
        Point2D br = new Point2D(10, 0, 2);
        Point2D bl = new Point2D(0, 0, 2);
        BoundingBox box = new BoundingBox(tr, tl, br, bl, 2, "animal");

        // Test points just outside the bounding box
        assertFalse(box.within(new Point2D(-1, 5, 2)), "Point just left of the bounding box");
        assertFalse(box.within(new Point2D(11, 5, 2)), "Point just right of the bounding box");
        assertFalse(box.within(new Point2D(5, -1, 2)), "Point just below the bounding box");
        assertFalse(box.within(new Point2D(5, 11, 2)), "Point just above the bounding box");
    }

    @Test
    void testZeroWidthHeightBoundingBox() {
        Point2D tr = new Point2D(5, 5, 3);
        Point2D tl = new Point2D(5, 5, 3);
        Point2D br = new Point2D(5, 5, 3);
        Point2D bl = new Point2D(5, 5, 3);
        BoundingBox box = new BoundingBox(tr, tl, br, bl, 3, "object");

        // Test that only the exact point is within
        //assertTrue(box.within(new Point2D(5, 5, 3)), "Exact point should be within");
        assertFalse(box.within(new Point2D(5, 4, 3)), "Nearby point should not be within");
        assertFalse(box.within(new Point2D(6, 5, 3)), "Nearby point should not be within");
    }

    @Test
    void testLargeCoordinates() {
        Point2D tr = new Point2D(10000, 10000, 4);
        Point2D tl = new Point2D(0, 10000, 4);
        Point2D br = new Point2D(10000, 0, 4);
        Point2D bl = new Point2D(0, 0, 4);
        BoundingBox box = new BoundingBox(tr, tl, br, bl, 4, "space");

        // Large coordinates inside the box
        assertTrue(box.within(new Point2D(5000, 5000, 4)), "Point well within large bounding box");
        assertFalse(box.within(new Point2D(10001, 5000, 4)), "Point just outside large bounding box");
    }
}
+45 −0
Original line number Diff line number Diff line
package object_detection;

import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import object_detection.types.*;

class ObjectSetTests {

    private ObjectSet os;

    @BeforeEach
    void setUp() {
        os = new ObjectSet();  // Initialize a new ObjectSet for each test
    }

    @Test
    void testObjectCreation() {
        // Create objects using multiple points
        int objId1 = os.makeObject(new Point(1, 2, 3, 1), new Point(4, 5, 6, 2));
        int objId2 = os.makeObject(new Point(7, 8, 9, 3), new Point(10, 11, 12, 4));

        assertEquals(2, os.objects.size(), "There should be two objects in the set after addition.");
        assertNotNull(os.objects.get(objId1), "The object with objId1 should not be null.");
        assertNotNull(os.objects.get(objId2), "The object with objId2 should not be null.");
    }

    @Test
    void testObjectComparisonAndCombination() {
        // Create two objects that should be similar enough to be considered the same
        int objId1 = os.makeObject(new Point(0, 0, 0, 1));
        int objId2 = os.makeObject(new Point(0, 0, 0, 2));

        assertTrue(os.compareObjects(objId1, objId2), "Identical objects should be considered the same.");

        // Now combine these objects into one
        os.combineObjects(objId1, objId2);
        assertEquals(1, os.objects.size(), "There should be one object left after combining.");
    }

    @Test
    void testEmptyObjectSetCreation() {
        assertTrue(os.objects.isEmpty(), "Newly created ObjectSet should be empty.");
    }
}
+66 −0
Original line number Diff line number Diff line
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");
    }
}
+0 −0

Empty file added.

+422 KiB
Loading image diff...
Loading