new method to check if a boat is between gates as well as updated the gps values to fit better with real life values

#story[1101]
main
hba56 8 years ago
parent 13922bc284
commit b7af4e19cf

@ -206,6 +206,7 @@ public class MockBoat extends Boat {
/**
* Check if a mark is on the port side of the boat
* @param mark mark to be passed
* @return true if mark is on port side
*/
public boolean isPortSide(Mark mark){
//if this boat is lower than the mark check which way it is facing
@ -219,6 +220,7 @@ public class MockBoat extends Boat {
/**
* Check if a mark is on the starboard side of the boat
* @param mark mark to be passed
* @return true if mark is on starboard side
*/
public boolean isStarboardSide(Mark mark){
//if this boat is lower than the mark check which way it is facing
@ -229,4 +231,18 @@ public class MockBoat extends Boat {
}
}
/**
* Used to check if this boat is between a gate
* @param gate the gate to be checked
* @return true if the boat is between two marks that make up a gate
*/
public boolean isBetweenGate(CompoundMark gate){
if ((this.isPortSide(gate.getMark1()) && this.isStarboardSide(gate.getMark2())) ||
(this.isStarboardSide(gate.getMark2()) && this.isPortSide(gate.getMark1()))){
return true;
}else{
return false;
}
}
}

@ -5,6 +5,7 @@ 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;
@ -19,6 +20,7 @@ public class MockBoatTest {
private MockBoat firstTestBoat;
private Mark markToTest;
private Mark markToTest2;
private GPSCoordinate highGPS;
private GPSCoordinate middleGPS;
@ -35,10 +37,11 @@ public class MockBoatTest {
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);
highGPS = new GPSCoordinate(-64.854000, 32.296577);
middleGPS = new GPSCoordinate(-64.854000, 32.292500);
lowGPS = new GPSCoordinate(-64.854000, 32.290000);
markToTest = new Mark(1, "test MARK", middleGPS);
markToTest2 = new Mark(2, "test MARK2", middleGPS);
}
catch (InvalidPolarFileException e) {
fail("Couldn't parse polar file.");
@ -153,4 +156,19 @@ public class MockBoatTest {
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);
}
}

Loading…
Cancel
Save