Added test for WindCommand

#story[1096]
main
Connor Taylor-Brown 8 years ago
parent 554f8a2a0f
commit e76de1cbf9

@ -12,6 +12,8 @@ public class WindCommand implements Command {
private MockBoat boat;
private int direction;
private double offset = 3.0;
public WindCommand(MockRace race, MockBoat boat, boolean upwind) {
this.race = race;
this.boat = boat;
@ -23,7 +25,6 @@ public class WindCommand implements Command {
double wind = race.getWindDirection().degrees();
double heading = boat.getBearing().degrees();
double offset = 3;
if(wind - heading < 0) offset *= -1 * direction;
boat.setBearing(Bearing.fromDegrees(heading + offset));
}

@ -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…
Cancel
Save