From 1d7b5271308df390bbb05dcb0513182c5fedcf99 Mon Sep 17 00:00:00 2001 From: William Muir Date: Thu, 10 Aug 2017 16:45:30 +1200 Subject: [PATCH] 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