From b7af4e19cfcfb4ce56776b8c39b802f79df2cf2f Mon Sep 17 00:00:00 2001 From: hba56 Date: Wed, 2 Aug 2017 18:09:12 +1200 Subject: [PATCH] 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] --- .../src/main/java/mock/model/MockBoat.java | 16 +++++++++++++ .../test/java/mock/model/MockBoatTest.java | 24 ++++++++++++++++--- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/racevisionGame/src/main/java/mock/model/MockBoat.java b/racevisionGame/src/main/java/mock/model/MockBoat.java index 44e8e4e6..97fe68ef 100644 --- a/racevisionGame/src/main/java/mock/model/MockBoat.java +++ b/racevisionGame/src/main/java/mock/model/MockBoat.java @@ -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; + } + } + } diff --git a/racevisionGame/src/test/java/mock/model/MockBoatTest.java b/racevisionGame/src/test/java/mock/model/MockBoatTest.java index 71b8f715..32c28ce1 100644 --- a/racevisionGame/src/test/java/mock/model/MockBoatTest.java +++ b/racevisionGame/src/test/java/mock/model/MockBoatTest.java @@ -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); + + } }