import org.junit.jupiter.api.Test; import java.util.HashSet; import static org.junit.jupiter.api.Assertions.*; public class Aufgabe6Test { @Test public void testEP2() { NamedBody sun1, mercury1, venus1, earth1, moon1, mars1, deimos1, phobos1, vesta1, pallas1, hygiea1, ceres1; // 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); // check basic functions of 'MassiveForceHashMap' MassiveForceTreeMap map = new MassiveForceTreeMap(); 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 HashSet set1 = new HashSet<>(); set1.add(sun1); set1.add(mercury1); set1.add(venus1); set1.add(earth1); set1.add(moon1); set1.add(mars1); set1.add(deimos1); set1.add(phobos1); set1.add(vesta1); set1.add(pallas1); set1.add(hygiea1); set1.add(ceres1); assertTrue(map.toString().contains("Mars")); assertTrue(map.toString().contains("Deimos")); assertTrue(map.toString().contains("Moon")); assertTrue(map.toString().contains("Earth")); assertEquals(12, map.getKeys().size()); assertTrue(map.getKeys().contains(mars1)); assertTrue(map.getKeys().contains(new NamedBody("Mars", 6.41712E23, new Vector3(0, 0, 0), new Vector3(0, 0, 0)))); assertFalse(map.getKeys().contains(new Body(6.41712E23, new Vector3(0, 0, 0), new Vector3(0, 0, 0)))); HashSet set2 = new HashSet<>(); for (Massive m : map.getKeys()) { set2.add(m); } assertEquals(set1, set2); MassiveLinkedList list = map.getKeys().toList(); while (list.size() > 0) { set1.remove(list.pollLast()); } assertTrue(set1.isEmpty()); map.getKeys().remove(mars1); assertFalse(map.containsKey(mars1)); assertEquals(11, map.getKeys().size()); map.getKeys().clear(); assertEquals(0, map.getKeys().size()); NamedBodyForcePair sun2, mercury2, venus2, earth2, moon2, mars2, deimos2, phobos2, vesta2, pallas2, hygiea2, ceres2; //test classes NamedBody and MassiveForceHashMap // create 12 named bodies // create the same 12 named body-force pairs sun2 = new NamedBodyForcePair(SolSystem4.SUN_NAMED); earth2 = new NamedBodyForcePair(SolSystem4.EARTH_NAMED); moon2 = new NamedBodyForcePair(SolSystem4.MOON_NAMED); mars2 = new NamedBodyForcePair(SolSystem4.MARS_NAMED); deimos2 = new NamedBodyForcePair(SolSystem4.DEIMOS_NAMED); phobos2 = new NamedBodyForcePair(SolSystem4.PHOBOS_NAMED); mercury2 = new NamedBodyForcePair(SolSystem4.MERCURY_NAMED); venus2 = new NamedBodyForcePair(SolSystem4.VENUS_NAMED); vesta2 = new NamedBodyForcePair(SolSystem4.VESTA_NAMED); pallas2 = new NamedBodyForcePair(SolSystem4.PALLAS_NAMED); hygiea2 = new NamedBodyForcePair(SolSystem4.HYGIEA_NAMED); ceres2 = new NamedBodyForcePair(SolSystem4.CERES_NAMED); CosmicSystem earthSystem = new HierarchicalSystem(earth2, moon2); CosmicSystem marsSystem = new HierarchicalSystem(mars2, deimos2, phobos2); HierarchicalSystem solarSystem = new HierarchicalSystem(sun2, mercury2, venus2, earthSystem, marsSystem, vesta2, pallas2, hygiea2, ceres2); int count = 0; for (Massive b : solarSystem) { count++; } assertEquals(12, count); } }