parent
554f8a2a0f
commit
e76de1cbf9
@ -1,31 +1,58 @@
|
||||
package mock.model.commandFactory;
|
||||
|
||||
import mock.model.MockBoat;
|
||||
import mock.model.MockRace;
|
||||
import network.Messages.Enums.BoatActionEnum;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import shared.model.Bearing;
|
||||
import shared.model.Boat;
|
||||
import shared.model.Race;
|
||||
import visualiser.model.VisualiserRace;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.testng.Assert.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Created by connortaylorbrown on 4/08/17.
|
||||
*/
|
||||
public class WindCommandTest {
|
||||
private Race race;
|
||||
private Boat boat;
|
||||
private MockRace race;
|
||||
private MockBoat boat;
|
||||
private Command upwind;
|
||||
private Command downwind;
|
||||
private double initial;
|
||||
|
||||
private double offset = 3.0;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
boat = new Boat(0, "Bob", "NZ");
|
||||
race = mock(MockRace.class);
|
||||
boat = new MockBoat(0, "Bob", "NZ", null);
|
||||
|
||||
when(race.getWindDirection()).thenReturn(Bearing.fromDegrees(0.0));
|
||||
boat.setBearing(Bearing.fromDegrees(45.0));
|
||||
|
||||
upwind = CommandFactory.createCommand(race, boat, BoatActionEnum.UPWIND);
|
||||
downwind = CommandFactory.createCommand(race, boat, BoatActionEnum.DOWNWIND);
|
||||
|
||||
initial = boat.getBearing().degrees();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the difference between initial and final angle is 3 degrees
|
||||
*/
|
||||
@Test
|
||||
public void upwindCommandDecreasesAngle() {
|
||||
upwind.execute();
|
||||
assertEquals(initial - boat.getBearing().degrees(), offset, 1e-5);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void downwindCommandIncreasesAngle() {
|
||||
downwind.execute();
|
||||
assertEquals(boat.getBearing().degrees() - initial, offset, 1e-5);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue