Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/main/java/LIC.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ public static boolean LIC1(int numPoints, Point[] points, Parameters p) throws I
public static boolean LIC2(int numPoints, Point[] points, Parameters p) {
double PI = 3.14159;
if (!(0 <= p.EPSILON && p.EPSILON < PI)) {
return false;
throw new IllegalArgumentException();
}
if (numPoints == 2) {
return false;
if (numPoints < 3) {
throw new IllegalArgumentException();
}
for (int i = 0; i < numPoints - 2; i++) {
Point p1 = points[i];
Expand Down Expand Up @@ -134,8 +134,11 @@ public static boolean LIC7(int numPoints, Point[] points, Parameters p) throws I
}

public static boolean LIC8(int numPoints, Point[] points, Parameters p) {
if (p.A_PTS < 1 || p.B_PTS < 1 || numPoints < 5 || p.A_PTS+p.B_PTS > (numPoints-3) || 0>p.RADIUS1){
return false;
if (p.A_PTS < 1 || p.B_PTS < 1 || p.A_PTS+p.B_PTS > (numPoints-3) || 0>p.RADIUS1){
throw new IllegalArgumentException();
}
if (numPoints < 5){
return false;
}
for (int i = 0; i + p.A_PTS+p.B_PTS < numPoints-2; i++){
Point p1 = points[i];
Expand Down Expand Up @@ -191,8 +194,8 @@ public static boolean LIC10(int numPoints, Point[] points, Parameters p) throws
}

public static boolean LIC11(int numPoints, Point[] points , Parameters p){
if (numPoints < 3 || 1 > p.G_PTS || p.G_PTS > numPoints-2){
return false;
if ( 1 > p.G_PTS || p.G_PTS > numPoints-2){
throw new IllegalArgumentException();
}
for (int i = 0; i + p.G_PTS < numPoints-1; i++){
Point p1 = points[i];
Expand Down
74 changes: 35 additions & 39 deletions src/test/java/LICTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,9 @@ point or the last point (or both) coincides with the vertex, the angle is undefi
};

//Tests that false is returned when NUMPOINTS < 3
assertFalse(LIC.LIC2(points1.length, points1, p));
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));
Expand All @@ -255,11 +257,15 @@ point or the last point (or both) coincides with the vertex, the angle is undefi

//Tests that false is returned when EPSILON < 0
p.EPSILON = -0.01;
assertFalse(LIC.LIC2(points4.length, points4, p));
assertThrows(IllegalArgumentException.class, () -> {
LIC.LIC2(points4.length, points4, p);
});

//Tests that false is returned when EPISILON > PI
p.EPSILON = PI + 0.01;
assertFalse(LIC.LIC2(points4.length, points4, p));
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)
Expand Down Expand Up @@ -698,19 +704,6 @@ public void testLIC8() {
* A PTS+B PTS ≤ (NUMPOINTS−3)
*/

Point[] points1 = new Point[] {
new Point(0, 10),
new Point(0, 0),
new Point(-10, 0),
new Point(10, 0)
};
// Tests that false is returned when NUMPOINTS < 5
Parameters p = new Parameters();
p.RADIUS1 = 3;
p.A_PTS = 1;
p.B_PTS = 1;
assertFalse(LIC.LIC8(points1.length, points1, p));

Point[] points2 = new Point[] {
new Point(0, 10),
new Point(0, 0),
Expand All @@ -719,23 +712,28 @@ public void testLIC8() {
new Point(10, 0)
};


Parameters p = new Parameters();
p.RADIUS1 = 1;
p.A_PTS = 0;
p.B_PTS = 1;

// Tests that false is returned when A PTS < 1
assertFalse(LIC.LIC8(points2.length, points2, p));

// Tests that false is returned when 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;
assertFalse(LIC.LIC8(points2.length, points2, p));
assertThrows(IllegalArgumentException.class, () -> {
LIC.LIC8(points2.length, points2, p);
});

// Tests that false is returned when A PTS + B PTS > (NUMPOINTS-3)
// Tests that IllegalArgumentException is thrown when A PTS + B PTS > (NUMPOINTS-3)
p.A_PTS = 2;
p.B_PTS = 1;
assertFalse(LIC.LIC8(points2.length, points2, p));
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
Expand Down Expand Up @@ -763,9 +761,11 @@ public void testLIC8() {
p.RADIUS1 = 1;
assertFalse(LIC.LIC8(points3.length, points3, p));

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

p.RADIUS1 = 1;
// Tests that true is returned for a valid input
Expand Down Expand Up @@ -1068,11 +1068,6 @@ public void testLIC11() {
new Point(-1, 1)
};

Point[] points2 = new Point[] {
new Point(1, -1),
new Point(-1, 1)
};

Point[] points3 = new Point[] {
new Point(-1, -1),
new Point(0, 0),
Expand All @@ -1086,22 +1081,23 @@ public void testLIC11() {

};
Parameters p = new Parameters();
p.G_PTS = 1;

//Tests that false is returned when NUMPOINTS < 3
assertFalse(LIC.LIC11(points2.length, points2, p));

//Tests that false is returned when G_PTS < 1
p.G_PTS = 0;
assertFalse(LIC.LIC11(points1.length, points1, p));
// Tests that IllegalArgumentException is thrown when G_PTS < 1
assertThrows(IllegalArgumentException.class, () -> {
LIC.LIC11(points1.length, points1, p);
});

//Tests that false is returned when NUMPOINTS-2 < G_PTS
p.G_PTS = 2;
assertFalse(LIC.LIC11(points1.length, points1, p));
// 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 )
p.G_PTS = 1;
assertFalse(LIC.LIC11(points3.length, points3, p));

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