Refactor tests
This commit is contained in:
@ -1,78 +1,51 @@
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class Aufgabe2Test {
|
||||
|
||||
public static void main(String[] args) {
|
||||
//test classes BodyQueue and BodyForceMap
|
||||
|
||||
@Test
|
||||
public void testEP2() {
|
||||
// create three bodies
|
||||
Body sun = new Body(1.989e30,new Vector3(0,0,0),new Vector3(0,0,0));
|
||||
Body earth = new Body(5.972e24,new Vector3(-1.394555e11,5.103346e10,0),new Vector3(-10308.53,-28169.38,0));
|
||||
Body mercury = new Body(3.301e23,new Vector3(-5.439054e10,9.394878e9,0),new Vector3(-17117.83,-46297.48,-1925.57));
|
||||
|
||||
Body sun = new Body(SolSystem.SUN);
|
||||
Body earth = new Body(SolSystem.EARTH);
|
||||
Body mercury = new Body(SolSystem.MERCURY);
|
||||
|
||||
// check basic functions of 'BodyQueue'
|
||||
System.out.println("Test1:");
|
||||
|
||||
BodyQueue bq = new BodyQueue(2);
|
||||
bq.add(mercury);
|
||||
bq.add(sun);
|
||||
bq.add(earth);
|
||||
testValue(bq.size(), 3);
|
||||
assertEquals(3, bq.size());
|
||||
|
||||
testValue(bq.poll(), mercury);
|
||||
testValue(bq.poll(), sun);
|
||||
testValue(bq.poll(), earth);
|
||||
assertEquals(mercury, bq.poll());
|
||||
assertEquals(sun, bq.poll());
|
||||
assertEquals(earth, bq.poll());
|
||||
|
||||
testValue(bq.size(), 0);
|
||||
assertEquals(0, bq.size());
|
||||
|
||||
bq.add(mercury);
|
||||
bq.add(sun);
|
||||
testValue(bq.size(), 2);
|
||||
assertEquals(2, bq.size());
|
||||
|
||||
// check constructor of 'BodyQueue'
|
||||
BodyQueue bqCopy = new BodyQueue(bq);
|
||||
testComparison(bq, bqCopy, false);
|
||||
testComparison(bq.poll(), bqCopy.poll(), true);
|
||||
assertNotEquals(bq, bqCopy);
|
||||
assertEquals(bqCopy.poll(), bq.poll());
|
||||
bq.add(earth);
|
||||
testValue(bq.size(), 2);
|
||||
testValue(bqCopy.size(), 1);
|
||||
assertEquals(2, bq.size());
|
||||
assertEquals(1, bqCopy.size());
|
||||
|
||||
// check basic functions of 'BodyForceMap'
|
||||
System.out.println("Test2:");
|
||||
BodyForceMap bfm = new BodyForceMap(5);
|
||||
bfm.put(earth, earth.gravitationalForce(sun));
|
||||
bfm.put(sun, sun.gravitationalForce(earth));
|
||||
|
||||
testValue(bfm.get(earth).distanceTo(earth.gravitationalForce(sun)),0);
|
||||
testValue(bfm.get(sun).distanceTo(sun.gravitationalForce(earth)),0);
|
||||
assertEquals(0, bfm.get(earth).distanceTo(earth.gravitationalForce(sun)));
|
||||
assertEquals(0, bfm.get(sun).distanceTo(sun.gravitationalForce(earth)));
|
||||
|
||||
bfm.put(earth, new Vector3(0,0,0));
|
||||
testValue(bfm.get(earth).distanceTo(new Vector3(0,0,0)), 0);
|
||||
testValue(bfm.get(mercury),null);
|
||||
}
|
||||
|
||||
public static void testComparison(Object first, Object second, boolean expected) {
|
||||
boolean real = first == second;
|
||||
|
||||
if (real == expected) {
|
||||
System.out.println("Successful comparison");
|
||||
} else {
|
||||
System.out.println("Comparison NOT successful! Expected value: " + expected + " / Given value: " + real);
|
||||
}
|
||||
}
|
||||
|
||||
public static void testValue(Object given, Object expected) {
|
||||
if (given == expected) {
|
||||
System.out.println("Successful test");
|
||||
} else {
|
||||
System.out.println("Test NOT successful! Expected value: " + expected + " / Given value: " + given);
|
||||
}
|
||||
}
|
||||
|
||||
public static void testValue(double given, double expected) {
|
||||
if (given < expected + (expected+1)/1e12 && given > expected - (expected+1)/1e12) {
|
||||
System.out.println("Successful test");
|
||||
} else {
|
||||
System.out.println("Test NOT successful! Expected value: " + expected + " / Given value: " + given);
|
||||
}
|
||||
bfm.put(earth, new Vector3(0, 0, 0));
|
||||
assertEquals(0, bfm.get(earth).distanceTo(new Vector3(0, 0, 0)));
|
||||
assertNull(bfm.get(mercury));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user