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
14 changes: 10 additions & 4 deletions src/main/java/LIC.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ public static boolean LIC3(int numPoints, Point[] points, Parameters p) {

public static boolean LIC4(int numPoints, Point[] points, Parameters p) {
if (p.Q_PTS > numPoints || p.Q_PTS < 2) {
return false;
throw new IllegalArgumentException();
}
if (p.QUADS < 1 || p.QUADS > 3) {
return false;
throw new IllegalArgumentException();
}

for (int i = 0; i <= numPoints - p.Q_PTS; i++) {
Expand All @@ -79,6 +79,9 @@ public static boolean LIC4(int numPoints, Point[] points, Parameters p) {
}

public static boolean LIC5(int numPoints, Point[] points, Parameters p) {
if (numPoints < 2) {
throw new IllegalArgumentException();
}
for (int i = 0; i < numPoints - 1; i++) {
if(points[i+1].x - points[i].x < 0) {
return true;
Expand Down Expand Up @@ -226,11 +229,14 @@ public static boolean LIC13(int numPoints, Point[] points, Parameters p) {
}

public static boolean LIC14(int numPoints, Point[] points, Parameters p) {
if (numPoints < 5 || p.AREA1 < 0 || p.AREA2 < 0 || p.E_PTS < 1 || p.F_PTS < 1) {
if (numPoints < 5) {
return false;
}
if (p.AREA1 < 0 || p.AREA2 < 0 || p.E_PTS < 1 || p.F_PTS < 1) {
throw new IllegalArgumentException();
}
if (p.E_PTS + p.F_PTS + 3 > numPoints) {
return false;
throw new IllegalArgumentException();
}

boolean moreThanArea1 = false;
Expand Down
130 changes: 124 additions & 6 deletions src/test/java/LICTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -356,13 +356,34 @@ void LIC4_true_five_consecutive_points_three_quadrants() {
}

@Test
void LIC4_false_on_bad_input() {
void LIC4_throws_on_too_few_points() {
/*
* Contract: LIC4 has constraints: 2 <= Q_PTS <= NUMPOINTS, 1 <= QUADS <= 3.
Set Q_PTS = 5, QUADS = 4, with 4 points.
* Set Q_PTS = 5, QUADS = 3, with 4 points.
*/
Parameters p = new Parameters();
p.Q_PTS = 5;
p.QUADS = 3;

Point[] points = new Point[] {
new Point(0, 0),
new Point(1, 0),
new Point(-1, 0),
new Point(0, -2),
};
assertThrows(IllegalArgumentException.class, () -> {
LIC.LIC4(points.length, points, p);
});
}

@Test
void LIC4_throws_on_too_many_quads() {
/*
* Contract: LIC4 has constraints: 2 <= Q_PTS <= NUMPOINTS, 1 <= QUADS <= 3.
* Set Q_PTS = 3, QUADS = 4, with 4 points.
*/
Parameters p = new Parameters();
p.Q_PTS = 3;
p.QUADS = 4;

Point[] points = new Point[] {
Expand All @@ -371,11 +392,13 @@ void LIC4_false_on_bad_input() {
new Point(-1, 0),
new Point(0, -2),
};
assertFalse(LIC.LIC4(points.length, points, p));
assertThrows(IllegalArgumentException.class, () -> {
LIC.LIC4(points.length, points, p);
});
}

@Test
void LIC4_false_five_consecutive_points_too_few_quadrants() {
void LIC4_throws_on_too_few_quadrants() {
/*
* Contract: LIC4 is false when the are not Q_PTS number of consecutive points that are contained in more than QUADS quadrants.
Set Q_PTS=5, QUADS=2, with an array of five points that are contained in two quadrants.
Expand Down Expand Up @@ -428,6 +451,22 @@ void LIC5_false_two_consecutive_points_x_difference_larger_than_zero() {
assertFalse(LIC.LIC5(points.length, points, p));
}

@Test
void LIC5_throws_on_too_few_points() {
/*
* Contract: LIC5 needs at least two points to evaluate.
* Use only 1 point.
*/
Parameters p = new Parameters();

Point[] points = new Point[] {
new Point(0, 0)
};
assertThrows(IllegalArgumentException.class, () -> {
LIC.LIC5(points.length, points, p);
});
}

@Test
public void LIC6_false_with_points_too_close() {
/*
Expand Down Expand Up @@ -1316,10 +1355,10 @@ void LIC14_false_too_few_points() {
}

@Test
void LIC14_false_on_bad_input() {
void LIC14_false_on_too_few_points() {
/*
* Contract: LIC14 is false when NUMPOINTS < 5
* Use 4 points to test.
* Use 4 points to test, with otherwise correct parameter setup.
*/
Parameters p = new Parameters();
p.E_PTS = 1;
Expand All @@ -1336,4 +1375,83 @@ void LIC14_false_on_bad_input() {

assertFalse(LIC.LIC14(points.length, points, p));
}

@Test
void LIC14_throws_on_negative_area() {
/*
* Contract: Negative area is not a correct input.
* Set negative areas, with otherwise correct parameters and point setup.
*/
Parameters p = new Parameters();
p.E_PTS = 1;
p.F_PTS = 1;
p.AREA1 = -0.9;
p.AREA2 = -0.5;

Point[] points = new Point[]{
new Point(0,0),
new Point(2,0),
new Point(1,2),
new Point(2.5,1),
new Point(1,0),
new Point(2.5,0)
};

assertThrows(IllegalArgumentException.class, () -> {
LIC.LIC14(points.length, points, p);
});
}

@Test
void LIC14_throws_on_too_large_E_PTS_and_F_PTS() {
/*
* Contract: We require a minimum of E_PTS+F_PTS+3 points to evaluate LIC14.
* Set E_PTS=F_PTS=2, which requires a minimum of 7 points to evaluate, use
* 6 points. Otherwise use correct parameters and point setup.
*/
Parameters p = new Parameters();
p.E_PTS = 2;
p.F_PTS = 2;
p.AREA1 = 0.9;
p.AREA2 = 0.5;

Point[] points = new Point[]{
new Point(0,0),
new Point(2,0),
new Point(1,2),
new Point(2.5,1),
new Point(1,0),
new Point(2.5,0)
};

assertThrows(IllegalArgumentException.class, () -> {
LIC.LIC14(points.length, points, p);
});
}

@Test
void LIC14_throws_on_too_small_E_PTS_and_F_PTS() {
/*
* Contract: E_PTS >= 1 AND F_PTS >= 1.
* Set E_PTS=F_PTS=0, with otherwise correct parameters and point setup.
*/
Parameters p = new Parameters();
p.E_PTS = 0;
p.F_PTS = 0;
p.AREA1 = 0.9;
p.AREA2 = 0.5;

Point[] points = new Point[]{
new Point(0,0),
new Point(2,0),
new Point(1,2),
new Point(2.5,1),
new Point(1,0),
new Point(2.5,0)
};

assertThrows(IllegalArgumentException.class, () -> {
LIC.LIC14(points.length, points, p);
});
}
}