import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; public class Aufgabe5Test { @Test public void testEP2() { //test classes NamedBody and MassiveForceHashMap // create 12 named bodies NamedBody sun1, mercury1, venus1, earth1, moon1, mars1, deimos1, phobos1, vesta1, pallas1, hygiea1, ceres1; // create a nameless body Body earth2 = new Body(SolSystem4.EARTH); // create the same 12 named body-force pairs sun1 = new NamedBody(SolSystem4.SUN_NAMED); earth1 = new NamedBody(SolSystem4.EARTH_NAMED); moon1 = new NamedBody(SolSystem4.MOON_NAMED); mars1 = new NamedBody(SolSystem4.MARS_NAMED); deimos1 = new NamedBody(SolSystem4.DEIMOS_NAMED); phobos1 = new NamedBody(SolSystem4.PHOBOS_NAMED); mercury1 = new NamedBody(SolSystem4.MERCURY_NAMED); venus1 = new NamedBody(SolSystem4.VENUS_NAMED); vesta1 = new NamedBody(SolSystem4.VESTA_NAMED); pallas1 = new NamedBody(SolSystem4.PALLAS_NAMED); hygiea1 = new NamedBody(SolSystem4.HYGIEA_NAMED); ceres1 = new NamedBody(SolSystem4.CERES_NAMED); NamedBody sun2 = new NamedBody("Sun", 1.9895E30, new Vector3(0.1, 0.0, 0.0), new Vector3(0.0, 0.0, 0.0)); NamedBody earth3 = new NamedBody("Earth", 1, new Vector3(0, 0, 0), new Vector3(0, 0, 0)); assertEquals(sun1, sun2); assertEquals(sun2.hashCode(), sun1.hashCode()); assertEquals(earth1, earth3); assertEquals(earth3.hashCode(), earth1.hashCode()); // check basic functions of 'MassiveForceHashMap' MassiveForceHashMap map = new MassiveForceHashMap(); map.put(sun1, new Vector3(0, 0, 0)); map.put(mercury1, new Vector3(0, 0, 0)); map.put(venus1, new Vector3(0, 0, 0)); map.put(earth1, new Vector3(0, 0, 0)); map.put(moon1, new Vector3(0, 0, 0)); map.put(mars1, new Vector3(0, 0, 0)); map.put(deimos1, new Vector3(0, 0, 0)); map.put(phobos1, new Vector3(0, 0, 0)); map.put(vesta1, new Vector3(0, 0, 0)); map.put(pallas1, new Vector3(0, 0, 0)); map.put(hygiea1, new Vector3(0, 0, 0)); map.put(ceres1, new Vector3(0, 0, 0)); map.put(mars1, new Vector3(0, 0, 0)); // inserted twice assertEquals(12, map.keyList().size()); assertTrue(map.toString().contains("Mars")); assertTrue(map.toString().contains("Deimos")); assertTrue(map.toString().contains("Moon")); assertTrue(map.toString().contains("Earth")); MassiveLinkedList bl = map.keyList(); boolean allThere = true; while (bl.size() > 0) { allThere &= map.containsKey(bl.pollFirst()); } assertTrue(allThere); assertFalse(map.containsKey(new Body(0, new Vector3(0, 0, 0), new Vector3(0, 0, 0)))); assertFalse(map.containsKey(new NamedBody("Omuamua", 0, new Vector3(0, 0, 0), new Vector3(0, 0, 0)))); int hashCode1 = map.hashCode(); Vector3 f = new Vector3(5, 5, 5); map.put(earth3, f); assertEquals(f, map.get(earth1)); assertNull(map.get(earth2)); int hashCode2 = map.hashCode(); assertEquals(map, map); assertEquals(hashCode2, map.hashCode()); assertNotEquals(hashCode1, hashCode2); } @Test public void testDelKey() { MassiveForceHashMap map = new MassiveForceHashMap(); NamedBody sun1 = new NamedBody(SolSystem4.SUN_NAMED); NamedBody earth1 = new NamedBody(SolSystem4.EARTH_NAMED); NamedBody moon1 = new NamedBody(SolSystem4.MOON_NAMED); map.put(sun1, new Vector3()); map.put(earth1, new Vector3()); map.put(moon1, new Vector3()); assertNotNull(map.get(sun1)); assertNotNull(map.delete(sun1)); assertNull(map.get(sun1)); assertNull(map.delete(sun1)); } }