Skip to content

Commit 73dd86e

Browse files
feat: Add exceptions for illegal arguments
Add IllegalArgumentExceptions to LIC0, LIC6, LIC10, for not valid argument. Adjust or create new tests, modify existing tests so they still run. Closes #166
1 parent 5338a08 commit 73dd86e

3 files changed

Lines changed: 122 additions & 46 deletions

File tree

src/main/java/LIC.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
public class LIC {
44

5-
public static boolean LIC0(int numPoints, Point[] points, Parameters p) {
6-
if (p.LENGTH1 < 0) return false;
5+
public static boolean LIC0(int numPoints, Point[] points, Parameters p) throws IllegalArgumentException {
6+
if (p.LENGTH1 < 0 || numPoints < 2) {
7+
throw new IllegalArgumentException();
8+
}
79
for (int i = 0; i < numPoints - 1; i++) {
810
if (Point.distance(points[i], points[i + 1]) > p.LENGTH1)
911
return true;
@@ -85,9 +87,11 @@ public static boolean LIC5(int numPoints, Point[] points, Parameters p) {
8587
return false;
8688
}
8789

88-
public static boolean LIC6(int numPoints, Point[] points, Parameters p) {
89-
if (numPoints < 3 || p.N_PTS < 3 || p.DIST < 0 || numPoints < p.N_PTS ||
90-
p.DIST < 0) return false;
90+
public static boolean LIC6(int numPoints, Point[] points, Parameters p) throws IllegalArgumentException {
91+
if (numPoints < 3) return false;
92+
if (p.N_PTS < 3 || p.DIST < 0 || numPoints < p.N_PTS) {
93+
throw new IllegalArgumentException();
94+
}
9195

9296
for (int i = 0; i <= numPoints - p.N_PTS; i++) {
9397
Point p_start = points[i];
@@ -152,9 +156,11 @@ public static boolean LIC9(int numPoints, Point[] points, Parameters p){
152156
return false;
153157
}
154158

155-
public static boolean LIC10(int numPoints, Point[] points, Parameters p) {
156-
if (numPoints < 5 || p.E_PTS < 1 ||p.F_PTS < 1 || p.E_PTS + p.F_PTS > numPoints - 3 ||
157-
p.AREA1 < 0) return false;
159+
public static boolean LIC10(int numPoints, Point[] points, Parameters p) throws IllegalArgumentException {
160+
if (numPoints < 5) return false;
161+
if (p.E_PTS < 1 ||p.F_PTS < 1 || p.E_PTS + p.F_PTS > numPoints - 3 || p.AREA1 < 0) {
162+
throw new IllegalArgumentException();
163+
}
158164

159165
for (int i = 0; i < numPoints - p.F_PTS - p.E_PTS - 2; i ++) {
160166
Point p1 = points[i];

src/test/java/DecideTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,25 @@ public void CMV_is_Vector_15_And_Only_True_Or_False() {
5050

5151
int numPoints = points.length;
5252
Parameters p = new Parameters();
53+
p.LENGTH1 = 0; //Best for all LICS
54+
p.RADIUS1 = 0; //Best for all LICS
55+
p.EPSILON = 0; //Best for all LICS
56+
p.AREA1 = 0; //Best for all LICs
57+
p.Q_PTS = 5; // The one in LIC4 testcase
58+
p.QUADS = 2; // Same for LIC4
59+
p.DIST = 3.0; //Same for LIC6
60+
p.N_PTS = 3; //Same for LIC6
61+
p.K_PTS = 1; //same for LIC7 and LIC12
62+
p.A_PTS = 1; //Same for LIC8 and LIC 13
63+
p.B_PTS = 1; //Same for LIC8 and LIC 13
64+
p.C_PTS = 1; //Same for LIC9
65+
p.D_PTS = 1; //Same for LIC9
66+
p.E_PTS = 1; //Same for LIC 10 and 14
67+
p.F_PTS = 1; //Same for LIC 10 and 14
68+
p.G_PTS = 1; //Same for LIC 11
69+
p.LENGTH2 = 10000;
70+
p.RADIUS2 = 10000;
71+
p.AREA2 = 10000;
5372
Matrix cmv = Decide.CMV(numPoints, points, p);
5473

5574
assertEquals(15, cmv.M);

src/test/java/LICTests.java

Lines changed: 89 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -146,21 +146,21 @@ void LIC0_false_with_smaller_distance() {
146146
}
147147

148148
@Test
149-
// Contract: LIC0 is false iff less than two points exist.
150-
void LIC0_false_with_too_few_points() {
149+
// Contract: LIC0 throws an IllegelArgumentException if less than two points exist.
150+
void LIC0_throws_with_too_few_points() {
151151
Parameters p = new Parameters();
152152
p.LENGTH1 = 4;
153153
Point[] pts = { new Point(0, 0) };
154-
assertFalse(LIC.LIC0(pts.length, pts, p));
154+
assertThrows(IllegalArgumentException.class, () -> LIC.LIC0(pts.length, pts, p));
155155
}
156156

157157
@Test
158-
// Contract: LIC0 is false iff LENGTH1 < 0
159-
void LIC0_false_with_length_too_small() {
158+
// Contract: LIC0 throws an IllegelArgumentException if LENGTH1 < 0
159+
void LIC0_throws_with_length_too_small() {
160160
Parameters p = new Parameters();
161161
p.LENGTH1 = -1;
162162
Point[] pts = { new Point(0, 0), new Point(3, 4)};
163-
assertFalse(LIC.LIC0(pts.length, pts, p));
163+
assertThrows(IllegalArgumentException.class, () -> LIC.LIC0(pts.length, pts, p));
164164
}
165165

166166
@Test
@@ -494,8 +494,8 @@ public void LIC6_false_with_too_few_points() {
494494
}
495495

496496
@Test
497-
public void LIC6_false_with_DIST_too_small() {
498-
// Contract: LIC6 is false iff DIST < 0
497+
public void LIC6_throws_exception_with_DIST_too_small() {
498+
// Contract: LIC6 throws an exception iff DIST < 0
499499
Parameters p = new Parameters();
500500
p.N_PTS = 3;
501501
p.DIST = -1;
@@ -511,12 +511,12 @@ public void LIC6_false_with_DIST_too_small() {
511511
new Point(6, 0),
512512
new Point(1, -1)
513513
};
514-
assertFalse(LIC.LIC6(points3.length, points3, p));
514+
assertThrows(IllegalArgumentException.class, () -> LIC.LIC6(points3.length, points3, p));
515515
}
516516

517517
@Test
518-
public void LIC6_false_with_too_small_N_PTS() {
519-
// Contract: LIC6 is false iff N_PTS < 3
518+
public void LIC6_throws_exception_with_too_small_N_PTS() {
519+
// Contract: LIC6 throws an exception iff N_PTS < 3
520520
Parameters p = new Parameters();
521521
p.N_PTS = 2;
522522
p.DIST = 30;
@@ -532,7 +532,28 @@ public void LIC6_false_with_too_small_N_PTS() {
532532
new Point(6, 0),
533533
new Point(1, -1)
534534
};
535-
assertFalse(LIC.LIC6(points2.length, points2, p));
535+
assertThrows(IllegalArgumentException.class, () -> LIC.LIC6(points2.length, points2, p));
536+
}
537+
538+
@Test
539+
public void LIC6_throws_exception_with_N_PTS_bigger_than_numpoints() {
540+
// Contract: LIC6 throws an exception iff N_PTS > numpoints
541+
Parameters p = new Parameters();
542+
p.N_PTS = 20;
543+
p.DIST = 30;
544+
Point[] points2 = new Point[] {
545+
new Point(0, 0),
546+
new Point(1, 0),
547+
new Point(2, 0),
548+
new Point(1, 1),
549+
new Point(2, 2),
550+
new Point(1, 1),
551+
new Point(0, 3),
552+
new Point(1, 2),
553+
new Point(6, 0),
554+
new Point(1, -1)
555+
};
556+
assertThrows(IllegalArgumentException.class, () -> LIC.LIC6(points2.length, points2, p));
536557
}
537558

538559
@Test
@@ -843,57 +864,87 @@ public void LIC10_false_when_too_few_points() {
843864
}
844865

845866
@Test
846-
public void LIC10_false_when_area_too_small() {
847-
// Contract: LIC10 is false if the area is smaller than 0
867+
public void LIC10_throws_exception_when_area_too_small() {
868+
// Contract: LIC10 throws exception if the area is smaller than 0
848869
Point [] points = new Point[] {
849870
new Point(1, 0),
850871
new Point(0, 0),
851-
new Point(1, 0)
872+
new Point(1, 0),
873+
new Point(1, 0),
874+
new Point(0, 0),
875+
new Point(0, 0),
876+
new Point(1, 0),
877+
new Point(1, 0),
878+
new Point(0, 0)
852879
};
853880
Parameters p = new Parameters();
854881
p.E_PTS = 2;
855882
p.F_PTS = 2;
856883
p.AREA1 = -1;
857-
assertFalse(LIC.LIC10(3, points, p));
884+
assertThrows(IllegalArgumentException.class, () -> LIC.LIC10(points.length, points, p));
858885
}
859886

860-
@Test
861-
public void LIC10_false_when_EPTS_plus_FTPS_too_large() {
862-
// Contract: LIC10 is false if E_PTS + F_PTS <= numpoints - 3
887+
@Test
888+
public void LIC10_throws_exception_when_EPTS_too_small() {
889+
// Contract: LIC10 throws exception if the EPTS < 1
863890
Point [] points = new Point[] {
864891
new Point(1, 0),
865892
new Point(0, 0),
866893
new Point(1, 0),
894+
new Point(1, 0),
867895
new Point(0, 0),
868-
new Point(1, 0)
896+
new Point(0, 0),
897+
new Point(1, 0),
898+
new Point(1, 0),
899+
new Point(0, 0)
869900
};
870901
Parameters p = new Parameters();
871-
p.E_PTS = 1;
902+
p.E_PTS = 0;
872903
p.F_PTS = 2;
873-
p.AREA1 = 10;
874-
assertFalse(LIC.LIC10(5, points, p));
904+
p.AREA1 = 4;
905+
assertThrows(IllegalArgumentException.class, () -> LIC.LIC10(points.length, points, p));
875906
}
876907

877908
@Test
878-
public void LIC10_false_with_smaller_area() {
879-
/*
880-
* Contract: LIC10 is false iff there exists no set of three data points
881-
* separated by exactly E PTS and F PTS consecutive intervening points, respectively,
882-
* that are the vertices of a triangle with area greater than AREA1.
883-
*/
909+
public void LIC10_throws_exception_when_FPTS_too_small() {
910+
// Contract: LIC10 throws exception if FPTS < 1
884911
Point [] points = new Point[] {
885912
new Point(1, 0),
886-
new Point(0, 1),
887-
new Point(2, 0),
888-
new Point(0, 2),
889-
new Point(1, 1),
890-
new Point(1, 1)
913+
new Point(0, 0),
914+
new Point(1, 0),
915+
new Point(1, 0),
916+
new Point(0, 0),
917+
new Point(0, 0),
918+
new Point(1, 0),
919+
new Point(1, 0),
920+
new Point(0, 0)
891921
};
892922
Parameters p = new Parameters();
893-
p.E_PTS = 1;
894-
p.F_PTS = 1;
895-
p.AREA1 = 10;
896-
assertFalse(LIC.LIC10(points.length, points, p));
923+
p.E_PTS = 2;
924+
p.F_PTS = 0;
925+
p.AREA1 = 4;
926+
assertThrows(IllegalArgumentException.class, () -> LIC.LIC10(points.length, points, p));
927+
}
928+
929+
@Test
930+
public void LIC10_throws_exception_when_EPTS_plus_FPTS_too_large() {
931+
// Contract: LIC10 throws exception if EPTS + FPTS > numpoints - 3
932+
Point [] points = new Point[] {
933+
new Point(1, 0),
934+
new Point(0, 0),
935+
new Point(1, 0),
936+
new Point(1, 0),
937+
new Point(0, 0),
938+
new Point(0, 0),
939+
new Point(1, 0),
940+
new Point(1, 0),
941+
new Point(0, 0)
942+
};
943+
Parameters p = new Parameters();
944+
p.E_PTS = 5;
945+
p.F_PTS = 5;
946+
p.AREA1 = 4;
947+
assertThrows(IllegalArgumentException.class, () -> LIC.LIC10(points.length, points, p));
897948
}
898949

899950
@Test

0 commit comments

Comments
 (0)