-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestCalcDistance.java
43 lines (37 loc) · 1.42 KB
/
TestCalcDistance.java
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
/**
* Tests calcDistance
*/
public class TestCalcDistance {
/**
* Tests calcDistance.
*/
public static void main(String[] args) {
checkCalcDistance();
}
/**
* Checks whether or not two Doubles are equal and prints the result.
*
* @param expected Expected double
* @param actual Double received
* @param label Label for the 'test' case
* @param eps Tolerance for the double comparison.
*/
private static void checkEquals(double actual, double expected, String label, double eps) {
if (Math.abs(expected - actual) <= eps * Math.max(expected, actual)) {
System.out.println("PASS: " + label + ": Expected " + expected + " and you gave " + actual);
} else {
System.out.println("FAIL: " + label + ": Expected " + expected + " and you gave " + actual);
}
}
/**
* Checks the Planet class to make sure calcDistance works.
*/
private static void checkCalcDistance() {
System.out.println("Checking calcDistance...");
Planet p1 = new Planet(1.0, 1.0, 3.0, 4.0, 5.0, "jupiter.gif");
Planet p2 = new Planet(2.0, 1.0, 3.0, 4.0, 5.0, "jupiter.gif");
Planet p3 = new Planet(4.0, 5.0, 3.0, 4.0, 5.0, "jupiter.gif");
checkEquals(p1.calcDistance(p2), 1.0, "calcDistance()", 0.01);
checkEquals(p1.calcDistance(p3), 5.0, "calcDistance()", 0.01);
}
}