Skip to content

Commit 96383fd

Browse files
authored
feat: add exception for illegal args for LIC 2, 8, and 11, and made unit tests (#176)
closes #169
1 parent 863e116 commit 96383fd

2 files changed

Lines changed: 45 additions & 46 deletions

File tree

src/main/java/LIC.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ public static boolean LIC1(int numPoints, Point[] points, Parameters p) throws I
3131
public static boolean LIC2(int numPoints, Point[] points, Parameters p) {
3232
double PI = 3.14159;
3333
if (!(0 <= p.EPSILON && p.EPSILON < PI)) {
34-
return false;
34+
throw new IllegalArgumentException();
3535
}
36-
if (numPoints == 2) {
37-
return false;
36+
if (numPoints < 3) {
37+
throw new IllegalArgumentException();
3838
}
3939
for (int i = 0; i < numPoints - 2; i++) {
4040
Point p1 = points[i];
@@ -135,8 +135,11 @@ public static boolean LIC7(int numPoints, Point[] points, Parameters p) throws I
135135
}
136136

137137
public static boolean LIC8(int numPoints, Point[] points, Parameters p) {
138-
if (p.A_PTS < 1 || p.B_PTS < 1 || numPoints < 5 || p.A_PTS+p.B_PTS > (numPoints-3) || 0>p.RADIUS1){
139-
return false;
138+
if (p.A_PTS < 1 || p.B_PTS < 1 || p.A_PTS+p.B_PTS > (numPoints-3) || 0>p.RADIUS1){
139+
throw new IllegalArgumentException();
140+
}
141+
if (numPoints < 5){
142+
return false;
140143
}
141144
for (int i = 0; i + p.A_PTS+p.B_PTS < numPoints-2; i++){
142145
Point p1 = points[i];
@@ -191,8 +194,8 @@ public static boolean LIC10(int numPoints, Point[] points, Parameters p) throws
191194
}
192195

193196
public static boolean LIC11(int numPoints, Point[] points , Parameters p){
194-
if (numPoints < 3 || 1 > p.G_PTS || p.G_PTS > numPoints-2){
195-
return false;
197+
if ( 1 > p.G_PTS || p.G_PTS > numPoints-2){
198+
throw new IllegalArgumentException();
196199
}
197200
for (int i = 0; i + p.G_PTS < numPoints-1; i++){
198201
Point p1 = points[i];

src/test/java/LICTests.java

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,9 @@ point or the last point (or both) coincides with the vertex, the angle is undefi
244244
};
245245

246246
//Tests that false is returned when NUMPOINTS < 3
247-
assertFalse(LIC.LIC2(points1.length, points1, p));
247+
assertThrows(IllegalArgumentException.class, () -> {
248+
LIC.LIC2(points1.length, points1, p);
249+
});
248250

249251
//Tests that false is returned if any point coincides with the vertex
250252
assertFalse(LIC.LIC2(points2.length, points2, p));
@@ -255,11 +257,15 @@ point or the last point (or both) coincides with the vertex, the angle is undefi
255257

256258
//Tests that false is returned when EPSILON < 0
257259
p.EPSILON = -0.01;
258-
assertFalse(LIC.LIC2(points4.length, points4, p));
260+
assertThrows(IllegalArgumentException.class, () -> {
261+
LIC.LIC2(points4.length, points4, p);
262+
});
259263

260264
//Tests that false is returned when EPISILON > PI
261265
p.EPSILON = PI + 0.01;
262-
assertFalse(LIC.LIC2(points4.length, points4, p));
266+
assertThrows(IllegalArgumentException.class, () -> {
267+
LIC.LIC2(points4.length, points4, p);
268+
});
263269

264270
//Tests that false is returned when there does not exist at least one set of three
265271
//consecutive data points which form an angle such that: angle < (PI−EPSILON)
@@ -695,19 +701,6 @@ public void testLIC8() {
695701
* A PTS+B PTS ≤ (NUMPOINTS−3)
696702
*/
697703

698-
Point[] points1 = new Point[] {
699-
new Point(0, 10),
700-
new Point(0, 0),
701-
new Point(-10, 0),
702-
new Point(10, 0)
703-
};
704-
// Tests that false is returned when NUMPOINTS < 5
705-
Parameters p = new Parameters();
706-
p.RADIUS1 = 3;
707-
p.A_PTS = 1;
708-
p.B_PTS = 1;
709-
assertFalse(LIC.LIC8(points1.length, points1, p));
710-
711704
Point[] points2 = new Point[] {
712705
new Point(0, 10),
713706
new Point(0, 0),
@@ -716,23 +709,28 @@ public void testLIC8() {
716709
new Point(10, 0)
717710
};
718711

719-
712+
Parameters p = new Parameters();
720713
p.RADIUS1 = 1;
721714
p.A_PTS = 0;
722715
p.B_PTS = 1;
723716

724-
// Tests that false is returned when A PTS < 1
725-
assertFalse(LIC.LIC8(points2.length, points2, p));
726-
727-
// Tests that false is returned when B PTS < 1
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
728722
p.A_PTS = 1;
729723
p.B_PTS = 0;
730-
assertFalse(LIC.LIC8(points2.length, points2, p));
724+
assertThrows(IllegalArgumentException.class, () -> {
725+
LIC.LIC8(points2.length, points2, p);
726+
});
731727

732-
// Tests that false is returned when A PTS + B PTS > (NUMPOINTS-3)
728+
// Tests that IllegalArgumentException is thrown when A PTS + B PTS > (NUMPOINTS-3)
733729
p.A_PTS = 2;
734730
p.B_PTS = 1;
735-
assertFalse(LIC.LIC8(points2.length, points2, p));
731+
assertThrows(IllegalArgumentException.class, () -> {
732+
LIC.LIC8(points2.length, points2, p);
733+
});
736734

737735
// Tests that false is returned when there exists a set of three data points
738736
// separated by exactly A PTS and B PTS
@@ -760,9 +758,11 @@ public void testLIC8() {
760758
p.RADIUS1 = 1;
761759
assertFalse(LIC.LIC8(points3.length, points3, p));
762760

763-
// Tests that false is returned if RADIUS1 < 0:
761+
// Tests that IllegalArgumentException is thrown when RADIUS1 < 0:
764762
p.RADIUS1 = -1;
765-
assertFalse(LIC.LIC8(points2.length, points2, p));
763+
assertThrows(IllegalArgumentException.class, () -> {
764+
LIC.LIC8(points2.length, points2, p);
765+
});
766766

767767
p.RADIUS1 = 1;
768768
// Tests that true is returned for a valid input
@@ -1057,11 +1057,6 @@ public void testLIC11() {
10571057
new Point(-1, 1)
10581058
};
10591059

1060-
Point[] points2 = new Point[] {
1061-
new Point(1, -1),
1062-
new Point(-1, 1)
1063-
};
1064-
10651060
Point[] points3 = new Point[] {
10661061
new Point(-1, -1),
10671062
new Point(0, 0),
@@ -1075,22 +1070,23 @@ public void testLIC11() {
10751070

10761071
};
10771072
Parameters p = new Parameters();
1078-
p.G_PTS = 1;
1079-
1080-
//Tests that false is returned when NUMPOINTS < 3
1081-
assertFalse(LIC.LIC11(points2.length, points2, p));
10821073

1083-
//Tests that false is returned when G_PTS < 1
10841074
p.G_PTS = 0;
1085-
assertFalse(LIC.LIC11(points1.length, points1, p));
1075+
// Tests that IllegalArgumentException is thrown when G_PTS < 1
1076+
assertThrows(IllegalArgumentException.class, () -> {
1077+
LIC.LIC11(points1.length, points1, p);
1078+
});
10861079

1087-
//Tests that false is returned when NUMPOINTS-2 < G_PTS
10881080
p.G_PTS = 2;
1089-
assertFalse(LIC.LIC11(points1.length, points1, p));
1081+
// Tests that IllegalArgumentException is thrown when NUMPOINTS-2 < G_PTS
1082+
assertThrows(IllegalArgumentException.class, () -> {
1083+
LIC.LIC11(points1.length, points1, p);
1084+
});
10901085

10911086
//Tests that false is returned when there does not exist at least one set of two data points,
10921087
//(X[i],Y[i]) and (X[j],Y[j]), separated by
10931088
//exactly G PTS consecutive intervening points, such that X[j] - X[i] < 0. (where i < j )
1089+
p.G_PTS = 1;
10941090
assertFalse(LIC.LIC11(points3.length, points3, p));
10951091

10961092
//Tests that false is returned if there exists at least one set of two data points,

0 commit comments

Comments
 (0)