added new methods to the mock boats to let them check which side a mark is on to them
#story[1101]
This commit is contained in:
@@ -203,4 +203,28 @@ public class MockBoat extends Boat {
|
|||||||
return distanceTravelledMeters;
|
return distanceTravelledMeters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a mark is on the port side of the boat
|
||||||
|
*/
|
||||||
|
public boolean isPortSide(Mark mark){
|
||||||
|
//if this boat is lower than the mark check which way it is facing
|
||||||
|
if(this.getCurrentPosition().getLongitude() < mark.getPosition().getLongitude()){
|
||||||
|
return this.getBearing().degrees() <= 180;
|
||||||
|
}else{
|
||||||
|
return this.getBearing().degrees() > 180;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a mark is on the starboard side of the boat
|
||||||
|
*/
|
||||||
|
public boolean isStarboardSide(Mark mark){
|
||||||
|
//if this boat is lower than the mark check which way it is facing
|
||||||
|
if(this.getCurrentPosition().getLongitude() < mark.getPosition().getLongitude()){
|
||||||
|
return this.getBearing().degrees() >= 180;
|
||||||
|
}else{
|
||||||
|
return this.getBearing().degrees() < 180;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,156 @@
|
|||||||
package mock.model;
|
package mock.model;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import mock.dataInput.PolarParser;
|
||||||
|
import mock.exceptions.InvalidPolarFileException;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import shared.model.Bearing;
|
||||||
|
import shared.model.GPSCoordinate;
|
||||||
|
import shared.model.Mark;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
public class MockBoatTest {
|
public class MockBoatTest {
|
||||||
//TODO
|
|
||||||
|
/**
|
||||||
|
* boat made for testing
|
||||||
|
*/
|
||||||
|
private MockBoat firstTestBoat;
|
||||||
|
|
||||||
|
private Mark markToTest;
|
||||||
|
|
||||||
|
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");
|
||||||
|
|
||||||
|
firstTestBoat = new MockBoat(1, "test", "NZ", polars);
|
||||||
|
highGPS = new GPSCoordinate(100, 100);
|
||||||
|
middleGPS = new GPSCoordinate(100, 75);
|
||||||
|
lowGPS = new GPSCoordinate(100, 50);
|
||||||
|
markToTest = new Mark(1, "test MARK", middleGPS);
|
||||||
|
}
|
||||||
|
catch (InvalidPolarFileException e) {
|
||||||
|
fail("Couldn't parse polar file.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user