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
38 changes: 31 additions & 7 deletions src/main/java/LIC.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ public static boolean LIC0(int numPoints, Point[] points, Parameters p) throws I
return false;
}

public static boolean LIC1(int numPoints, Point[] points, Parameters p) {
if (numPoints < 3 || p.RADIUS1 < 0)
return false;
public static boolean LIC1(int numPoints, Point[] points, Parameters p) throws IllegalArgumentException {
if (p.RADIUS1 < 0) {
throw new IllegalArgumentException();
}

if (numPoints < 3) return false;


for (int i = 0; i < numPoints - 2; i++) {
if (Point.circleRadius(points[i], points[i + 1], points[i + 2]) > p.RADIUS1)
return true;
Expand Down Expand Up @@ -107,8 +112,16 @@ public static boolean LIC6(int numPoints, Point[] points, Parameters p) throws I
return false;
}

public static boolean LIC7(int numPoints, Point[] points, Parameters p) {
if (numPoints < 3 || p.K_PTS < 1 || p.K_PTS > numPoints - 2 || p.LENGTH1 < 0) return false;
public static boolean LIC7(int numPoints, Point[] points, Parameters p) throws IllegalArgumentException {

if (p.K_PTS < 1 || p.K_PTS > numPoints - 2) {
throw new IllegalArgumentException();
}
if (p.LENGTH1 < 0) {
throw new IllegalArgumentException();
}

if (numPoints < 3) return false;

for (int i = 0; i < numPoints - p.K_PTS - 1; i++) {
if (Point.distance(points[i], points[i + p.K_PTS + 1]) > p.LENGTH1)
Expand Down Expand Up @@ -210,8 +223,19 @@ public static boolean LIC12(int numPoints, Point[] points , Parameters p){
return false;
}

public static boolean LIC13(int numPoints, Point[] points, Parameters p) {
if (numPoints < 5 || p.RADIUS2 < 0 || p.RADIUS1 < 0 || p.A_PTS < 1 || p.B_PTS < 1) return false;
public static boolean LIC13(int numPoints, Point[] points, Parameters p) throws IllegalArgumentException {
if (p.RADIUS2 < 0) {
throw new IllegalArgumentException();
}
if (p.RADIUS1 < 0) {
throw new IllegalArgumentException();
}
if (p.A_PTS < 1 || p.B_PTS < 1 || p.A_PTS + p.B_PTS > numPoints - 3) {
throw new IllegalArgumentException();
}


if (numPoints < 5) return false;

boolean not_contained_flag = false, contained_flag = false;
for (int i = 0; i < numPoints - p.A_PTS - p.B_PTS - 2; i++) {
Expand Down
203 changes: 165 additions & 38 deletions src/test/java/LICTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,26 @@ void LIC0_throws_with_length_too_small() {
assertThrows(IllegalArgumentException.class, () -> LIC.LIC0(pts.length, pts, p));
}


@Test
/*
* Contract: Method throws exception due to RADIUS1 being invalid since it is negative
*/
void testLIC1InvalidRADIUS1() {
Point[] points = new Point[] {
new Point(2, 2),
new Point(8, 2),
new Point(6, 5)
};
Parameters p = new Parameters();
p.RADIUS1 = -1;

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

}

@Test
/*
* Contract: LIC1 is true iff there exists 3 consecutive points that
Expand All @@ -176,13 +196,8 @@ void testLIC1() {
new Point(6, 5)
};
Parameters p = new Parameters();

p.RADIUS1 = -1;
assertFalse(LIC.LIC1(points.length, points, p));
p.RADIUS1 = 3;

assertFalse(LIC.LIC1(0, new Point[]{}, p));

assertTrue(LIC.LIC1(points.length, points, p));
points[0].x = 2.1;
assertFalse(LIC.LIC1(points.length, points, p));
Expand Down Expand Up @@ -556,6 +571,46 @@ public void LIC6_throws_exception_with_N_PTS_bigger_than_numpoints() {
assertThrows(IllegalArgumentException.class, () -> LIC.LIC6(points2.length, points2, p));
}

@Test
public void testLIC7InvalidKPTS() {
/*
* Contract: Method throws exception due to K_PTS being invalid since it is sat 0
*/
Point[] points = new Point[] {
new Point(2, 2),
new Point(5, 5),
new Point(8, 2)
};

Parameters p = new Parameters();
p.LENGTH1 = 1;
p.K_PTS = 0;

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

@Test
public void testLIC7InvalidLENGTH1() {
/*
* Contract: Method throws exception due to LENGTH1 being invalid since it is negtive
*/
Point[] points = new Point[] {
new Point(2, 2),
new Point(5, 5),
new Point(8, 2)
};

Parameters p = new Parameters();
p.LENGTH1 = -1;
p.K_PTS = 1;

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

@Test
public void testLIC7() {
/*
Expand All @@ -577,18 +632,9 @@ public void testLIC7() {
new Point(-12, 5)
};


Parameters p = new Parameters();
p.LENGTH1 = 1;
p.K_PTS = 0;
assertFalse(LIC.LIC7(points1.length, points1, p));
p.K_PTS = 1;

assertFalse(LIC.LIC7(0, new Point[]{}, p));

p.LENGTH1 = -1;
assertFalse(LIC.LIC7(points1.length, points1, p));


p.LENGTH1 = 5.9;
assertTrue(LIC.LIC7(points1.length, points1, p));
p.LENGTH1 = 6;
Expand Down Expand Up @@ -1181,6 +1227,110 @@ public void LIC12_false_when_LENGTH1_is_Negative() {
assertFalse(LIC.LIC12(numPoints, points, p));
}

@Test
public void testLIC13InvalidAPTS() {
/*
* Contract: Method throws exception due to A_PTS being invalid since it is sat 0
*/
Point[] points = new Point[] {
new Point(2, 2),
new Point(99, 99),
new Point(8, 2),
new Point(100, 100),
new Point(6, 5),
new Point(101, 101),
new Point(5, 11)
};

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

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

@Test
public void testLIC13InvalidBPTS() {
/*
* Contract: Method throws exception due to B_PTS being invalid since it is sat 0
*/
Point[] points = new Point[] {
new Point(2, 2),
new Point(99, 99),
new Point(8, 2),
new Point(100, 100),
new Point(6, 5),
new Point(101, 101),
new Point(5, 11)
};

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

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

@Test
public void testLIC13InvalidRADIUS1() {
/*
* Contract: Method throws exception due to RADIUS1 being invalid since it is negative
*/
Point[] points = new Point[] {
new Point(2, 2),
new Point(99, 99),
new Point(8, 2),
new Point(100, 100),
new Point(6, 5),
new Point(101, 101),
new Point(5, 11)
};

Parameters p = new Parameters();
p.RADIUS1 = -3;
p.A_PTS = 1;
p.B_PTS = 1;
p.RADIUS2 = 1.5;

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

@Test
public void testLIC13InvalidRADIUS2() {
/*
* Contract: Method throws exception due to RADIUS2 being invalid since it is negative
*/
Point[] points = new Point[] {
new Point(2, 2),
new Point(99, 99),
new Point(8, 2),
new Point(100, 100),
new Point(6, 5),
new Point(101, 101),
new Point(5, 11)
};

Parameters p = new Parameters();
p.RADIUS1 = 3;
p.A_PTS = 1;
p.B_PTS = 1;
p.RADIUS2 = -1.5;

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

@Test
public void testLIC13() {
/*
Expand All @@ -1207,29 +1357,6 @@ public void testLIC13() {
System.out.println(radius3);

Parameters p = new Parameters();
p.RADIUS1 = -1;
p.A_PTS = 1;
p.B_PTS = 1;
p.RADIUS2 = 1.5;

assertFalse(LIC.LIC13(points.length, points, p));
p.RADIUS1 = 3;

p.A_PTS = 0;
assertFalse(LIC.LIC13(points.length, points, p));
p.A_PTS = 1;

p.B_PTS = 0;
assertFalse(LIC.LIC13(points.length, points, p));
p.B_PTS = 1;

p.RADIUS2 = -1;
assertFalse(LIC.LIC13(points.length, points, p));
p.RADIUS2 = 1.5;

assertFalse(LIC.LIC13(0, new Point[]{}, p));


p.RADIUS1 = 3;
p.A_PTS = 1;
p.B_PTS = 1;
Expand Down