You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.6 KiB
58 lines
1.6 KiB
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 MockRace race;
|
|
private MockBoat boat;
|
|
private Command upwind;
|
|
private Command downwind;
|
|
private double initial;
|
|
|
|
private double offset = 3.0;
|
|
|
|
@Before
|
|
public void setUp() {
|
|
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(initial - boat.getBearing().degrees(), offset, 1e-5);
|
|
}
|
|
} |