parent
554f8a2a0f
commit
e76de1cbf9
@ -1,31 +1,58 @@
|
|||||||
package mock.model.commandFactory;
|
package mock.model.commandFactory;
|
||||||
|
|
||||||
|
import mock.model.MockBoat;
|
||||||
import mock.model.MockRace;
|
import mock.model.MockRace;
|
||||||
import network.Messages.Enums.BoatActionEnum;
|
import network.Messages.Enums.BoatActionEnum;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import shared.model.Bearing;
|
||||||
import shared.model.Boat;
|
import shared.model.Boat;
|
||||||
import shared.model.Race;
|
import shared.model.Race;
|
||||||
import visualiser.model.VisualiserRace;
|
import visualiser.model.VisualiserRace;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
import static org.testng.Assert.*;
|
import static org.testng.Assert.*;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by connortaylorbrown on 4/08/17.
|
* Created by connortaylorbrown on 4/08/17.
|
||||||
*/
|
*/
|
||||||
public class WindCommandTest {
|
public class WindCommandTest {
|
||||||
private Race race;
|
private MockRace race;
|
||||||
private Boat boat;
|
private MockBoat boat;
|
||||||
private Command upwind;
|
private Command upwind;
|
||||||
private Command downwind;
|
private Command downwind;
|
||||||
|
private double initial;
|
||||||
|
|
||||||
|
private double offset = 3.0;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
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
|
@Test
|
||||||
public void upwindCommandDecreasesAngle() {
|
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