From 1d7b5271308df390bbb05dcb0513182c5fedcf99 Mon Sep 17 00:00:00 2001 From: William Muir Date: Thu, 10 Aug 2017 16:45:30 +1200 Subject: [PATCH 1/2] Tidied code. Added tests #story[1124] #pair[wmu16, hyi25] --- src/test/java/seng302/model/YachtTest.java | 59 ----------------- .../seng302/model/mark/CompoundMarkTest.java | 66 +++++++++++++++++++ .../seng302/utilities/GeoUtilityTest.java | 7 ++ 3 files changed, 73 insertions(+), 59 deletions(-) delete mode 100644 src/test/java/seng302/model/YachtTest.java create mode 100644 src/test/java/seng302/model/mark/CompoundMarkTest.java diff --git a/src/test/java/seng302/model/YachtTest.java b/src/test/java/seng302/model/YachtTest.java deleted file mode 100644 index bc3b8c80..00000000 --- a/src/test/java/seng302/model/YachtTest.java +++ /dev/null @@ -1,59 +0,0 @@ -package seng302.model; - -import static org.junit.Assert.*; - -import java.util.ArrayList; -import java.util.List; -import org.junit.Before; -import org.junit.Test; -import seng302.model.mark.CompoundMark; -import seng302.model.mark.Mark; - -/** - * Use this link to test geo distances - * http://www.csgnetwork.com/gpsdistcalc.html - * Created by wmu16 on 3/08/17. - */ -public class YachtTest { - - private Yacht yacht; - private CompoundMark compoundMark; - private Double toleranceRatio = 0.01; - private GeoPoint p1 = new GeoPoint(57.670333, 11.827833); - private GeoPoint p2 = new GeoPoint(57.671524, 11.844495); - private GeoPoint p3 = new GeoPoint(57.670822, 11.843392); - private GeoPoint p4 = new GeoPoint(25.694829, 98.392049); - - @Before - public void setup() { - yacht = new Yacht("Yacht", - 0, - "0", - "WillIsCool", - "HaomingIsOk", - "NZL"); - - yacht.setLocation(57.670333, 11.827833); - - List subMarks = new ArrayList<>(); - Mark subMark1 = new Mark("H", 57.671524, 11.844495, 0); - Mark subMark2 = new Mark("H", 57.670822, 11.843392, 0); - subMarks.add(subMark1); - subMarks.add(subMark2); - compoundMark = new CompoundMark(0, "HaomingsMark", subMarks); - } - - - //This will no longer work as we cant set the next mark any more as we no longer hold it in - //yacht class as an attribute - -// @Test -// public void testDistanceToNextMark() { -// Double actual, expected; -// actual = yacht.calcDistanceToCurrentMark(); -// expected = 927d; -// assertEquals(expected, actual, expected * toleranceRatio); -// } - - -} \ No newline at end of file diff --git a/src/test/java/seng302/model/mark/CompoundMarkTest.java b/src/test/java/seng302/model/mark/CompoundMarkTest.java new file mode 100644 index 00000000..55ccebf3 --- /dev/null +++ b/src/test/java/seng302/model/mark/CompoundMarkTest.java @@ -0,0 +1,66 @@ +package seng302.model.mark; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.List; +import org.junit.Before; +import org.junit.Test; +import seng302.model.GeoPoint; + +/** + * A class to test the compound mark calss + * Created by wmu16 on 10/08/17. + */ +public class CompoundMarkTest { + + private Mark mark1; + private Mark mark2; + private CompoundMark gateMark; + private CompoundMark singleMark; + + private static Double TOLERANCE_RATIO = 0.01; + + + @Before + public void setUp() throws Exception { + mark1 = new Mark("Mark1", 57.670333, 11.842833, 0); + mark2 = new Mark("Mark2", 57.671524, 11.844495, 1); + + List gateMarks = new ArrayList(); + gateMarks.add(mark1); + gateMarks.add(mark2); + + List singleMarks = new ArrayList(); + singleMarks.add(mark1); + + gateMark = new CompoundMark(0, "Fun Mark", gateMarks); + singleMark = new CompoundMark(1, "Awesome Mark", singleMarks); + } + + + @Test + public void getSubMark() throws Exception { + assertEquals(mark1, gateMark.getSubMark(1)); + assertEquals(mark2, gateMark.getSubMark(2)); + + assertEquals(mark1, singleMark.getSubMark(1)); + } + + @Test + public void getMidPoint() throws Exception { + GeoPoint result = gateMark.getMidPoint(); + assertEquals(57.6709285, result.getLat(), result.getLat() * TOLERANCE_RATIO); + assertEquals(11.843664, result.getLng(), result.getLng() * TOLERANCE_RATIO); + + result = singleMark.getMidPoint(); + assertEquals(result, mark1); + } + + @Test + public void isGate() throws Exception { + assertTrue(gateMark.isGate()); + assertFalse(singleMark.isGate()); + } + +} \ No newline at end of file diff --git a/src/test/java/seng302/utilities/GeoUtilityTest.java b/src/test/java/seng302/utilities/GeoUtilityTest.java index 109b1723..ca2af0e9 100644 --- a/src/test/java/seng302/utilities/GeoUtilityTest.java +++ b/src/test/java/seng302/utilities/GeoUtilityTest.java @@ -170,4 +170,11 @@ public class GeoUtilityTest { assertTrue(GeoUtility.checkCrossedLine(mark2, mark1, location2, location3) == 2); assertTrue(GeoUtility.checkCrossedLine(mark1, mark2, location3, location2) == 2); } + + @Test + public void testDirtyMiddlePoint() { + GeoPoint result = GeoUtility.getDirtyMidPoint(p1, p2); + assertEquals(57.6709285, result.getLat(), result.getLat() * toleranceRate); + assertEquals(11.836164, result.getLng(), result.getLng() * toleranceRate); + } } \ No newline at end of file From 0b8ad137b30e3769fc662da5fcbdcb8f24790780 Mon Sep 17 00:00:00 2001 From: William Muir Date: Thu, 10 Aug 2017 17:47:24 +1200 Subject: [PATCH 2/2] Minor fixes for merge #story[1124] #pair[wmu16, hyi25] --- src/main/java/seng302/model/Yacht.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/seng302/model/Yacht.java b/src/main/java/seng302/model/Yacht.java index 94f351c5..e676bd80 100644 --- a/src/main/java/seng302/model/Yacht.java +++ b/src/main/java/seng302/model/Yacht.java @@ -32,8 +32,6 @@ public class Yacht { private Logger logger = LoggerFactory.getLogger(Yacht.class); - - private static final Integer SPEED_MULTIPLIER = 4; private static final Double ROUNDING_DISTANCE = 50d; // TODO: 3/08/17 wmu16 - Look into this value further @@ -106,7 +104,7 @@ public class Yacht { Double windSpeedKnots = GameState.getWindSpeedKnots(); Double trueWindAngle = Math.abs(GameState.getWindDirection() - heading); Double boatSpeedInKnots = PolarTable.getBoatSpeed(windSpeedKnots, trueWindAngle); - Double maxBoatSpeed = boatSpeedInKnots / 1.943844492 * 1000 * SPEED_MULTIPLIER; + Double maxBoatSpeed = boatSpeedInKnots / 1.943844492 * 1000; if (sailIn && velocity <= maxBoatSpeed && maxBoatSpeed != 0d) { if (velocity < maxBoatSpeed) { @@ -295,7 +293,7 @@ public class Yacht { currentMarkSeqID++; finishedRace = true; logMarkRounding(currentMark); - System.out.println("YAY YOU FINISHED!"); + logger.debug(sourceId + " finished"); // TODO: 8/08/17 wmu16 - Do something! } } @@ -588,10 +586,13 @@ public class Yacht { if (currentMark.isGate()) { typeString = "gate"; } - System.out.println( - "(" + currentMarkSeqID + ") Passed " + typeString + ": " + currentMark.getMarks().get(0) - .getName() - + " ID(" + currentMark.getId() + ")"); + logger.debug( + String.format("BoatID %d passed %s %s with id %d. Now on leg %d", + sourceId, + typeString, + currentMark.getMarks().get(0).getName(), + currentMark.getId(), + currentMarkSeqID)); } public void addLocationListener (YachtLocationListener listener) {