|
| 1 | +package renderer; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.*; |
| 4 | + |
| 5 | +import org.junit.jupiter.api.Test; |
| 6 | + |
| 7 | +import primitives.*; |
| 8 | + |
| 9 | +/** |
| 10 | + * Testing Camera Class |
| 11 | + * |
| 12 | + * @author Dan, Benjamin Mamistvalov, Eyal Nathan |
| 13 | + * |
| 14 | + */ |
| 15 | +class CameraTest { |
| 16 | + static final Point ZERO_POINT = new Point(0, 0, 0); |
| 17 | + |
| 18 | + /** |
| 19 | + * Test method for |
| 20 | + * {@link renderer.Camera(primitives.Point, primitives.Vector, primitives.Vector)} |
| 21 | + */ |
| 22 | + @Test |
| 23 | + void testConstructor() { |
| 24 | + Vector v = new Vector(1, 0, 0); |
| 25 | + |
| 26 | + // =============== Boundary Values Tests ================== |
| 27 | + // BVA01: vTo and vUp are not orthogonal |
| 28 | + assertThrows( |
| 29 | + IllegalArgumentException.class, |
| 30 | + () -> new Camera(ZERO_POINT, v, new Vector(1, 1, 0)), |
| 31 | + "BVA01: ctor() does not throw an exception when vTo and vUp are not orthogonal" |
| 32 | + ); |
| 33 | + |
| 34 | + // BVA02: vTo and vUp are the same vector |
| 35 | + assertThrows( |
| 36 | + IllegalArgumentException.class, |
| 37 | + () -> new Camera(ZERO_POINT, v, v), |
| 38 | + "BVA02: ctor() does not throw an exception when vTo and vUp are the same vector" |
| 39 | + ); |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * Test method for |
| 44 | + * {@link renderer.Camera#constructRay(int, int, int, int)}. |
| 45 | + */ |
| 46 | + @Test |
| 47 | + void testConstructRay() { |
| 48 | + Camera camera = new Camera( |
| 49 | + ZERO_POINT, new Vector(0, 0, -1), |
| 50 | + new Vector(0, -1, 0) |
| 51 | + ).setVPDistance(10); |
| 52 | + String badRay = "Bad ray"; |
| 53 | + |
| 54 | + // ============ Equivalence Partitions Tests ============== |
| 55 | + // EP01: 4X4 Inside (1,1) |
| 56 | + assertEquals(new Ray(ZERO_POINT, new Vector(1, -1, -10)), |
| 57 | + camera.setVPSize(8, 8).constructRay(4, 4, 1, 1), badRay); |
| 58 | + |
| 59 | + // =============== Boundary Values Tests ================== |
| 60 | + // BVA01: 3X3 Center (1,1) |
| 61 | + assertEquals(new Ray(ZERO_POINT, new Vector(0, 0, -10)), |
| 62 | + camera.setVPSize(6, 6).constructRay(3, 3, 1, 1), badRay); |
| 63 | + |
| 64 | + // BVA02: 3X3 Center of Upper Side (0,1) |
| 65 | + assertEquals(new Ray(ZERO_POINT, new Vector(0, -2, -10)), |
| 66 | + camera.setVPSize(6, 6).constructRay(3, 3, 1, 0), badRay); |
| 67 | + |
| 68 | + // BVA03: 3X3 Center of Left Side (1,0) |
| 69 | + assertEquals(new Ray(ZERO_POINT, new Vector(2, 0, -10)), |
| 70 | + camera.setVPSize(6, 6).constructRay(3, 3, 0, 1), badRay); |
| 71 | + |
| 72 | + // BVA04: 3X3 Corner (0,0) |
| 73 | + assertEquals(new Ray(ZERO_POINT, new Vector(2, -2, -10)), |
| 74 | + camera.setVPSize(6, 6).constructRay(3, 3, 0, 0), badRay); |
| 75 | + |
| 76 | + // BVA05: 4X4 Corner (0,0) |
| 77 | + assertEquals(new Ray(ZERO_POINT, new Vector(3, -3, -10)), |
| 78 | + camera.setVPSize(8, 8).constructRay(4, 4, 0, 0), badRay); |
| 79 | + |
| 80 | + // BVA06: 4X4 Side (0,1) |
| 81 | + assertEquals(new Ray(ZERO_POINT, new Vector(1, -3, -10)), |
| 82 | + camera.setVPSize(8, 8).constructRay(4, 4, 1, 0), badRay); |
| 83 | + |
| 84 | + } |
| 85 | + |
| 86 | +} |
0 commit comments