Merge remote-tracking branch 'origin/master' into issue_28_36_decoders
# Conflicts: # racevisionGame/src/main/java/mock/app/ConnectionAcceptor.java # racevisionGame/src/main/java/mock/app/Event.java # racevisionGame/src/main/java/visualiser/gameController/ControllerServer.java
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
package mock.model;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import shared.model.Bearing;
|
||||
import shared.model.Wind;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
||||
public class WindGeneratorTest {
|
||||
|
||||
|
||||
private WindGenerator windGenerator;
|
||||
|
||||
private Bearing windBaselineBearing;
|
||||
private Bearing windBearingLowerBound;
|
||||
private Bearing windBearingUpperBound;
|
||||
private double windBaselineSpeed;
|
||||
private double windSpeedLowerBound;
|
||||
private double windSpeedUpperBound;
|
||||
|
||||
private double speedKnotsEpsilon;
|
||||
private double bearingDegreeEpsilon;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
||||
|
||||
//Bounds.
|
||||
this.windBaselineBearing = Bearing.fromDegrees(88.3);
|
||||
this.windBearingLowerBound = Bearing.fromDegrees(66.5);
|
||||
this.windBearingUpperBound = Bearing.fromDegrees(248.6);
|
||||
this.windBaselineSpeed = 13;
|
||||
this.windSpeedLowerBound = 7;
|
||||
this.windSpeedUpperBound = 20;
|
||||
|
||||
this.windGenerator = new WindGenerator(
|
||||
windBaselineBearing,
|
||||
windBearingLowerBound,
|
||||
windBearingUpperBound,
|
||||
windBaselineSpeed,
|
||||
windSpeedLowerBound,
|
||||
windSpeedUpperBound );
|
||||
|
||||
this.bearingDegreeEpsilon = 0.001;
|
||||
this.speedKnotsEpsilon = 0.001;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests if the baseline wind generated it accurate.
|
||||
*/
|
||||
@Test
|
||||
public void generateBaselineWindTest() {
|
||||
|
||||
Wind wind = windGenerator.generateBaselineWind();
|
||||
|
||||
assertEquals(windBaselineSpeed, wind.getWindSpeed(), speedKnotsEpsilon);
|
||||
assertEquals(windBaselineBearing.degrees(), wind.getWindDirection().degrees(), bearingDegreeEpsilon);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if the random wind generated is inside the bounds.
|
||||
*/
|
||||
@Test
|
||||
public void generateRandomWindTest() {
|
||||
|
||||
int randomWindCount = 1000;
|
||||
|
||||
for (int i = 0; i < randomWindCount; i++) {
|
||||
|
||||
Wind wind = windGenerator.generateRandomWind();
|
||||
|
||||
assertTrue(wind.getWindSpeed() >= windSpeedLowerBound);
|
||||
assertTrue(wind.getWindSpeed() <= windSpeedUpperBound);
|
||||
|
||||
assertTrue(wind.getWindDirection().degrees() >= windBearingLowerBound.degrees());
|
||||
assertTrue(wind.getWindDirection().degrees() <= windBearingUpperBound.degrees());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests if the next wind generated is inside the bounds.
|
||||
*/
|
||||
@Test
|
||||
public void generateNextWindTest() {
|
||||
|
||||
Wind wind = windGenerator.generateBaselineWind();
|
||||
|
||||
int randomWindCount = 1000;
|
||||
|
||||
for (int i = 0; i < randomWindCount; i++) {
|
||||
|
||||
wind = windGenerator.generateNextWind(wind);
|
||||
|
||||
assertTrue(wind.getWindSpeed() >= windSpeedLowerBound);
|
||||
assertTrue(wind.getWindSpeed() <= windSpeedUpperBound);
|
||||
|
||||
assertTrue(wind.getWindDirection().degrees() >= windBearingLowerBound.degrees());
|
||||
assertTrue(wind.getWindDirection().degrees() <= windBearingUpperBound.degrees());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +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 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user