import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

public class Aufgabe3Test {

    @Test
    public void testEP2() {
        // create five bodies
        Body sun = new Body(SolSystem.SUN);
        Body earth = new Body(SolSystem.EARTH);
        Body mercury = new Body(SolSystem.MERCURY);
        Body venus = new Body(SolSystem.VENUS);
        Body mars = new Body(SolSystem.MARS);

        // check basic functions of 'BodyLinkedList'
        BodyLinkedList bl = new BodyLinkedList();

        bl.addLast(mercury);
        bl.addLast(sun);
        bl.addLast(earth);
        assertEquals(3, bl.size());

        assertEquals(mercury, bl.getFirst());
        assertEquals(earth, bl.getLast());

        assertEquals(mercury, bl.get(0));
        assertEquals(sun, bl.get(1));
        assertEquals(earth, bl.get(2));

        assertEquals(2, bl.indexOf(earth));
        assertEquals(1, bl.indexOf(sun));
        assertEquals(0, bl.indexOf(mercury));

        assertEquals(mercury, bl.pollFirst());
        assertEquals(earth, bl.pollLast());
        assertEquals(sun, bl.pollFirst());

        assertEquals(0, bl.size());
        assertNull(bl.getFirst());

        bl.addFirst(earth);
        bl.addFirst(venus);
        bl.addFirst(sun);
        bl.add(1, mercury);
        bl.add(4, mars);

        assertEquals(5, bl.size());

        assertEquals(sun, bl.get(0));
        assertEquals(mercury, bl.get(1));
        assertEquals(venus, bl.get(2));
        assertEquals(earth, bl.get(3));
        assertEquals(mars, bl.get(4));

        // check constructor of 'BodyLinkedList'
        BodyLinkedList blCopy = new BodyLinkedList(bl);
        assertNotEquals(bl, blCopy);
        assertEquals(blCopy.pollFirst(), bl.pollFirst());
        bl.addFirst(sun);
        assertEquals(5, bl.size());
        assertEquals(4, blCopy.size());

        // check basic functions of 'BodyForceTreeMap'
        BodyForceTreeMap bfm = new BodyForceTreeMap();
        bfm.put(earth, earth.gravitationalForce(sun));
        bfm.put(sun, sun.gravitationalForce(earth).plus(sun.gravitationalForce(venus)));
        bfm.put(venus, venus.gravitationalForce(sun));
        bfm.put(mars, mars.gravitationalForce(sun));
        bfm.put(mercury, mercury.gravitationalForce(sun));

        assertEquals(0, bfm.get(earth).distanceTo(earth.gravitationalForce(sun)));
        assertEquals(0, bfm.get(sun).distanceTo(sun.gravitationalForce(earth).plus(sun.gravitationalForce(venus))));

        assertEquals(0, bfm.put(earth, new Vector3(0, 0, 0)).distanceTo(earth.gravitationalForce(sun)));
        assertEquals(0, bfm.get(mercury).distanceTo(mercury.gravitationalForce(sun)));
        assertEquals(mercury.gravitationalForce(sun), bfm.get(mercury));
    }
}
