-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestCalcForceExertedBy.java
45 lines (38 loc) · 1.52 KB
/
TestCalcForceExertedBy.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
44
45
import java.math.*;
/**
* Tests calcForceExertedBy
*/
public class TestCalcForceExertedBy {
/**
* Tests calcForceExertedBy.
*/
public static void main(String[] args) {
checkCalcForceExertedBy();
}
/**
* 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 calcForceExertedBy works.
*/
private static void checkCalcForceExertedBy() {
System.out.println("Checking calcForceExertedBy...");
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, 4e11, "jupiter.gif");
Planet p3 = new Planet(4.0, 5.0, 3.0, 4.0, 5.0, "jupiter.gif");
checkEquals(p1.calcForceExertedBy(p2), 133.4, "calcForceExertedBy()", 0.01);
checkEquals(p1.calcForceExertedBy(p3), 6.67e-11, "calcForceExertedBy()", 0.01);
}
}