-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLICTests.java
More file actions
1580 lines (1361 loc) · 50.8 KB
/
LICTests.java
File metadata and controls
1580 lines (1361 loc) · 50.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import org.junit.jupiter.api.Test;
import static java.lang.Math.PI;
import static org.junit.jupiter.api.Assertions.*;
public class LICTests {
@Test
public void testTest() {
// Contract: 2 + 2 should be 4, used to see if the JUnit works
assertEquals(4, 2 + 2);
}
@Test
public void testAngleFunction() {
/* Point.angle(Point p1, Point p2, Point p3) returns the
angle of the 3 points when using the dot product method */
Point p1 = new Point(2, 0);
Point p2 = new Point(1, 0);
Point p3 = new Point(1, 3);
assertEquals(Point.angle(p1, p2, p3), 3.14159 / 2, 0.0001);
assertNotEquals(Point.angle(p1, p2, p3), 3.14159 / 3, 0.0001);
}
@Test
public void testDirectedAngleFunction() {
/* Contract: returns the directed angle formed by three points */
assertAll(
() -> assertEquals(Math.PI / 2.0, // 90°
Point.directedAngle(new Point(1, 0), new Point(0, 0), new Point(0, 1))),
() -> assertEquals(Math.PI, // 180°
Point.directedAngle(new Point(-1, 0), new Point(0, 0), new Point(1, 0))),
() -> assertEquals(3.0 * Math.PI / 2.0, // 270°
Point.directedAngle(new Point(1, 0), new Point(0, 0), new Point(0, -1))),
() -> assertEquals(0.0, // 0°
Point.directedAngle(new Point(1, 0), new Point(0, 0), new Point(2, 0))));
}
@Test
/* Contract: returns the area of a triangle formed by the three points */
public void testTriangleAreaFunction() {
Point p1 = new Point(0.0, 0.0);
Point p2 = new Point(4.0, 0.0);
Point p3 = new Point(0.0, 3.0);
assertEquals(6.0, Point.triangleArea(p1, p2, p3));
}
@Test
/*
* Contract: the function returns the radius of the smallest circle that contains or has the three
* points on its boarder.
*/
public void testCircleRadiusFunction() {
Point p1 = new Point(2, 2);
Point p2 = new Point(8, 2);
Point p3 = new Point(6, 5);
assertEquals(Point.circleRadius(p3, p1, p2), 3.004626062886658, 0.0000001);
}
@Test
/*
* Contract: DistancePointToLine returns the closest distance of the 3rd point p3 to the line created by points
* p1 and p2.
*/
public void testDistancePointToLine() {
Point p1 = new Point(2, 2);
Point p2 = new Point(5, 4);
Point p3 = new Point(4, 2);
assertEquals(1.1094, Point.distancePointToLine(p1, p2, p3), 0.0001);
assertEquals(1.1094, Point.distancePointToLine(p2, p1, p3), 0.0001);
assertEquals(1.7889, Point.distancePointToLine(p2, p3, p1), 0.0001);
assertEquals(3.6056, Point.distancePointToLine(p1, p1, p2), 0.0001);
}
@Test
/*
* Contract: PointQuadrantEvaluation fulfills: There exists at least one set of Q PTS consecutive data points that lie
* in more than QUADS quadrants. Where there is ambiguity as to which quadrant contains a given point, priority of
* decision will be by quadrant number, i.e., I, II, III, IV. For example, the data point (0,0)
* is in quadrant I, the point (-l,0) is in quadrant II, the point (0,-l) is in quadrant III, the point
* (0,1) is in quadrant I and the point (1,0) is in quadrant I.
*/
public void testPointQuadrantEvaluation() {
Point[] quadOne = new Point[]{
new Point(0,0),
new Point(0,1),
new Point(1, 0),
};
Point[] quadTwo = new Point[]{
new Point(-1,0),
new Point(-2,0),
new Point(-2,2)
};
Point[] quadThree = new Point[]{
new Point(0,-1),
new Point(0,-3),
new Point(-2,-3)
};
Point[] quadFour = new Point[]{
new Point(1, -1),
new Point(2, -3)
};
for (Point p : quadOne) {
assertTrue(Point.pointQuadrant(p) == 1);
}
for (Point p : quadTwo) {
assertTrue(Point.pointQuadrant(p) == 2);
}
for (Point p : quadThree) {
assertTrue(Point.pointQuadrant(p) == 3);
}
for (Point p : quadFour) {
assertTrue(Point.pointQuadrant(p) == 4);
}
}
@Test
/*
* Contract: LIC0 is true iff at least two consecutive points exist, with
* distance strictly greater than LENGHT1 between them.
*/
void LIC0_true_with_greater_distance() {
Parameters p = new Parameters();
p.LENGTH1 = 4;
Point[] pts = { new Point(0, 0), new Point(3, 4) };
assertTrue(LIC.LIC0(pts.length, pts, p));
}
@Test
/*
* Contract: LIC0 is false iff no two consecutive points exists, with
* distance strictly greater than LENGHT1 between them.
*/
void LIC0_false_with_smaller_distance() {
Parameters p = new Parameters();
p.LENGTH1 = 20;
Point[] pts = { new Point(0, 0), new Point(3, 4) };
assertFalse(LIC.LIC0(pts.length, pts, p));
}
@Test
// Contract: LIC0 throws an IllegelArgumentException if less than two points exist.
void LIC0_throws_with_too_few_points() {
Parameters p = new Parameters();
p.LENGTH1 = 4;
Point[] pts = { new Point(0, 0) };
assertThrows(IllegalArgumentException.class, () -> LIC.LIC0(pts.length, pts, p));
}
@Test
// Contract: LIC0 throws an IllegelArgumentException if LENGTH1 < 0
void LIC0_throws_with_length_too_small() {
Parameters p = new Parameters();
p.LENGTH1 = -1;
Point[] pts = { new Point(0, 0), new Point(3, 4)};
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
* cannot all be contained within a circle of RADIUS1. If not such 3
* consecutive points exist then LIC1 is false
*/
void testLIC1() {
Point[] points = new Point[] {
new Point(2, 2),
new Point(8, 2),
new Point(6, 5)
};
Parameters p = new Parameters();
p.RADIUS1 = 3;
assertTrue(LIC.LIC1(points.length, points, p));
points[0].x = 2.1;
assertFalse(LIC.LIC1(points.length, points, p));
}
@Test
public void testLIC2() {
/* LIC2 returns true if and only if
there exists at least one set of three consecutive data points which form an angle such that:
angle < (PI−EPSILON)
or
angle > (PI+EPSILON)
The second of the three consecutive points is always the vertex of the angle. If either the first
point or the last point (or both) coincides with the vertex, the angle is undefined and the LIC
is not satisfied by those three points.
(0 ≤ EPSILON < PI) */
Parameters p = new Parameters();
p.EPSILON = 0.01;
Point[] points1 = new Point[] {
new Point(2, 2),
new Point(5, 5)
};
Point[] points2 = new Point[] {
new Point(1, 0),
new Point(1, 0),
new Point(0, 1)
};
Point[] points3 = new Point[] {
new Point(1, 1),
new Point(1, 1),
new Point(-2, -2),
new Point(-2, -1),
new Point(-3, -1)
};
Point[] points4 = new Point[] {
new Point(-2, -2),
new Point(-2, -1),
new Point(-3, -1)
};
//Tests that false is returned when NUMPOINTS < 3
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));
//Tests that true is returned for an input which fulfills the contract
p.EPSILON = (PI / 2) - 0.01;
assertTrue(LIC.LIC2(points3.length, points3, p));
//Tests that false is returned when EPSILON < 0
p.EPSILON = -0.01;
assertThrows(IllegalArgumentException.class, () -> {
LIC.LIC2(points4.length, points4, p);
});
//Tests that false is returned when EPISILON > PI
p.EPSILON = PI + 0.01;
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)
//or angle > (PI+EPSILON)
p.EPSILON = PI / 2 + 0.01;
assertFalse(LIC.LIC2(points4.length, points3, p));
}
// LIC3 Unit Tests
@Test
public void LIC3_true_Triangle_GreaterThan_AREA1() {
/*
* Contract: LIC must return true iff exists at least one set of three
* consecutive points
* that form a triangle with area strictly greater than AREA1.
*/
int numPoints = 3;
Point[] points = new Point[] {
new Point(0.0, 0.0),
new Point(4.0, 0.0),
new Point(0.0, 3.0),
};
Parameters p = new Parameters();
p.AREA1 = 5.0;
assertTrue(LIC.LIC3(numPoints, points, p));
}
@Test
public void LIC3_false_InputInvalid_AREA1_Negative() {
/* Contract: If AREA1 < 0 (invalid input), LIC3 must return false */
int numPoints = 3;
Point[] points = new Point[] {
new Point(0, 0), new Point(4,0), new Point(0,3)
};
Parameters p = new Parameters();
p.AREA1 = -1.0;
assertFalse(LIC.LIC3(numPoints, points, p));
}
@Test
public void LIC3_false_Triangle_NotGreaterThan_AREA1() {
/*
* Contract: If for every three consecutive points, the triangle area
* is NOT strictly greater than AREA1, then LIC3 must return false.
*/
int numPoints = 3;
Point[] points = new Point[] {
new Point(0.0, 0.0),
new Point(2.0, 0.0),
new Point(0.0, 1.0),
};
Parameters p = new Parameters();
p.AREA1 = 2.0;
assertFalse(LIC.LIC3(numPoints, points, p));
}
@Test
public void LIC3_false_InputInvalid_numPoints_Equals_2() {
/*
* Contract: If there are 2 points, LIC3 has no valid triple consecutive points
* to evaluate,
* therefore it must return false.
*/
int numPoints = 2;
Point[] points = new Point[] {
new Point(0.0, 0.0),
new Point(4.0, 0.0),
};
Parameters p = new Parameters();
p.AREA1 = 0.0;
assertFalse(LIC.LIC3(numPoints, points, p));
}
@Test
void LIC4_true_five_consecutive_points_three_quadrants() {
/*
* Contract: LIC4 is true iff there is at least Q_PTS number of consecutive points that are
contained in more than QUADS quadrants.
Q_PTS=5, QUADS=2, with an array of five points that are contained in three quadrants.
*/
Parameters p = new Parameters();
p.Q_PTS = 5;
p.QUADS = 2;
Point[] points = new Point[] {
new Point(0, 0), // Q1
new Point(1, 0), // Q1
new Point(-1, 0), // Q2
new Point(0, -2), // Q3
new Point(4, 3), // Q1
};
assertTrue(LIC.LIC4(points.length, points, p));
}
@Test
void LIC4_throws_on_too_few_points() {
/*
* Contract: LIC4 has constraints: 2 <= Q_PTS <= NUMPOINTS, 1 <= QUADS <= 3.
* 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[] {
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_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.
*/
Parameters p = new Parameters();
p.Q_PTS = 5;
p.QUADS = 2;
Point[] points = new Point[] {
new Point(0, 0), // Q1
new Point(1, 0), // Q1
new Point(-1, 0), // Q2
new Point(-2, 0), // Q2
new Point(4, 3), // Q1
};
assertFalse(LIC.LIC4(points.length, points, p));
}
@Test
void LIC5_true_two_consecutive_points_x_difference_less_than_zero() {
/*
* Contract: LIC5 is true iff there exists at least one pair of consecutive points (i, i+1)
* such that the x coordinate of i is larger than that of i+1: X[i+1]-X[i] < 0.
* The minimum amounts of points (2) is being tested, where the second point has a lower x coordinate
* than the first.
*/
Parameters p = new Parameters();
Point[] points = new Point[] {
new Point(2, 0),
new Point(1, 1),
};
assertTrue(LIC.LIC5(points.length, points, p));
}
@Test
void LIC5_false_two_consecutive_points_x_difference_larger_than_zero() {
/*
* Contract: LIC5 is false iff there is no pair of consecutive points (i, i+1)
* such that the x coordinate of i is larger than that of i+1: X[i+1]-X[i] < 0.
* The minimum amount of points (2) is being tested, where the second point has a higher x coordinate
* than the first.
*/
Parameters p = new Parameters();
Point[] points = new Point[] {
new Point(1, 0),
new Point(2, 1),
};
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() {
/*
* Contract: LIC6 is false iff there exists no set of N PTS consecutive data points such that at
* least one of the points lies a distance greater than DIST from the line joining the first
* and last of these N PTS points.
* All points in this test are within a small area, max distance: 2
*/
Parameters p = new Parameters();
p.N_PTS = 3;
p.DIST = 30;
Point[] points1 = new Point[] {
new Point(0, 0),
new Point(1, 0),
new Point(2, 0),
new Point(1, 1),
new Point(2, 2),
new Point(1, 1),
new Point(0, 3),
new Point(1, 2),
new Point(6, 0)
};
assertFalse(LIC.LIC6(points1.length, points1, p));
}
@Test
public void LIC6_true() {
Parameters p = new Parameters();
p.N_PTS = 3;
p.DIST = 3;
/*
* Contract: LIC6 is true iff there exists at least one set of N PTS consecutive data points such that at
* least one of the points lies a distance greater than DIST from the line joining the first
* and last of these N PTS points.
* Line fron (1,2) - (1,-1) is parallel to the y axis - point (6,0) is 5 away
*/
Point[] points2 = new Point[] {
new Point(0, 0),
new Point(1, 0),
new Point(2, 0),
new Point(1, 1),
new Point(2, 2),
new Point(1, 1),
new Point(0, 3),
new Point(1, 2),
new Point(6, 0),
new Point(1, -1)
};
assertTrue(LIC.LIC6(points2.length, points2, p));
}
@Test
public void LIC6_false_with_too_few_points() {
// Contract: LIC6 is false iff there exist less than 3 points
Parameters p = new Parameters();
p.N_PTS = 3;
p.DIST = 30;
Point[] points3 = new Point[] {
new Point(0, 0),
new Point(1, 0)
};
assertFalse(LIC.LIC6(points3.length, points3, p));
}
@Test
public void LIC6_throws_exception_with_DIST_too_small() {
// Contract: LIC6 throws an exception iff DIST < 0
Parameters p = new Parameters();
p.N_PTS = 3;
p.DIST = -1;
Point[] points3 = new Point[] {
new Point(0, 0),
new Point(1, 0),
new Point(2, 0),
new Point(1, 1),
new Point(2, 2),
new Point(1, 1),
new Point(0, 3),
new Point(1, 2),
new Point(6, 0),
new Point(1, -1)
};
assertThrows(IllegalArgumentException.class, () -> LIC.LIC6(points3.length, points3, p));
}
@Test
public void LIC6_throws_exception_with_too_small_N_PTS() {
// Contract: LIC6 throws an exception iff N_PTS < 3
Parameters p = new Parameters();
p.N_PTS = 2;
p.DIST = 30;
Point[] points2 = new Point[] {
new Point(0, 0),
new Point(1, 0),
new Point(2, 0),
new Point(1, 1),
new Point(2, 2),
new Point(1, 1),
new Point(0, 3),
new Point(1, 2),
new Point(6, 0),
new Point(1, -1)
};
assertThrows(IllegalArgumentException.class, () -> LIC.LIC6(points2.length, points2, p));
}
@Test
public void LIC6_throws_exception_with_N_PTS_bigger_than_numpoints() {
// Contract: LIC6 throws an exception iff N_PTS > numpoints
Parameters p = new Parameters();
p.N_PTS = 20;
p.DIST = 30;
Point[] points2 = new Point[] {
new Point(0, 0),
new Point(1, 0),
new Point(2, 0),
new Point(1, 1),
new Point(2, 2),
new Point(1, 1),
new Point(0, 3),
new Point(1, 2),
new Point(6, 0),
new Point(1, -1)
};
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() {
/*
* Contract: LIC7 is true iff there exists at least on set of 2 consecutive points seperated by K_PTS
* (meaning number of points in between) that are a greater distance apart than LENGTH1
* If not such 2 consecutive points exist then LIC7 is false
*/
Point[] points1 = new Point[] {
new Point(2, 2),
new Point(5, 5),
new Point(8, 2)
};
Point[] points2 = new Point[] {
new Point(2, 2),
new Point(15, 5),
new Point(8, 2),
new Point(5, 5),
new Point(-12, 5)
};
Parameters p = new Parameters();
p.K_PTS = 1;
p.LENGTH1 = 5.9;
assertTrue(LIC.LIC7(points1.length, points1, p));
p.LENGTH1 = 6;
assertFalse(LIC.LIC7(points1.length, points1, p));
p.K_PTS = 2;
p.LENGTH1 = 26;
assertTrue(LIC.LIC7(points2.length, points2, p));
p.LENGTH1 = 27;
assertFalse(LIC.LIC7(points2.length, points2, p));
}
@Test
public void testLIC8() {
/*
* Contract: LIC8 returns true if and only if there exists at least one set of
* three data points
* separated by exactly A PTS and B PTS
* consecutive intervening points, respectively, that cannot be contained within
* or on a circle of
* radius RADIUS1. The condition is not met when NUMPOINTS < 5.
* 1 ≤ A PTS, 1 ≤ B PTS
* A PTS+B PTS ≤ (NUMPOINTS−3)
*/
Point[] points2 = new Point[] {
new Point(0, 10),
new Point(0, 0),
new Point(-10, 0),
new Point(0, -1),
new Point(10, 0)
};
Parameters p = new Parameters();
p.RADIUS1 = 1;
p.A_PTS = 0;
p.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;
assertThrows(IllegalArgumentException.class, () -> {
LIC.LIC8(points2.length, points2, p);
});
// Tests that IllegalArgumentException is thrown when A PTS + B PTS > (NUMPOINTS-3)
p.A_PTS = 2;
p.B_PTS = 1;
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
// consecutive intervening points, respectively, that can be contained within or
// on a circle of
// radius RADIUS1
p.RADIUS1 = 100;
p.A_PTS = 1;
assertFalse(LIC.LIC8(points2.length, points2, p));
Point[] points3 = new Point[] {
new Point(0, 10),
new Point(-10, 0),
new Point(0, 10),
new Point(10, 0),
new Point(0, 10),
};
// Tests that false is returned if there exists at least
// one set of three data points which are not separated by exactly A PTS and B
// PTS
// consecutive intervening points, respectively, that cannot be contained within
// or on a circle of
// radius RADIUS1.
p.RADIUS1 = 1;
assertFalse(LIC.LIC8(points3.length, points3, p));
// Tests that IllegalArgumentException is thrown when RADIUS1 < 0:
p.RADIUS1 = -1;
assertThrows(IllegalArgumentException.class, () -> {
LIC.LIC8(points2.length, points2, p);
});
p.RADIUS1 = 1;
// Tests that true is returned for a valid input
assertTrue(LIC.LIC8(points2.length, points2, p));
}
// LIC9 Unit Tests
@Test
public void LIC9_false_when_numPoint_LessThan_5() {
/* Contract: If numPoints < 5, returns false (invalid input) */
int numPoints = 4;
Point[] points = new Point[] {
new Point(0, 0), new Point(1, 0), new Point(2, 0), new Point(3, 0)
};
Parameters p = new Parameters();
p.C_PTS = 1;
p.D_PTS = 1;
p.EPSILON = 0.1;
assertFalse(LIC.LIC9(numPoints, points, p));
}
@Test
public void LIC9_false_whenC_PTSorD_PTS_Invalid() {
/* Contract: If C_PTS < 1 or D_PTS < 1, LCI9 returns false (invalid input) */
int numPoints = 5;
Point[] points = new Point[] {
new Point(0, 0), new Point(1, 0), new Point(2, 0), new Point(3, 0), new Point(4, 0)
};
Parameters p1 = new Parameters();
p1.C_PTS = 0;
p1.D_PTS = 1;
p1.EPSILON = 0.1;
assertFalse(LIC.LIC9(numPoints, points, p1));
Parameters p2 = new Parameters();
p2.C_PTS = 1;
p2.D_PTS = 0;
p2.EPSILON = 0.1;
assertFalse(LIC.LIC9(numPoints, points, p2));
}
@Test
public void LIC9_false_when_EPSILON_OutOfRange() {
/* Contract: Given EPSILON outside [0, PI), LIC9 must return FALSE */
Point[] points = new Point[] {
new Point(0,0), new Point(1,0), new Point(2,0), new Point(2,1), new Point(3,1)
};
int numPoints = points.length;
/* Case 1: EPSILON < 0 */
Parameters p1 = new Parameters();
p1.C_PTS = 1;
p1.D_PTS = 1;
p1.EPSILON = -0.1;
assertFalse(LIC.LIC9(numPoints, points, p1));
/* Case 2: EPSILON >= 1 */
Parameters p2 = new Parameters();
p2.C_PTS = 1;
p2.D_PTS = 1;
p2.EPSILON = Math.PI;
assertFalse(LIC.LIC9(numPoints, points, p2));
}
@Test
public void LIC9_false_When_C_PTSplusD_PTS_GreaterThan_numPoints_minus_three() {
/*
* Contract: If C_PTS + D_PTS > numPoints - 3, LIC9 returns false (invalid
* input)
*/
int numPoints = 5;
Point[] points = new Point[] {
new Point(0, 0), new Point(1, 0), new Point(2, 0), new Point(3, 0), new Point(4, 0)
};
Parameters p = new Parameters();
p.C_PTS = 2;
p.D_PTS = 1;
p.EPSILON = 0.1;
assertFalse(LIC.LIC9(numPoints, points, p));
}
@Test
public void LIC9_true_When_AngleOutside_PIPlusMinusEpsilon() {
/*
* Contract: LIC9 returns true iff there exists points A,B,C with the required
* spacing
* such that the angle at B is < (PI - EPSILON) or > (PI + EPSILON)
*/
int numPoints = 5;
Point[] points = new Point[] {
new Point(0, 0), // 0 = A
new Point(999, 999), // 1 = C_PTS
new Point(1, 0), // 2 = B
new Point(999, 999), // 3 = D_PTS
new Point(1, 1) // 4 = C
};
Parameters p = new Parameters();
p.C_PTS = 1;
p.D_PTS = 1;
p.EPSILON = 0.1;
assertTrue(LIC.LIC9(numPoints, points, p));
}
@Test
public void LIC9_false_AllEvaluatingAngles_AreWithin_PIPlusMinusEpsilon() {
/*
* Contract: If for every valid triple A,B,C (with required spacing),
* the angle at B lies within [PI - EPSILON, PI + EPSILON], LIC9 returns false
*/
int numPoints = 5;
Point[] points = new Point[] {
new Point(0, 0), // 0 = A
new Point(111, 111), // 1 = C_PTS
new Point(1, 0), // 2 = B
new Point(222, 222), // 3 = D_PTS
new Point(2, 0) // 4 = C
};
Parameters p = new Parameters();
p.C_PTS = 1;
p.D_PTS = 1;
p.EPSILON = 0.01;
assertFalse(LIC.LIC9(numPoints, points, p));
}
@Test
public void LIC9_false_when_SkippedTriples_Where_A_equals_B_or_C_equals_B_IfNoOtherTriplesSatisfies() {
/*
* Contract: f A==B or C==B, the angle is undefined and that triple is ignored.
* If no other valid triple satisfies the angle condition, LIC9 returns false.
*/
int numPoints = 5;
Point[] points = new Point[] {
new Point(1, 0), // 0 = A
new Point(0, 0), // 1 = C_PTS
new Point(1, 0), // 2 = B
new Point(0, 0), // 3 = D_PTS
new Point(2, 0) // 4 = C
};
Parameters p = new Parameters();
p.C_PTS = 1;
p.D_PTS = 1;
p.EPSILON = 0.1;
assertFalse(LIC.LIC9(numPoints, points, p));
}
@Test
public void LIC10_false_when_too_few_points() {
// Contract: LIC10 is false if less than 5 points are being passed
Point [] points = new Point[] {
new Point(1, 0),
new Point(0, 0),
new Point(1, 0)
};
Parameters p = new Parameters();
p.E_PTS = 2;
p.F_PTS = 2;
p.AREA1 = 10;
assertFalse(LIC.LIC10(3, points, p));
}
@Test
public void LIC10_throws_exception_when_area_too_small() {
// Contract: LIC10 throws exception if the area is smaller than 0
Point [] points = new Point[] {
new Point(1, 0),
new Point(0, 0),
new Point(1, 0),
new Point(1, 0),
new Point(0, 0),
new Point(0, 0),
new Point(1, 0),
new Point(1, 0),
new Point(0, 0)
};
Parameters p = new Parameters();
p.E_PTS = 2;
p.F_PTS = 2;
p.AREA1 = -1;
assertThrows(IllegalArgumentException.class, () -> LIC.LIC10(points.length, points, p));
}
@Test
public void LIC10_throws_exception_when_EPTS_too_small() {
// Contract: LIC10 throws exception if the EPTS < 1
Point [] points = new Point[] {
new Point(1, 0),
new Point(0, 0),
new Point(1, 0),
new Point(1, 0),
new Point(0, 0),
new Point(0, 0),
new Point(1, 0),
new Point(1, 0),
new Point(0, 0)
};
Parameters p = new Parameters();
p.E_PTS = 0;
p.F_PTS = 2;
p.AREA1 = 4;
assertThrows(IllegalArgumentException.class, () -> LIC.LIC10(points.length, points, p));
}
@Test
public void LIC10_throws_exception_when_FPTS_too_small() {
// Contract: LIC10 throws exception if FPTS < 1
Point [] points = new Point[] {
new Point(1, 0),
new Point(0, 0),
new Point(1, 0),
new Point(1, 0),