Skip to content

Commit 03e246e

Browse files
author
Alexander Mannertorn
committed
test: move tests for invalid inputs to
new unit test funcs for LIC 2, 8, and 11 closes #177
1 parent 843c97d commit 03e246e

1 file changed

Lines changed: 108 additions & 57 deletions

File tree

src/test/java/LICTests.java

Lines changed: 108 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ void testLIC1() {
205205
}
206206

207207
@Test
208-
public void testLIC2() {
209-
/* LIC2 returns true if and only if
208+
public void testValidInputsLIC2() {
209+
/* Contract: LIC2 returns true if and only if
210210
there exists at least one set of three consecutive data points which form an angle such that:
211211
angle < (PI−EPSILON)
212212
or
@@ -218,11 +218,6 @@ point or the last point (or both) coincides with the vertex, the angle is undefi
218218
Parameters p = new Parameters();
219219
p.EPSILON = 0.01;
220220

221-
Point[] points1 = new Point[] {
222-
new Point(2, 2),
223-
new Point(5, 5)
224-
};
225-
226221
Point[] points2 = new Point[] {
227222
new Point(1, 0),
228223
new Point(1, 0),
@@ -243,35 +238,55 @@ point or the last point (or both) coincides with the vertex, the angle is undefi
243238
new Point(-3, -1)
244239
};
245240

246-
//Tests that false is returned when NUMPOINTS < 3
247-
assertThrows(IllegalArgumentException.class, () -> {
248-
LIC.LIC2(points1.length, points1, p);
249-
});
250-
251241
//Tests that false is returned if any point coincides with the vertex
252242
assertFalse(LIC.LIC2(points2.length, points2, p));
253243

254244
//Tests that true is returned for an input which fulfills the contract
255245
p.EPSILON = (PI / 2) - 0.01;
256246
assertTrue(LIC.LIC2(points3.length, points3, p));
257247

258-
//Tests that false is returned when EPSILON < 0
248+
//Tests that false is returned when there does not exist at least one set of three
249+
//consecutive data points which form an angle such that: angle < (PI−EPSILON)
250+
//or angle > (PI+EPSILON)
251+
p.EPSILON = PI / 2 + 0.01;
252+
assertFalse(LIC.LIC2(points4.length, points3, p));
253+
}
254+
255+
@Test
256+
public void testInvalidInputsLIC2() {
257+
/*Contract: LIC2 should throw IllegalArgumentException if
258+
0 > EPSILON, or EPSILON > PI, or number of points < 3,
259+
because it constitutes an invalid input*/
260+
Parameters p = new Parameters();
261+
p.EPSILON = 0.01;
262+
263+
Point[] points1 = new Point[] {
264+
new Point(2, 2),
265+
new Point(5, 5)
266+
};
267+
268+
Point[] points4 = new Point[] {
269+
new Point(-2, -2),
270+
new Point(-2, -1),
271+
new Point(-3, -1)
272+
};
273+
274+
// Tests that IllegalArgumentException is thrown when NUMPOINTS < 3
275+
assertThrows(IllegalArgumentException.class, () -> {
276+
LIC.LIC2(points1.length, points1, p);
277+
});
278+
279+
// Tests that IllegalArgumentException is thrown when EPSILON < 0
259280
p.EPSILON = -0.01;
260281
assertThrows(IllegalArgumentException.class, () -> {
261282
LIC.LIC2(points4.length, points4, p);
262283
});
263284

264-
//Tests that false is returned when EPISILON > PI
285+
// Tests that IllegalArgumentException is thrown when EPISILON > PI
265286
p.EPSILON = PI + 0.01;
266287
assertThrows(IllegalArgumentException.class, () -> {
267288
LIC.LIC2(points4.length, points4, p);
268289
});
269-
270-
//Tests that false is returned when there does not exist at least one set of three
271-
//consecutive data points which form an angle such that: angle < (PI−EPSILON)
272-
//or angle > (PI+EPSILON)
273-
p.EPSILON = PI / 2 + 0.01;
274-
assertFalse(LIC.LIC2(points4.length, points3, p));
275290
}
276291

277292
// LIC3 Unit Tests
@@ -689,7 +704,7 @@ public void testLIC7() {
689704
}
690705

691706
@Test
692-
public void testLIC8() {
707+
public void testValidInputsLIC8() {
693708
/*
694709
* Contract: LIC8 returns true if and only if there exists at least one set of
695710
* three data points
@@ -711,26 +726,6 @@ public void testLIC8() {
711726

712727
Parameters p = new Parameters();
713728
p.RADIUS1 = 1;
714-
p.A_PTS = 0;
715-
p.B_PTS = 1;
716-
717-
// Tests that IllegalArgumentException is thrown when A PTS < 1
718-
assertThrows(IllegalArgumentException.class, () -> {
719-
LIC.LIC8(points2.length, points2, p);
720-
});
721-
// Tests that IllegalArgumentException is thrown when B PTS < 1
722-
p.A_PTS = 1;
723-
p.B_PTS = 0;
724-
assertThrows(IllegalArgumentException.class, () -> {
725-
LIC.LIC8(points2.length, points2, p);
726-
});
727-
728-
// Tests that IllegalArgumentException is thrown when A PTS + B PTS > (NUMPOINTS-3)
729-
p.A_PTS = 2;
730-
p.B_PTS = 1;
731-
assertThrows(IllegalArgumentException.class, () -> {
732-
LIC.LIC8(points2.length, points2, p);
733-
});
734729

735730
// Tests that false is returned when there exists a set of three data points
736731
// separated by exactly A PTS and B PTS
@@ -739,6 +734,7 @@ public void testLIC8() {
739734
// radius RADIUS1
740735
p.RADIUS1 = 100;
741736
p.A_PTS = 1;
737+
p.B_PTS = 1;
742738
assertFalse(LIC.LIC8(points2.length, points2, p));
743739

744740
Point[] points3 = new Point[] {
@@ -758,15 +754,55 @@ public void testLIC8() {
758754
p.RADIUS1 = 1;
759755
assertFalse(LIC.LIC8(points3.length, points3, p));
760756

757+
p.RADIUS1 = 1;
758+
// Tests that true is returned for a valid input
759+
assertTrue(LIC.LIC8(points2.length, points2, p));
760+
}
761+
762+
@Test
763+
public void testInvalidInputsLIC8() {
764+
/* Contract: LIC8 should throw IllegalArgumentException if
765+
A_PTS < 1, or B_PTS < 1, or A_PTS+B_PTS > numPoints-3, or 0>RADIUS1,
766+
because it constitutes an invalid input*/
767+
768+
Point[] points2 = new Point[] {
769+
new Point(0, 10),
770+
new Point(0, 0),
771+
new Point(-10, 0),
772+
new Point(0, -1),
773+
new Point(10, 0)
774+
};
775+
776+
Parameters p = new Parameters();
777+
p.RADIUS1 = 1;
778+
p.A_PTS = 0;
779+
p.B_PTS = 1;
780+
781+
// Tests that IllegalArgumentException is thrown when A PTS < 1
782+
assertThrows(IllegalArgumentException.class, () -> {
783+
LIC.LIC8(points2.length, points2, p);
784+
});
785+
// Tests that IllegalArgumentException is thrown when B PTS < 1
786+
p.A_PTS = 1;
787+
p.B_PTS = 0;
788+
assertThrows(IllegalArgumentException.class, () -> {
789+
LIC.LIC8(points2.length, points2, p);
790+
});
791+
792+
// Tests that IllegalArgumentException is thrown when A PTS + B PTS > (NUMPOINTS-3)
793+
p.A_PTS = 2;
794+
p.B_PTS = 1;
795+
assertThrows(IllegalArgumentException.class, () -> {
796+
LIC.LIC8(points2.length, points2, p);
797+
});
798+
761799
// Tests that IllegalArgumentException is thrown when RADIUS1 < 0:
762800
p.RADIUS1 = -1;
801+
p.A_PTS = 1;
763802
assertThrows(IllegalArgumentException.class, () -> {
764803
LIC.LIC8(points2.length, points2, p);
765804
});
766805

767-
p.RADIUS1 = 1;
768-
// Tests that true is returned for a valid input
769-
assertTrue(LIC.LIC8(points2.length, points2, p));
770806
}
771807

772808
// LIC9 Unit Tests
@@ -1044,7 +1080,7 @@ public void LIC10_true() {
10441080
}
10451081

10461082
@Test
1047-
public void testLIC11() {
1083+
public void testValidInputsLIC11() {
10481084
/* Contract: LIC11 returns true if and only if there exists at least one set of two data points,
10491085
(X[i],Y[i]) and (X[j],Y[j]), separated by
10501086
exactly G PTS consecutive intervening points, such that X[j] - X[i] < 0. (where i < j ) The
@@ -1071,18 +1107,6 @@ public void testLIC11() {
10711107
};
10721108
Parameters p = new Parameters();
10731109

1074-
p.G_PTS = 0;
1075-
// Tests that IllegalArgumentException is thrown when G_PTS < 1
1076-
assertThrows(IllegalArgumentException.class, () -> {
1077-
LIC.LIC11(points1.length, points1, p);
1078-
});
1079-
1080-
p.G_PTS = 2;
1081-
// Tests that IllegalArgumentException is thrown when NUMPOINTS-2 < G_PTS
1082-
assertThrows(IllegalArgumentException.class, () -> {
1083-
LIC.LIC11(points1.length, points1, p);
1084-
});
1085-
10861110
//Tests that false is returned when there does not exist at least one set of two data points,
10871111
//(X[i],Y[i]) and (X[j],Y[j]), separated by
10881112
//exactly G PTS consecutive intervening points, such that X[j] - X[i] < 0. (where i < j )
@@ -1100,6 +1124,33 @@ public void testLIC11() {
11001124

11011125
}
11021126

1127+
@Test
1128+
public void testInvalidInputsLIC11() {
1129+
/* Contract: LIC11 should throw IllegalArgumentException if
1130+
1 > G_PTS, or G_PTS > numPoints-2, because it constitutes
1131+
an invalid input */
1132+
1133+
Point[] points1 = new Point[] {
1134+
new Point(1, -1),
1135+
new Point(0, 0),
1136+
new Point(-1, 1)
1137+
};
1138+
1139+
Parameters p = new Parameters();
1140+
1141+
p.G_PTS = 0;
1142+
// Tests that IllegalArgumentException is thrown when G_PTS < 1
1143+
assertThrows(IllegalArgumentException.class, () -> {
1144+
LIC.LIC11(points1.length, points1, p);
1145+
});
1146+
1147+
p.G_PTS = 2;
1148+
// Tests that IllegalArgumentException is thrown when NUMPOINTS-2 < G_PTS
1149+
assertThrows(IllegalArgumentException.class, () -> {
1150+
LIC.LIC11(points1.length, points1, p);
1151+
});
1152+
}
1153+
11031154

11041155
// LIC12 Unit Tests
11051156

0 commit comments

Comments
 (0)