Reads data from boat XML file

- Creates marks for building CompoundMarks (formerly Markers)
- Rearranged Boat constructor and removed velocity

#story[782]
This commit is contained in:
cbt24
2017-05-10 13:57:20 +12:00
parent 6e9386f4fb
commit 69cd44bda8
38 changed files with 511 additions and 384 deletions
+25 -25
View File
@@ -13,23 +13,23 @@ public class BoatTest {
private GPSCoordinate ORIGIN_COORDS = new GPSCoordinate(0, 0);
private Boat TEST_BOAT = new Boat("Test", 1, "tt", 1);
private Boat TEST_BOAT = new Boat(1, "Test", "tt");
@Test
public void calculateDueNorthAzimuthReturns0() {
Marker startMarker = new Marker(ORIGIN_COORDS);
Marker endMarker = new Marker(new GPSCoordinate(50, 0));
Leg start = new Leg("Start", startMarker, endMarker, 0);
CompoundMarker startCompoundMarker = new CompoundMarker(ORIGIN_COORDS);
CompoundMarker endCompoundMarker = new CompoundMarker(new GPSCoordinate(50, 0));
Leg start = new Leg("Start", startCompoundMarker, endCompoundMarker, 0);
TEST_BOAT.setCurrentLeg(start);
assertEquals(TEST_BOAT.calculateAzimuth(), 0, 1e-8);
}
@Test
public void calculateDueSouthAzimuthReturns180() {
Marker startMarker = new Marker(ORIGIN_COORDS);
Marker endMarker = new Marker(new GPSCoordinate(-50, 0));
Leg start = new Leg("Start", startMarker, endMarker, 0);
CompoundMarker startCompoundMarker = new CompoundMarker(ORIGIN_COORDS);
CompoundMarker endCompoundMarker = new CompoundMarker(new GPSCoordinate(-50, 0));
Leg start = new Leg("Start", startCompoundMarker, endCompoundMarker, 0);
TEST_BOAT.setCurrentLeg(start);
assertEquals(TEST_BOAT.calculateAzimuth(), 180, 1e-8);
}
@@ -38,9 +38,9 @@ public class BoatTest {
@Test
public void calculateDueEastAzimuthReturns90() {
Marker startMarker = new Marker(ORIGIN_COORDS);
Marker endMarker = new Marker(new GPSCoordinate(0, 50));
Leg start = new Leg("Start", startMarker, endMarker, 0);
CompoundMarker startCompoundMarker = new CompoundMarker(ORIGIN_COORDS);
CompoundMarker endCompoundMarker = new CompoundMarker(new GPSCoordinate(0, 50));
Leg start = new Leg("Start", startCompoundMarker, endCompoundMarker, 0);
TEST_BOAT.setCurrentLeg(start);
assertEquals(TEST_BOAT.calculateAzimuth(), 90, 1e-8);
}
@@ -48,9 +48,9 @@ public class BoatTest {
@Test
public void calculateDueWestAzimuthReturnsNegative90() {
Marker startMarker = new Marker(ORIGIN_COORDS);
Marker endMarker = new Marker(new GPSCoordinate(0, -50));
Leg start = new Leg("Start", startMarker, endMarker, 0);
CompoundMarker startCompoundMarker = new CompoundMarker(ORIGIN_COORDS);
CompoundMarker endCompoundMarker = new CompoundMarker(new GPSCoordinate(0, -50));
Leg start = new Leg("Start", startCompoundMarker, endCompoundMarker, 0);
TEST_BOAT.setCurrentLeg(start);
assertEquals(TEST_BOAT.calculateAzimuth(), -90, 1e-8);
@@ -59,9 +59,9 @@ public class BoatTest {
@Test
public void calculateDueNorthHeadingReturns0() {
Marker startMarker = new Marker(ORIGIN_COORDS);
Marker endMarker = new Marker(new GPSCoordinate(50, 0));
Leg start = new Leg("Start", startMarker, endMarker, 0);
CompoundMarker startCompoundMarker = new CompoundMarker(ORIGIN_COORDS);
CompoundMarker endCompoundMarker = new CompoundMarker(new GPSCoordinate(50, 0));
Leg start = new Leg("Start", startCompoundMarker, endCompoundMarker, 0);
TEST_BOAT.setCurrentLeg(start);
assertEquals(TEST_BOAT.calculateHeading(), 0, 1e-8);
}
@@ -69,27 +69,27 @@ public class BoatTest {
@Test
public void calculateDueEastHeadingReturns90() {
Marker startMarker = new Marker(ORIGIN_COORDS);
Marker endMarker = new Marker(new GPSCoordinate(0, 50));
Leg start = new Leg("Start", startMarker, endMarker, 0);
CompoundMarker startCompoundMarker = new CompoundMarker(ORIGIN_COORDS);
CompoundMarker endCompoundMarker = new CompoundMarker(new GPSCoordinate(0, 50));
Leg start = new Leg("Start", startCompoundMarker, endCompoundMarker, 0);
TEST_BOAT.setCurrentLeg(start);
assertEquals(TEST_BOAT.calculateHeading(), 90, 1e-8);
}
@Test
public void calculateDueSouthHeadingReturns180() {
Marker startMarker = new Marker(ORIGIN_COORDS);
Marker endMarker = new Marker(new GPSCoordinate(-50, 0));
Leg start = new Leg("Start", startMarker, endMarker, 0);
CompoundMarker startCompoundMarker = new CompoundMarker(ORIGIN_COORDS);
CompoundMarker endCompoundMarker = new CompoundMarker(new GPSCoordinate(-50, 0));
Leg start = new Leg("Start", startCompoundMarker, endCompoundMarker, 0);
TEST_BOAT.setCurrentLeg(start);
assertEquals(TEST_BOAT.calculateHeading(), 180, 1e-8);
}
@Test
public void calculateDueWestHeadingReturns270() {
Marker startMarker = new Marker(ORIGIN_COORDS);
Marker endMarker = new Marker(new GPSCoordinate(0, -50));
Leg start = new Leg("Start", startMarker, endMarker, 0);
CompoundMarker startCompoundMarker = new CompoundMarker(ORIGIN_COORDS);
CompoundMarker endCompoundMarker = new CompoundMarker(new GPSCoordinate(0, -50));
Leg start = new Leg("Start", startCompoundMarker, endCompoundMarker, 0);
TEST_BOAT.setCurrentLeg(start);
assertEquals(TEST_BOAT.calculateHeading(), 270, 1e-8);
}
@@ -8,14 +8,14 @@ import static org.junit.Assert.assertTrue;
/**
* Created by esa46 on 29/03/17.
*/
public class MarkerTest {
public class CompoundMarkerTest {
GPSCoordinate ORIGIN_COORD = new GPSCoordinate(0, 0);
@Test
public void averageOfSingleMarkAtOriginIsSingleMark() {
Marker testMark = new Marker(ORIGIN_COORD);
CompoundMarker testMark = new CompoundMarker(ORIGIN_COORD);
assertTrue(testMark.getAverageGPSCoordinate().equals(ORIGIN_COORD));
}
@@ -24,7 +24,7 @@ public class MarkerTest {
public void averageOfSingleMarkIsSingleMark() {
GPSCoordinate testCoord = new GPSCoordinate(20, 25);
Marker testMark = new Marker(testCoord);
CompoundMarker testMark = new CompoundMarker(testCoord);
assertTrue(testMark.getAverageGPSCoordinate().equals(testCoord));
}
@@ -34,7 +34,7 @@ public class MarkerTest {
public void averageLatOfTwoMarksIsAccurate() {
GPSCoordinate testCoord = new GPSCoordinate(10, 0);
Marker testMark = new Marker(ORIGIN_COORD, testCoord);
CompoundMarker testMark = new CompoundMarker(ORIGIN_COORD, testCoord);
assertTrue(testMark.getAverageGPSCoordinate().equals(new GPSCoordinate(5, 0)));
}
@@ -42,7 +42,7 @@ public class MarkerTest {
public void averageLongOfTwoMarksIsAccurate() {
GPSCoordinate testCoord = new GPSCoordinate(0, 10);
Marker testMark = new Marker(ORIGIN_COORD, testCoord);
CompoundMarker testMark = new CompoundMarker(ORIGIN_COORD, testCoord);
assertTrue(testMark.getAverageGPSCoordinate().equals(new GPSCoordinate(0, 5)));
}
@@ -52,7 +52,7 @@ public class MarkerTest {
GPSCoordinate testCoord1 = new GPSCoordinate(10, 30);
GPSCoordinate testCoord2 = new GPSCoordinate(30, 60);
Marker testMark = new Marker(testCoord1, testCoord2);
CompoundMarker testMark = new CompoundMarker(testCoord1, testCoord2);
assertTrue(testMark.getAverageGPSCoordinate().equals(new GPSCoordinate(020.644102, 44.014817)));
}
+12 -12
View File
@@ -14,7 +14,7 @@ import static junit.framework.TestCase.assertEquals;
*/
public class LegTest {
private Marker ORIGIN_MARKER = new Marker(new GPSCoordinate(0, 0));
private CompoundMarker ORIGIN_Compound_MARKER = new CompoundMarker(new GPSCoordinate(0, 0));
@Test
public void calculateDistanceHandles5nmNorth() {
@@ -22,8 +22,8 @@ public class LegTest {
calc.setStartingGeographicPoint(0, 0);
calc.setDirection(0, 5 * Constants.NMToMetersConversion);
Marker endMarker = getEndMarker(calc.getDestinationGeographicPoint());
Leg test = new Leg("Test", ORIGIN_MARKER, endMarker, 0);
CompoundMarker endCompoundMarker = getEndMarker(calc.getDestinationGeographicPoint());
Leg test = new Leg("Test", ORIGIN_Compound_MARKER, endCompoundMarker, 0);
assertEquals(test.getDistance(), 5, 1e-8);
}
@@ -33,8 +33,8 @@ public class LegTest {
calc.setStartingGeographicPoint(0, 0);
calc.setDirection(90, 12 * Constants.NMToMetersConversion);
Marker endMarker = getEndMarker(calc.getDestinationGeographicPoint());
Leg test = new Leg("Test", ORIGIN_MARKER, endMarker, 0);
CompoundMarker endCompoundMarker = getEndMarker(calc.getDestinationGeographicPoint());
Leg test = new Leg("Test", ORIGIN_Compound_MARKER, endCompoundMarker, 0);
assertEquals(test.getDistance(), 12, 1e-8);
}
@@ -44,8 +44,8 @@ public class LegTest {
calc.setStartingGeographicPoint(0, 0);
calc.setDirection(180, 0.5 * Constants.NMToMetersConversion);
Marker endMarker = getEndMarker(calc.getDestinationGeographicPoint());
Leg test = new Leg("Test", ORIGIN_MARKER, endMarker, 0);
CompoundMarker endCompoundMarker = getEndMarker(calc.getDestinationGeographicPoint());
Leg test = new Leg("Test", ORIGIN_Compound_MARKER, endCompoundMarker, 0);
assertEquals(test.getDistance(), 0.5, 1e-8);
}
@@ -55,23 +55,23 @@ public class LegTest {
calc.setStartingGeographicPoint(0, 0);
calc.setDirection(-90, 0.1 * Constants.NMToMetersConversion);
Marker endMarker = getEndMarker(calc.getDestinationGeographicPoint());
Leg test = new Leg("Test", ORIGIN_MARKER, endMarker, 0);
CompoundMarker endCompoundMarker = getEndMarker(calc.getDestinationGeographicPoint());
Leg test = new Leg("Test", ORIGIN_Compound_MARKER, endCompoundMarker, 0);
assertEquals(test.getDistance(), 0.1, 1e-8);
}
@Test
public void calculateDistanceHandlesZeroDifference() {
Leg test = new Leg("Test", ORIGIN_MARKER, ORIGIN_MARKER, 0);
Leg test = new Leg("Test", ORIGIN_Compound_MARKER, ORIGIN_Compound_MARKER, 0);
assertEquals(test.getDistance(), 0, 1e-8);
}
private Marker getEndMarker(Point2D point) {
private CompoundMarker getEndMarker(Point2D point) {
GPSCoordinate coords = new GPSCoordinate(point.getY(), point.getX());
return new Marker(coords);
return new CompoundMarker(coords);
}
}
@@ -28,8 +28,8 @@
//public class RaceTest{
//
// private static MockOutput mockOutput;
// SharedModel.Leg START_LEG = new SharedModel.Leg("Start", new SharedModel.Marker(new SharedModel.GPSCoordinate(0, 0)), new SharedModel.Marker(new SharedModel.GPSCoordinate(1, 1)), 0);
// SharedModel.Leg FINISH_LEG = new SharedModel.Leg("Finish", new SharedModel.Marker(new SharedModel.GPSCoordinate(1, 1)), new SharedModel.Marker(new SharedModel.GPSCoordinate(2, 2)), 0);
// SharedModel.Leg START_LEG = new SharedModel.Leg("Start", new SharedModel.CompoundMarker(new SharedModel.GPSCoordinate(0, 0)), new SharedModel.CompoundMarker(new SharedModel.GPSCoordinate(1, 1)), 0);
// SharedModel.Leg FINISH_LEG = new SharedModel.Leg("Finish", new SharedModel.CompoundMarker(new SharedModel.GPSCoordinate(1, 1)), new SharedModel.CompoundMarker(new SharedModel.GPSCoordinate(2, 2)), 0);
//
//// @Override
//// public void start(Stage primaryStage) throws Exception{}
@@ -37,23 +37,23 @@ public class RaceXMLTest {
//test boat 2
assertEquals(boats.get(1).getName(), "Land Rover BAR");
assertTrue(boats.get(1).getVelocity() == 30);
assertEquals(boats.get(1).getAbbrev(), "GBR");
assertEquals(boats.get(1).getCountry(), "GBR");
//test boat 3
assertEquals(boats.get(2).getName(), "SoftBank Team Japan");
assertTrue(boats.get(2).getVelocity() == 25);
assertEquals(boats.get(2).getAbbrev(), "JPN");
assertEquals(boats.get(2).getCountry(), "JPN");
//test boat 4
assertEquals(boats.get(3).getName(), "Groupama Team France");
assertTrue(boats.get(3).getVelocity() == 20);
assertEquals(boats.get(3).getAbbrev(), "FRA");
assertEquals(boats.get(3).getCountry(), "FRA");
//test boat 5
assertEquals(boats.get(4).getName(), "Artemis Racing");
assertTrue(boats.get(4).getVelocity() == 29);
assertEquals(boats.get(4).getAbbrev(), "SWE");
assertEquals(boats.get(4).getCountry(), "SWE");
//test boat 6
assertEquals(boats.get(5).getName(), "Emirates Team New Zealand");
assertTrue(boats.get(5).getVelocity() == 62);
assertEquals(boats.get(5).getAbbrev(), "NZL");
assertEquals(boats.get(5).getCountry(), "NZL");
} catch (Exception e) {
fail("Boat Unreadable");
}
@@ -48,7 +48,7 @@
<leg>
<name>Start to Mark 1</name>
<start>
<marker>
<compoundMark>
<coordinate>
<latitude>32.296577</latitude>
<longitude>-64.854304</longitude>
@@ -57,29 +57,29 @@
<latitude>32.293771</latitude>
<longitude>-64.855242</longitude>
</coordinate>
</marker>
</compoundMark>
</start>
<finish>
<marker>
<compoundMark>
<coordinate>
<latitude>32.293039</latitude>
<longitude>-64.843983</longitude>
</coordinate>
</marker>
</compoundMark>
</finish>
</leg>
<leg>
<name>Mark 1 to Leeward Gate</name>
<start>
<marker>
<compoundMark>
<coordinate>
<latitude>32.293039</latitude>
<longitude>-64.843983</longitude>
</coordinate>
</marker>
</compoundMark>
</start>
<finish>
<marker>
<compoundMark>
<coordinate>
<latitude>32.309693</latitude>
<longitude>-64.835249</longitude>
@@ -88,13 +88,13 @@
<latitude>32.308046</latitude>
<longitude>-64.831785</longitude>
</coordinate>
</marker>
</compoundMark>
</finish>
</leg>
<leg>
<name>Leeward Gate to Windward Gate</name>
<start>
<marker>
<compoundMark>
<coordinate>
<latitude>32.309693</latitude>
<longitude>-64.835249</longitude>
@@ -103,10 +103,10 @@
<latitude>32.308046</latitude>
<longitude>-64.831785</longitude>
</coordinate>
</marker>
</compoundMark>
</start>
<finish>
<marker>
<compoundMark>
<coordinate>
<latitude>32.284680</latitude>
<longitude>-64.850045</longitude>
@@ -115,13 +115,13 @@
<latitude>32.280164</latitude>
<longitude>-64.847591</longitude>
</coordinate>
</marker>
</compoundMark>
</finish>
</leg>
<leg>
<name>Windward Gate to Leeward Gate</name>
<start>
<marker>
<compoundMark>
<coordinate>
<latitude>32.284680</latitude>
<longitude>-64.850045</longitude>
@@ -130,10 +130,10 @@
<latitude>32.280164</latitude>
<longitude>-64.847591</longitude>
</coordinate>
</marker>
</compoundMark>
</start>
<finish>
<marker>
<compoundMark>
<coordinate>
<latitude>32.309693</latitude>
<longitude>-64.835249</longitude>
@@ -142,13 +142,13 @@
<latitude>32.308046</latitude>
<longitude>-64.831785</longitude>
</coordinate>
</marker>
</compoundMark>
</finish>
</leg>
<leg>
<name>Leeward Gate to Finish</name>
<start>
<marker>
<compoundMark>
<coordinate>
<latitude>32.309693</latitude>
<longitude>-64.835249</longitude>
@@ -157,10 +157,10 @@
<latitude>32.308046</latitude>
<longitude>-64.831785</longitude>
</coordinate>
</marker>
</compoundMark>
</start>
<finish>
<marker>
<compoundMark>
<coordinate>
<latitude>32.317379</latitude>
<longitude>-64.839291</longitude>
@@ -169,7 +169,7 @@
<latitude>32.317257</latitude>
<longitude>-64.836260</longitude>
</coordinate>
</marker>
</compoundMark>
</finish>
</leg>
</legs>
@@ -220,7 +220,7 @@
<longitude>-64.849184</longitude>
</coordinate>
</boundaries>
<marker>
<compoundMark>
<name>Start Line</name>
<coordinate>
<latitude>32.296577</latitude>
@@ -230,15 +230,15 @@
<latitude>32.293771</latitude>
<longitude>-64.855242</longitude>
</coordinate>
</marker>
<marker>
</compoundMark>
<compoundMark>
<name>Mark</name>
<coordinate>
<latitude>32.293039</latitude>
<longitude>-64.843983</longitude>
</coordinate>
</marker>
<marker>
</compoundMark>
<compoundMark>
<name>Windward Gate</name>
<coordinate>
<latitude>32.284680</latitude>
@@ -248,8 +248,8 @@
<latitude>32.280164</latitude>
<longitude>-64.847591</longitude>
</coordinate>
</marker>
<marker>
</compoundMark>
<compoundMark>
<name>Leeward Gate</name>
<coordinate>
<latitude>32.309693</latitude>
@@ -259,8 +259,8 @@
<latitude>32.308046</latitude>
<longitude>-64.831785</longitude>
</coordinate>
</marker>
<marker>
</compoundMark>
<compoundMark>
<name>Finish Line</name>
<coordinate>
<latitude>32.317379</latitude>
@@ -270,6 +270,6 @@
<latitude>32.317257</latitude>
<longitude>-64.836260</longitude>
</coordinate>
</marker>
</compoundMark>
</course>
</race>