Commit bf2e89bd authored by Sanford Jonathan Edelist's avatar Sanford Jonathan Edelist
Browse files

updated tests

parent 320688e7
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -38,6 +38,25 @@ public class CameraIntrinsics {
        this.K = new DMatrixRMaj(ktemp);
    }

    /* ##########
        Getters
    ########## */
    public float[] getFocalLength() {
        return FocalLength;
    }

    public float[] getPrincipalPoint() {
        return PrincipalPoint;
    }

    public float[] getImageSize() {
        return ImageSize;
    }

    public DMatrixRMaj getK() {
        return K;
    }

    /* ###############
        Members
     ############### */
+10 −0
Original line number Diff line number Diff line
@@ -39,6 +39,16 @@ public class CameraPose {
        });
    }

    /* ##########
        Getters
    ########## */
    public DMatrixRMaj getR() {
        return R;
    }

    public DMatrixRMaj getTranslation() {
        return translation;
    }

    /* ##################
        Members
+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 BoundingBox2DTests {

    @Test
    void testPointOnEachEdge() {
        BoundingBox2D box = new BoundingBox2D(0, 0, 10, 10, "vehicle");

        // Points on the boundaries of the box
        Point2D topEdge = new Point2D(5, 10);
        Point2D bottomEdge = new Point2D(5, 0);
        Point2D leftEdge = new Point2D(0, 5);
        Point2D rightEdge = new Point2D(10, 5);

        assertTrue(box.within(topEdge), "Point on top edge should be within");
        assertTrue(box.within(bottomEdge), "Point on bottom edge should be within");
        assertTrue(box.within(leftEdge), "Point on left edge should be within");
        assertTrue(box.within(rightEdge), "Point on right edge should be within");
    }

    @Test
    void testPointsJustOutsideEachEdge() {
        BoundingBox2D box = new BoundingBox2D(0, 0, 10, 10, "animal");

        // Points just outside the boundaries of the box
        Point2D leftOfBox = new Point2D(-1, 5);
        Point2D rightOfBox = new Point2D(11, 5);
        Point2D belowBox = new Point2D(5, -1);
        Point2D aboveBox = new Point2D(5, 11);

        assertFalse(box.within(leftOfBox), "Point just left of the bounding box should not be within");
        assertFalse(box.within(rightOfBox), "Point just right of the bounding box should not be within");
        assertFalse(box.within(belowBox), "Point just below the bounding box should not be within");
        assertFalse(box.within(aboveBox), "Point just above the bounding box should not be within");
    }

    @Test
    void testZeroWidthHeightBoundingBox() {
        BoundingBox2D box = new BoundingBox2D(5, 5, 0, 0, "object");

        // Points to test
        Point2D exactPoint = new Point2D(5, 5);
        Point2D nearbyPoint1 = new Point2D(5, 4);
        Point2D nearbyPoint2 = new Point2D(6, 5);

        assertTrue(box.within(exactPoint), "Exact point should be within");
        assertFalse(box.within(nearbyPoint1), "Nearby point should not be within");
        assertFalse(box.within(nearbyPoint2), "Nearby point should not be within");
    }

    @Test
    void testLargeCoordinates() {
        BoundingBox2D box = new BoundingBox2D(0, 0, 10000, 10000, "space");

        // Points to test
        Point2D wellWithin = new Point2D(5000, 5000);
        Point2D justOutside = new Point2D(10001, 5000);

        assertTrue(box.within(wellWithin), "Point well within large bounding box should be within");
        assertFalse(box.within(justOutside), "Point just outside large bounding box should not be within");
    }
}
+46 −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 BoundingBox3DTests {

    private PointSet ps;
    private BoundingBox3D box;

    @BeforeEach
    void setUp() {
        // Create a PointSet with some sample points
        ps = new PointSet(
            1, 
            "object",
            new Point(1.0f, 2.0f, 3.0f),
            new Point(4.0f, 5.0f, 6.0f)
        );

        // Initialize a BoundingBox3D with this PointSet
        box = new BoundingBox3D(ps);
    }

    @Test
    void testBoundingBoxCreation() {
        assertNotNull(box, "BoundingBox3D should not be null after initialization");

        // Assuming BoundingBox3D internally manages the given PointSet
        assertEquals(ps, getPointSet(box), "BoundingBox3D should contain the same PointSet used during initialization");
    }

    // Helper function to access the PointSet within BoundingBox3D
    private PointSet getPointSet(BoundingBox3D box) {
        try {
            java.lang.reflect.Field field = box.getClass().getDeclaredField("ps");
            field.setAccessible(true);
            return (PointSet) field.get(box);
        } catch (Exception e) {
            fail("Failed to retrieve the PointSet from BoundingBox3D.");
            return null;
        }
    }
}
+0 −65
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 br = new Point2D(10000, 10000, 4);
        Point2D bl = new Point2D(0, 10000, 4);
        Point2D tr = new Point2D(10000, 0, 4);
        Point2D tl = 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");
    }
}
Loading