-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestReadRadius.java
38 lines (35 loc) · 1.39 KB
/
TestReadRadius.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
/**
* Tests Nbody.readRadius. Reads in ./data/planets.txt and checks to see that
* result matches hard coded value.
*/
public class TestReadRadius {
/**
* 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 NBody.readRadius() method.
*/
private static void checkReadRadius() {
System.out.println("Checking readRadius...");
String planetsTxtPath = "./data/planets.txt";
/* If the following line fails to compile, you probably need to make
* a certain method static! */
double actualOutput = NBody.readRadius(planetsTxtPath);
checkEquals(actualOutput, 2.50E11, "readRadius()", 0.01);
}
public static void main(String[] args) {
checkReadRadius();
}
}