Files
SENG302/racevisionGame/src/test/java/mock/model/commandFactory/WindCommandTest.java
T
fjc40 7366aba5ec Added empty data sources, to be used by VisualiserRace.
Created FrameRateTracker which can be used to track framerate.
Updated RequestToJoinEnum and JoinAcceptanceEnum to match the agreed connection API.
Added AssignPlayerBoat message, which is used internally on the client to assign the player a source ID once they have connected.
Fixed some race conditions in the MessageRouter.
Updated ConnectionAcceptor.CheckClientConnection to wait slightly longer before removing connection (there was a slight race condition before).
Race no longer has a reference to LatestMessages. LatestMessages no longer has specific messages types in it.
Created RaceState class, which contains the state that is shared between VisualiserRaceState and MockRaceState (currently only used on visualiser).
Split VisualiserRace into VisualiserRaceState and VisualiserRaceService.
Added the VisualiserRace commands (BoatLocatonCommand, RaceStatusCommand, etc...).
Slightly increased the preferred width of race.fxml table columns.
issues #27 #37 #35
#story[1095]
2017-08-14 00:53:05 +12:00

68 lines
2.0 KiB
Java

package mock.model.commandFactory;
import mock.exceptions.CommandConstructionException;
import mock.model.MockBoat;
import mock.model.MockRace;
import mock.model.MockRaceTest;
import network.Messages.BoatAction;
import network.Messages.Enums.BoatActionEnum;
import org.junit.Before;
import org.junit.Test;
import shared.exceptions.InvalidBoatDataException;
import shared.exceptions.InvalidRaceDataException;
import shared.exceptions.InvalidRegattaDataException;
import shared.model.Bearing;
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() throws CommandConstructionException, InvalidBoatDataException, InvalidRegattaDataException, InvalidRaceDataException {
race = MockRaceTest.createMockRace();
boat = race.getBoats().get(0);
//when(race.getWindDirection()).thenReturn(Bearing.fromDegrees(0.0));
boat.setBearing(Bearing.fromDegrees(45.0));
BoatAction upwindAction = new BoatAction(BoatActionEnum.UPWIND);
upwindAction.setSourceID(boat.getSourceID());
BoatAction downwindAction = new BoatAction(BoatActionEnum.DOWNWIND);
downwindAction.setSourceID(boat.getSourceID());
upwind = CommandFactory.createCommand(race, upwindAction);
downwind = CommandFactory.createCommand(race, downwindAction);
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);
}
}