Merge branch 'master' into story_64_sails

# Conflicts:
#	racevisionGame/src/main/java/shared/model/Boat.java
#	racevisionGame/src/main/java/visualiser/Commands/VisualiserRaceCommands/BoatLocationCommand.java
This commit is contained in:
Joseph Gardner
2017-08-17 12:59:25 +12:00
29 changed files with 538 additions and 324 deletions
@@ -1,174 +1,35 @@
package mock.model;
import mock.dataInput.PolarParser;
import mock.exceptions.InvalidPolarFileException;
import org.junit.Before;
import org.junit.Test;
import shared.model.Bearing;
import shared.model.CompoundMark;
import shared.model.GPSCoordinate;
import shared.model.Mark;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.Assert.*;
public class MockBoatTest {
private MockBoat boat;
private Mark near;
private Mark far;
/**
* boat made for testing
*/
private MockBoat firstTestBoat;
private Mark markToTest;
private Mark markToTest2;
private GPSCoordinate highGPS;
private GPSCoordinate middleGPS;
private GPSCoordinate lowGPS;
/**
* Creates the Polars object for the tests.
*/
@Before
public void setUp() {
//Read in polars.
try {
//Parse data file.
Polars polars = PolarParser.parse("mock/polars/acc_polars.csv");
boat = new MockBoat(0, "Bob", "NZ", null);
boat.setPosition(new GPSCoordinate(0,0));
boat.setBearing(Bearing.fromDegrees(180));
firstTestBoat = new MockBoat(1, "test", "NZ", polars);
highGPS = new GPSCoordinate(32.296577, -64.854000);
middleGPS = new GPSCoordinate(32.292500, -64.854000);
lowGPS = new GPSCoordinate(32.290000, -64.854000);
markToTest = new Mark(1, "test MARK", middleGPS);
markToTest2 = new Mark(2, "test MARK2", middleGPS);
}
catch (InvalidPolarFileException e) {
fail("Couldn't parse polar file.");
}
near = new Mark(0, "Near", new GPSCoordinate(-.0001, 0));
far = new Mark(0, "Far", new GPSCoordinate(.001, 0));
}
//////////////////////////////Mark Higher////////////////////////////////
/**
* Tests if the boat is lower than the mark that the port side method works if
* boat is facing east
*/
@Test
public void testIsPortSide() {
firstTestBoat.setBearing(Bearing.fromDegrees(90));
firstTestBoat.setCurrentPosition(lowGPS);
markToTest.setPosition(highGPS);
assertEquals(firstTestBoat.isPortSide(markToTest), true);
public void nearMarkWithin100m() {
assertTrue(near.rayCast(boat, 100));
}
/**
* Tests if the boat is lower than the mark that the port side method works if
* boat is facing west
*/
@Test
public void testIsPortSideWrong() {
firstTestBoat.setBearing(Bearing.fromDegrees(270));
firstTestBoat.setCurrentPosition(lowGPS);
markToTest.setPosition(highGPS);
assertEquals(firstTestBoat.isPortSide(markToTest), false);
}
/**
* Tests if the boat is lower than the mark that the starboard side method works if
* boat is facing east
*/
@Test
public void testIsStarboardSideWrong() {
firstTestBoat.setBearing(Bearing.fromDegrees(90));
firstTestBoat.setCurrentPosition(lowGPS);
markToTest.setPosition(highGPS);
assertEquals(firstTestBoat.isStarboardSide(markToTest), false);
}
/**
* Tests if the boat is lower than the mark that the starboard side method works if
* boat is facing west
*/
@Test
public void testIsStarboardSide() {
firstTestBoat.setBearing(Bearing.fromDegrees(270));
firstTestBoat.setCurrentPosition(lowGPS);
markToTest.setPosition(highGPS);
assertEquals(firstTestBoat.isStarboardSide(markToTest), true);
}
//////////////////////////////Mark Lower////////////////////////////////
/**
* Tests if the boat is higher than the mark that the port side method works if
* boat is facing east
*/
@Test
public void testIsPortSideHigherWrong() {
firstTestBoat.setBearing(Bearing.fromDegrees(90));
firstTestBoat.setCurrentPosition(highGPS);
markToTest.setPosition(lowGPS);
assertEquals(firstTestBoat.isPortSide(markToTest), false);
}
/**
* Tests if the boat is higher than the mark that the port side method works if
* boat is facing west
*/
@Test
public void testIsPortSideHigher() {
firstTestBoat.setBearing(Bearing.fromDegrees(270));
firstTestBoat.setCurrentPosition(highGPS);
markToTest.setPosition(lowGPS);
assertEquals(firstTestBoat.isPortSide(markToTest), true);
}
/**
* Tests if the boat is higher than the mark that the starboard side method works if
* boat is facing east
*/
@Test
public void testIsStarboardSideHigher() {
firstTestBoat.setBearing(Bearing.fromDegrees(90));
firstTestBoat.setCurrentPosition(highGPS);
markToTest.setPosition(lowGPS);
assertEquals(firstTestBoat.isStarboardSide(markToTest), true);
}
/**
* Tests if the boat is higher than the mark that the starboard side method works if
* boat is facing west
*/
@Test
public void testIsStarboardSideHigherWrong() {
firstTestBoat.setBearing(Bearing.fromDegrees(270));
firstTestBoat.setCurrentPosition(highGPS);
markToTest.setPosition(lowGPS);
assertEquals(firstTestBoat.isStarboardSide(markToTest), false);
}
/**
* Tests if a boat is between a gate
*/
@Test
public void testIsBetweenGate(){
markToTest.setPosition(highGPS);
markToTest2.setPosition(lowGPS);
CompoundMark testGate = new CompoundMark(1, "test GATE", markToTest, markToTest2);
firstTestBoat.setCurrentPosition(middleGPS);
assertEquals(firstTestBoat.isBetweenGate(testGate), true);
public void farMarkBeyond100m() {
assertFalse(far.rayCast(boat, 100));
}
}
@@ -0,0 +1,47 @@
package network.MessageDecoders;
import network.MessageEncoders.RaceVisionByteEncoder;
import network.Messages.Enums.YachtEventEnum;
import network.Messages.YachtEvent;
import org.junit.Before;
import org.junit.Test;
import static org.testng.Assert.*;
/**
* Tests for the YachtEvent decoder and encoder
*/
public class YachtEventCodeDecoderTest {
private YachtEvent decodedMessage;
private YachtEvent originalMessage;
@Before
public void setUp() throws Exception {
long timestamp = System.currentTimeMillis();
originalMessage = new YachtEvent(
timestamp,
55,
35,
0,
1,
YachtEventEnum.COLLISION
);
byte[] encodedMessage = RaceVisionByteEncoder.encode(originalMessage);
YachtEventCodeDecoder testDecoder = new YachtEventCodeDecoder();
testDecoder.decode(encodedMessage);
decodedMessage = testDecoder.getMessage();
}
@Test
public void decodingEqualsOriginal() {
assertEquals(originalMessage.getCurrentTime(), decodedMessage.getCurrentTime());
assertEquals(originalMessage.getAckNum(), decodedMessage.getAckNum());
assertEquals(originalMessage.getRaceID(), decodedMessage.getRaceID());
assertEquals(originalMessage.getSourceID(), decodedMessage.getSourceID());
assertEquals(originalMessage.getIncidentID(), decodedMessage.getIncidentID());
assertEquals(originalMessage.getYachtEvent(), decodedMessage.getYachtEvent());
}
}
@@ -19,7 +19,7 @@ public class BoatTest {
public void setUp() {
ORIGIN_COORDS = new GPSCoordinate(0, 0);
TEST_BOAT = new Boat(1, "Test", "tt");
TEST_BOAT.setCurrentPosition(ORIGIN_COORDS);
TEST_BOAT.setPosition(ORIGIN_COORDS);
}
//TODO these bearing tests could be tidied up to reduce code repetition.
@@ -113,7 +113,7 @@ public class BoatTest {
Leg start = new Leg("Start", startMarker, endMarker, 0);
TEST_BOAT.setCurrentLeg(start);
assertEquals(GPSCoordinate.calculateAzimuth(TEST_BOAT.getCurrentPosition(), endMarker.getAverageGPSCoordinate()).degrees(), 0, 1e-8);
assertEquals(GPSCoordinate.calculateAzimuth(TEST_BOAT.getPosition(), endMarker.getAverageGPSCoordinate()).degrees(), 0, 1e-8);
}
@@ -131,7 +131,7 @@ public class BoatTest {
Leg start = new Leg("Start", startMarker, endMarker, 0);
TEST_BOAT.setCurrentLeg(start);
assertEquals(GPSCoordinate.calculateAzimuth(TEST_BOAT.getCurrentPosition(), endMarker.getAverageGPSCoordinate()).degrees(), 90, 1e-8);
assertEquals(GPSCoordinate.calculateAzimuth(TEST_BOAT.getPosition(), endMarker.getAverageGPSCoordinate()).degrees(), 90, 1e-8);
}
@Test
@@ -148,7 +148,7 @@ public class BoatTest {
Leg start = new Leg("Start", startMarker, endMarker, 0);
TEST_BOAT.setCurrentLeg(start);
assertEquals(GPSCoordinate.calculateAzimuth(TEST_BOAT.getCurrentPosition(), endMarker.getAverageGPSCoordinate()).degrees(), -180, 1e-8);
assertEquals(GPSCoordinate.calculateAzimuth(TEST_BOAT.getPosition(), endMarker.getAverageGPSCoordinate()).degrees(), -180, 1e-8);
}
@Test
@@ -165,7 +165,7 @@ public class BoatTest {
Leg start = new Leg("Start", startMarker, endMarker, 0);
TEST_BOAT.setCurrentLeg(start);
assertEquals(GPSCoordinate.calculateBearing(TEST_BOAT.getCurrentPosition(), endMarker.getAverageGPSCoordinate()).degrees(), 270, 1e-8);
assertEquals(GPSCoordinate.calculateBearing(TEST_BOAT.getPosition(), endMarker.getAverageGPSCoordinate()).degrees(), 270, 1e-8);
}