-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollisionTest.java
More file actions
107 lines (94 loc) · 3.56 KB
/
CollisionTest.java
File metadata and controls
107 lines (94 loc) · 3.56 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
// CollsionTest.java
import java.util.Calendar;
import java.util.Date;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Test class for the Collision class. Simple accessor methods like
* getOwnshipId() and getOthershipId() were not tested, and the constructor was
* also not tested.
*/
public class CollisionTest {
private final Collision testColl1;
private final Collision testColl2;
private static final int MINUTE_OFFSET1 = 50;
private static final int MINUTE_OFFSET2 = 10;
private static final double[] ALL_ZEROS = {0.0,0.0,0.0};
private static final Aircraft SELF1 =
new Aircraft("thisone", ALL_ZEROS, ALL_ZEROS, 0);
private static final Aircraft OTHER1 =
new Aircraft("otherone", ALL_ZEROS, ALL_ZEROS, 0);
private static final Aircraft SELF2 =
new Aircraft("thistwo", ALL_ZEROS, ALL_ZEROS, 0);
private static final Aircraft OTHER2 =
new Aircraft("othertwo", ALL_ZEROS, ALL_ZEROS, 0);
/** xyz velocities */
private static final double[] HEADING1 = {0.0, 550.0, 0.0};
/** latitude, longitude, and altitude */
private static final double[] LOCATION1 = {0.0, 0.0, 1000.0};
/** xyz velocities */
private static final double[] HEADING2 = {-550.0, 0.0, 0.0};
/** latitude, longitude, and altitude */
private static final double[] LOCATION2 = {550.0, 550.0, 1000.0};
private static final Aircraft DOOMED_PLANE1 =
new Aircraft("dp1", HEADING1, LOCATION1, 0);
private static final Aircraft DOOMED_PLANE2 =
new Aircraft("dp2", HEADING2, LOCATION2, 0);
/**
* Set up the test objects
*/
public CollisionTest() {
Calendar cal1 = Calendar.getInstance();
Calendar cal2 = Calendar.getInstance();
cal1.add(Calendar.MINUTE, MINUTE_OFFSET1);
cal2.add(Calendar.MINUTE, MINUTE_OFFSET2);
testColl1 = new Collision(SELF1, OTHER1, cal1.getTime());
testColl2 = new Collision(SELF2, OTHER2, cal2.getTime());
}
/**
* Test of compareTo method, of class Collision.
*/
@Test
public void testCompareTo() {
System.out.println("compareTo");
int result = testColl1.compareTo(testColl2);
assertTrue(result > 0);
}
/**
* Test of getTime method, of class Collision.
* Make sure it is making a new defensive copy each time it is called.
*/
@Test
public void testGetTime() {
System.out.println("getTime");
Date testDate1 = testColl1.getTime();
Date testDate2 = testColl1.getTime();
assertTrue(testDate1 != testDate2);
}
/**
* Test of getLocation method, of class Collision.
*/
@Test
public void testGetLocation() {
System.out.println("getLocation");
double expLatitude = 550.0;
double expLongitude = 550.0;
double expAltitude = 1000.0;
WarningLevelCalculator wlc = new WarningLevelCalculator();
double[] result =
wlc.detectCollision(DOOMED_PLANE1, DOOMED_PLANE2).getLocation();
assertEquals(expLatitude, result[0], Math.ulp(expLatitude));
assertEquals(expLongitude, result[1], Math.ulp(expLongitude));
assertEquals(expAltitude, result[2], Math.ulp(expAltitude));
}
/**
* Test of getRelativeAltitude method, of class Collision.
*/
@Test
public void testGetRelativeAltitude() {
System.out.println("getRelativeAltitude");
double expResult = 0.0;
double result = testColl1.getRelativeAltitude();
assertEquals(expResult, result, Math.ulp(result));
}
}