package seng302.Model;


import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

/**
 * Created by esa46 on 22/03/17.
 */
public class BoatTest {


    private GPSCoordinate ORIGIN_COORDS;
    private Boat TEST_BOAT;

    @Before
    public void setUp() {
        ORIGIN_COORDS = new GPSCoordinate(0, 0);
        TEST_BOAT = new Boat(1, "Test", "tt", new Polars());
        TEST_BOAT.setCurrentPosition(ORIGIN_COORDS);
    }

    @Test
    public void calculateDueNorthAzimuthReturns0() {

        CompoundMark startMarker = new CompoundMark(new Mark(1, "test origin 1", ORIGIN_COORDS));
        CompoundMark endMarker = new CompoundMark(new Mark(2, "test mark 2", new GPSCoordinate(50, 0)));
        Leg start = new Leg("Start", startMarker, endMarker, 0);
        TEST_BOAT.setCurrentLeg(start);
        assertEquals(GPSCoordinate.calculateAzimuth(startMarker.getAverageGPSCoordinate(), endMarker.getAverageGPSCoordinate()).degrees(), 0, 1e-8);
    }

    @Test
    public void calculateDueSouthAzimuthReturns180() {
        CompoundMark startMarker = new CompoundMark(new Mark(1, "test origin 1", ORIGIN_COORDS));
        CompoundMark endMarker = new CompoundMark(new Mark(2, "test mark 2", new GPSCoordinate(-50, 0)));
        Leg start = new Leg("Start", startMarker, endMarker, 0);
        TEST_BOAT.setCurrentLeg(start);
        assertEquals(GPSCoordinate.calculateAzimuth(startMarker.getAverageGPSCoordinate(), endMarker.getAverageGPSCoordinate()).degrees(), -180, 1e-8);
    }


    @Test
    public void calculateDueEastAzimuthReturns90() {

        CompoundMark startMarker = new CompoundMark(new Mark(1, "test origin 1", ORIGIN_COORDS));
        CompoundMark endMarker = new CompoundMark(new Mark(2, "test mark 2", new GPSCoordinate(0, 50)));
        Leg start = new Leg("Start", startMarker, endMarker, 0);
        TEST_BOAT.setCurrentLeg(start);
        assertEquals(GPSCoordinate.calculateAzimuth(startMarker.getAverageGPSCoordinate(), endMarker.getAverageGPSCoordinate()).degrees(), 90, 1e-8);
    }


    @Test
    public void calculateDueWestAzimuthReturnsNegative90() {
        CompoundMark startMarker = new CompoundMark(new Mark(1, "test origin 1", ORIGIN_COORDS));
        CompoundMark endMarker = new CompoundMark(new Mark(2, "test mark 2", new GPSCoordinate(0, -50)));
        Leg start = new Leg("Start", startMarker, endMarker, 0);
        TEST_BOAT.setCurrentLeg(start);
        assertEquals(GPSCoordinate.calculateAzimuth(startMarker.getAverageGPSCoordinate(), endMarker.getAverageGPSCoordinate()).degrees(), -90, 1e-8);

    }

    @Test
    public void calculateDueNorthHeadingReturns0() {

        CompoundMark startMarker = new CompoundMark(new Mark(1, "test origin 1", ORIGIN_COORDS));
        CompoundMark endMarker = new CompoundMark(new Mark(2, "test mark 2", new GPSCoordinate(50, 0)));
        Leg start = new Leg("Start", startMarker, endMarker, 0);
        TEST_BOAT.setCurrentLeg(start);
        assertEquals(TEST_BOAT.calculateBearingToNextMarker().degrees(), 0, 1e-8);
    }


    @Test
    public void calculateDueEastHeadingReturns90() {
        CompoundMark startMarker = new CompoundMark(new Mark(1, "test origin 1", ORIGIN_COORDS));
        CompoundMark endMarker = new CompoundMark(new Mark(2, "test mark 2", new GPSCoordinate(0, 50)));
        Leg start = new Leg("Start", startMarker, endMarker, 0);
        TEST_BOAT.setCurrentLeg(start);
        assertEquals(TEST_BOAT.calculateBearingToNextMarker().degrees(), 90, 1e-8);
    }

    @Test
    public void calculateDueSouthHeadingReturns180() {
        CompoundMark startMarker = new CompoundMark(new Mark(1, "test origin 1", ORIGIN_COORDS));
        CompoundMark endMarker = new CompoundMark(new Mark(2, "test mark 2", new GPSCoordinate(-50, 0)));
        Leg start = new Leg("Start", startMarker, endMarker, 0);
        TEST_BOAT.setCurrentLeg(start);
        assertEquals(TEST_BOAT.calculateBearingToNextMarker().degrees(), 180, 1e-8);
    }

    @Test
    public void calculateDueWestHeadingReturns270() {
        CompoundMark startMarker = new CompoundMark(new Mark(1, "test origin 1", ORIGIN_COORDS));
        CompoundMark endMarker = new CompoundMark(new Mark(2, "test mark 2", new GPSCoordinate(0, -50)));
        Leg start = new Leg("Start", startMarker, endMarker, 0);
        TEST_BOAT.setCurrentLeg(start);
        assertEquals(TEST_BOAT.calculateBearingToNextMarker().degrees(), 270, 1e-8);
    }
}
