-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestPlanetConstructor.java
76 lines (66 loc) · 2.65 KB
/
TestPlanetConstructor.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
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
/**
* Tests the Planet constructor.
*/
public class TestPlanetConstructor {
/**
* Tests the Planet constructor to make sure it's working correctly.
*/
public static void main(String[] args) {
checkPlanetConstructor();
}
/**
* 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
*/
private static void checkEquals(double expected, double actual, String label) {
if (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 whether or not two Strings are equal and prints the result.
* @param expected Expected String
* @param actual String received
* @param label Label for the 'test' case
*/
private static void checkStringEquals(String expected, String actual, String label) {
if (expected.equals(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 Planet constructors to make sure they are setting instance
* variables correctly.
*/
private static void checkPlanetConstructor() {
System.out.println("Checking first Planet constructor...");
double xxPos = 1.0,
yyPos = 2.0,
xxVel = 3.0,
yyVel = 4.0,
mass = 5.0;
String imgFileName = "jupiter.gif";
Planet p = new Planet(xxPos, yyPos, xxVel, yyVel, mass, imgFileName);
checkEquals(xxPos, p.xxPos, "xxPos");
checkEquals(yyPos, p.yyPos, "yyPos");
checkEquals(xxVel ,p.xxVel, "xxVel");
checkEquals(yyVel, p.yyVel, "yyVel");
checkEquals(mass, p.mass, "mass");
checkStringEquals(imgFileName, p.imgFileName, "path to image");
System.out.println("Checking second Planet constructor...");
Planet pCopy = new Planet(p);
checkEquals(p.xxPos, pCopy.xxPos, "xxPos");
checkEquals(p.yyPos, pCopy.yyPos, "yyPos");
checkEquals(p.xxVel, pCopy.xxVel, "xxVel");
checkEquals(p.yyVel, pCopy.yyVel, "yyVel");
checkEquals(p.mass, pCopy.mass, "mass");
checkStringEquals(p.imgFileName, pCopy.imgFileName, "path to image");
}
}