diff --git a/src/test/java/LICTests.java b/src/test/java/LICTests.java index fe85ca4..7efca15 100644 --- a/src/test/java/LICTests.java +++ b/src/test/java/LICTests.java @@ -205,8 +205,8 @@ void testLIC1() { } @Test - public void testLIC2() { - /* LIC2 returns true if and only if + public void testValidInputsLIC2() { + /* Contract: LIC2 returns true if and only if there exists at least one set of three consecutive data points which form an angle such that: angle < (PI−EPSILON) or @@ -218,11 +218,6 @@ point or the last point (or both) coincides with the vertex, the angle is undefi Parameters p = new Parameters(); p.EPSILON = 0.01; - Point[] points1 = new Point[] { - new Point(2, 2), - new Point(5, 5) - }; - Point[] points2 = new Point[] { new Point(1, 0), new Point(1, 0), @@ -243,11 +238,6 @@ point or the last point (or both) coincides with the vertex, the angle is undefi new Point(-3, -1) }; - //Tests that false is returned when NUMPOINTS < 3 - assertThrows(IllegalArgumentException.class, () -> { - LIC.LIC2(points1.length, points1, p); - }); - //Tests that false is returned if any point coincides with the vertex assertFalse(LIC.LIC2(points2.length, points2, p)); @@ -255,23 +245,48 @@ point or the last point (or both) coincides with the vertex, the angle is undefi p.EPSILON = (PI / 2) - 0.01; assertTrue(LIC.LIC2(points3.length, points3, p)); - //Tests that false is returned when EPSILON < 0 + //Tests that false is returned when there does not exist at least one set of three + //consecutive data points which form an angle such that: angle < (PI−EPSILON) + //or angle > (PI+EPSILON) + p.EPSILON = PI / 2 + 0.01; + assertFalse(LIC.LIC2(points4.length, points3, p)); + } + +@Test + public void testInvalidInputsLIC2() { + /*Contract: LIC2 should throw IllegalArgumentException if + 0 > EPSILON, or EPSILON > PI, or number of points < 3, + because it constitutes an invalid input*/ + Parameters p = new Parameters(); + p.EPSILON = 0.01; + + Point[] points1 = new Point[] { + new Point(2, 2), + new Point(5, 5) + }; + + Point[] points4 = new Point[] { + new Point(-2, -2), + new Point(-2, -1), + new Point(-3, -1) + }; + + // Tests that IllegalArgumentException is thrown when NUMPOINTS < 3 + assertThrows(IllegalArgumentException.class, () -> { + LIC.LIC2(points1.length, points1, p); + }); + + // Tests that IllegalArgumentException is thrown when EPSILON < 0 p.EPSILON = -0.01; assertThrows(IllegalArgumentException.class, () -> { LIC.LIC2(points4.length, points4, p); }); - //Tests that false is returned when EPISILON > PI + // Tests that IllegalArgumentException is thrown when EPISILON > PI p.EPSILON = PI + 0.01; assertThrows(IllegalArgumentException.class, () -> { LIC.LIC2(points4.length, points4, p); }); - - //Tests that false is returned when there does not exist at least one set of three - //consecutive data points which form an angle such that: angle < (PI−EPSILON) - //or angle > (PI+EPSILON) - p.EPSILON = PI / 2 + 0.01; - assertFalse(LIC.LIC2(points4.length, points3, p)); } // LIC3 Unit Tests @@ -689,7 +704,7 @@ public void testLIC7() { } @Test - public void testLIC8() { + public void testValidInputsLIC8() { /* * Contract: LIC8 returns true if and only if there exists at least one set of * three data points @@ -711,26 +726,6 @@ public void testLIC8() { Parameters p = new Parameters(); p.RADIUS1 = 1; - p.A_PTS = 0; - p.B_PTS = 1; - - // Tests that IllegalArgumentException is thrown when A PTS < 1 - assertThrows(IllegalArgumentException.class, () -> { - LIC.LIC8(points2.length, points2, p); - }); - // Tests that IllegalArgumentException is thrown when B PTS < 1 - p.A_PTS = 1; - p.B_PTS = 0; - assertThrows(IllegalArgumentException.class, () -> { - LIC.LIC8(points2.length, points2, p); - }); - - // Tests that IllegalArgumentException is thrown when A PTS + B PTS > (NUMPOINTS-3) - p.A_PTS = 2; - p.B_PTS = 1; - assertThrows(IllegalArgumentException.class, () -> { - LIC.LIC8(points2.length, points2, p); - }); // Tests that false is returned when there exists a set of three data points // separated by exactly A PTS and B PTS @@ -739,6 +734,7 @@ public void testLIC8() { // radius RADIUS1 p.RADIUS1 = 100; p.A_PTS = 1; + p.B_PTS = 1; assertFalse(LIC.LIC8(points2.length, points2, p)); Point[] points3 = new Point[] { @@ -758,15 +754,55 @@ public void testLIC8() { p.RADIUS1 = 1; assertFalse(LIC.LIC8(points3.length, points3, p)); + p.RADIUS1 = 1; + // Tests that true is returned for a valid input + assertTrue(LIC.LIC8(points2.length, points2, p)); + } + + @Test + public void testInvalidInputsLIC8() { + /* Contract: LIC8 should throw IllegalArgumentException if + A_PTS < 1, or B_PTS < 1, or A_PTS+B_PTS > numPoints-3, or 0>RADIUS1, + because it constitutes an invalid input*/ + + Point[] points2 = new Point[] { + new Point(0, 10), + new Point(0, 0), + new Point(-10, 0), + new Point(0, -1), + new Point(10, 0) + }; + + Parameters p = new Parameters(); + p.RADIUS1 = 1; + p.A_PTS = 0; + p.B_PTS = 1; + + // Tests that IllegalArgumentException is thrown when A PTS < 1 + assertThrows(IllegalArgumentException.class, () -> { + LIC.LIC8(points2.length, points2, p); + }); + // Tests that IllegalArgumentException is thrown when B PTS < 1 + p.A_PTS = 1; + p.B_PTS = 0; + assertThrows(IllegalArgumentException.class, () -> { + LIC.LIC8(points2.length, points2, p); + }); + + // Tests that IllegalArgumentException is thrown when A PTS + B PTS > (NUMPOINTS-3) + p.A_PTS = 2; + p.B_PTS = 1; + assertThrows(IllegalArgumentException.class, () -> { + LIC.LIC8(points2.length, points2, p); + }); + // Tests that IllegalArgumentException is thrown when RADIUS1 < 0: p.RADIUS1 = -1; + p.A_PTS = 1; assertThrows(IllegalArgumentException.class, () -> { LIC.LIC8(points2.length, points2, p); }); - p.RADIUS1 = 1; - // Tests that true is returned for a valid input - assertTrue(LIC.LIC8(points2.length, points2, p)); } // LIC9 Unit Tests @@ -1044,7 +1080,7 @@ public void LIC10_true() { } @Test - public void testLIC11() { + public void testValidInputsLIC11() { /* Contract: LIC11 returns true if and only if there exists at least one set of two data points, (X[i],Y[i]) and (X[j],Y[j]), separated by exactly G PTS consecutive intervening points, such that X[j] - X[i] < 0. (where i < j ) The @@ -1071,18 +1107,6 @@ public void testLIC11() { }; Parameters p = new Parameters(); - p.G_PTS = 0; - // Tests that IllegalArgumentException is thrown when G_PTS < 1 - assertThrows(IllegalArgumentException.class, () -> { - LIC.LIC11(points1.length, points1, p); - }); - - p.G_PTS = 2; - // Tests that IllegalArgumentException is thrown when NUMPOINTS-2 < G_PTS - assertThrows(IllegalArgumentException.class, () -> { - LIC.LIC11(points1.length, points1, p); - }); - //Tests that false is returned when there does not exist at least one set of two data points, //(X[i],Y[i]) and (X[j],Y[j]), separated by //exactly G PTS consecutive intervening points, such that X[j] - X[i] < 0. (where i < j ) @@ -1100,6 +1124,33 @@ public void testLIC11() { } + @Test + public void testInvalidInputsLIC11() { + /* Contract: LIC11 should throw IllegalArgumentException if + 1 > G_PTS, or G_PTS > numPoints-2, because it constitutes + an invalid input */ + + Point[] points1 = new Point[] { + new Point(1, -1), + new Point(0, 0), + new Point(-1, 1) + }; + + Parameters p = new Parameters(); + + p.G_PTS = 0; + // Tests that IllegalArgumentException is thrown when G_PTS < 1 + assertThrows(IllegalArgumentException.class, () -> { + LIC.LIC11(points1.length, points1, p); + }); + + p.G_PTS = 2; + // Tests that IllegalArgumentException is thrown when NUMPOINTS-2 < G_PTS + assertThrows(IllegalArgumentException.class, () -> { + LIC.LIC11(points1.length, points1, p); + }); + } + // LIC12 Unit Tests