From 30b844e094c971ed326261b0a5d0f58184099a24 Mon Sep 17 00:00:00 2001 From: Erika Savell Date: Mon, 20 Mar 2017 14:35:26 +1300 Subject: [PATCH 01/10] Renamed project to team-7 #chore --- .idea/.name | 1 - .idea/compiler.xml | 22 ++------ .idea/copyright/profiles_settings.xml | 3 -- .idea/misc.xml | 78 ++++++++++++++------------- .idea/modules.xml | 2 +- pom.xml | 4 +- 6 files changed, 47 insertions(+), 63 deletions(-) delete mode 100644 .idea/.name delete mode 100644 .idea/copyright/profiles_settings.xml diff --git a/.idea/.name b/.idea/.name deleted file mode 100644 index 7a0b7f00..00000000 --- a/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -app \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml index c9e75922..12dfecd9 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,32 +1,16 @@ - - - - - - - - - - - - - - - - + - - + - + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml deleted file mode 100644 index e7bedf33..00000000 --- a/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 1972028c..e033ea8a 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,25 +1,42 @@ - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index 6361584b..09c81627 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,7 +2,7 @@ - + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 69af7436..2de31d34 100644 --- a/pom.xml +++ b/pom.xml @@ -2,10 +2,10 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 seng302 - app + team-7 jar 0.0 - app + team-7 https://eng-git.canterbury.ac.nz/SENG302-2016/team-7 From 0387bdc5970ba73d35550e0b7f1631c246d34a32 Mon Sep 17 00:00:00 2001 From: Erika Savell Date: Wed, 22 Mar 2017 10:07:14 +1300 Subject: [PATCH 02/10] Tests for genreating new coordinate added #test #story[9] --- src/main/java/seng302/Constants.java | 12 +-- .../seng302/Model/ConstantVelocityRace.java | 4 +- src/main/java/seng302/Model/Race.java | 4 +- .../Model/ConstantVelocityRaceTest.java | 73 +++++++++++++++++-- 4 files changed, 78 insertions(+), 15 deletions(-) diff --git a/src/main/java/seng302/Constants.java b/src/main/java/seng302/Constants.java index 0db52afb..785448c2 100644 --- a/src/main/java/seng302/Constants.java +++ b/src/main/java/seng302/Constants.java @@ -25,12 +25,12 @@ public class Constants { public static final GPSCoordinate finishLineMarker2 = new GPSCoordinate(32.317257, -64.836260); public static final BoatInRace[] OFFICIAL_AC35_COMPETITORS = new BoatInRace[] - {new BoatInRace("Oracle Team USA", 200.0, Color.BLUEVIOLET), - new BoatInRace("Land Rover BAR", 180.0, Color.BLACK), - new BoatInRace("SoftBank Team Japan", 190.0, Color.RED), - new BoatInRace("Groupama Team France", 210.0, Color.ORANGE), - new BoatInRace("Artemis Racing", 220.0, Color.DARKOLIVEGREEN), - new BoatInRace("Emirates Team New Zealand", 310, Color.LIMEGREEN)}; + {new BoatInRace("Oracle Team USA", 300.0, Color.BLUEVIOLET), + new BoatInRace("Land Rover BAR", 500.0, Color.BLACK), + new BoatInRace("SoftBank Team Japan", 400.0, Color.RED), + new BoatInRace("Groupama Team France", 350.0, Color.ORANGE), + new BoatInRace("Artemis Racing", 440.0, Color.DARKOLIVEGREEN), + new BoatInRace("Emirates Team New Zealand", 620, Color.LIMEGREEN)}; //public static final Leg bermudaCourseStartToMark1 = new Leg(0, , new ) } diff --git a/src/main/java/seng302/Model/ConstantVelocityRace.java b/src/main/java/seng302/Model/ConstantVelocityRace.java index db18b1e3..fb2afc99 100644 --- a/src/main/java/seng302/Model/ConstantVelocityRace.java +++ b/src/main/java/seng302/Model/ConstantVelocityRace.java @@ -35,13 +35,13 @@ public class ConstantVelocityRace extends Race { double distanceTravelled = boat.getVelocity() * millisecondsElapsed/3600000; double totalDistanceTravelled = distanceTravelled + boat.getDistanceTravelledInLeg(); - if (!boat.getCurrentLeg().getName().equals("Finish")) { + boolean finish = boat.getCurrentLeg().getName().equals("Finish"); + if (!finish) { boat.setDistanceTravelledInLeg(totalDistanceTravelled); boat.setCurrentPosition(calculatePosition(boat.getCurrentLeg().getStartGraphCoordinate(), totalDistanceTravelled, boat.calculateAzimuth())); } - } /** diff --git a/src/main/java/seng302/Model/Race.java b/src/main/java/seng302/Model/Race.java index cff2b9a8..113ef4fe 100644 --- a/src/main/java/seng302/Model/Race.java +++ b/src/main/java/seng302/Model/Race.java @@ -24,8 +24,8 @@ public abstract class Race implements Runnable { protected long totalTimeElapsed; - private int SLEEP_TIME = 25; //time in milliseconds to pause in a paced loop - private int PRERACE_TIME = Integer.MAX_VALUE; //time in milliseconds to pause during pre-race + private int SLEEP_TIME = 100; //time in milliseconds to pause in a paced loop + private int PRERACE_TIME = 1000; //time in milliseconds to pause during pre-race /** * Initailiser for Race diff --git a/src/test/java/seng302/Model/ConstantVelocityRaceTest.java b/src/test/java/seng302/Model/ConstantVelocityRaceTest.java index 19e57e7d..024028da 100644 --- a/src/test/java/seng302/Model/ConstantVelocityRaceTest.java +++ b/src/test/java/seng302/Model/ConstantVelocityRaceTest.java @@ -1,7 +1,10 @@ package seng302.Model; +import org.geotools.referencing.GeodeticCalculator; import org.junit.Test; +import org.opengis.geometry.coordinate.Geodesic; +import seng302.Constants; import seng302.GPSCoordinate; import java.awt.geom.Point2D; @@ -13,12 +16,72 @@ import static org.junit.Assert.assertEquals; */ public class ConstantVelocityRaceTest { +// @Test +// public void + + + + @Test + public void travelling10nmNorthGivesCorrectNewCoordinates() { + GPSCoordinate oldPos = new GPSCoordinate(0, 0); + GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 10, 0); + + GeodeticCalculator calc = new GeodeticCalculator(); + calc.setStartingGeographicPoint(0, 0); + calc.setDirection(0, 10 * Constants.NMToMetersConversion); + + + assertEquals(newPos.getLongitude(), 0, 1e-8); + assertEquals(newPos.getLatitude(), calc.getDestinationGeographicPoint().getY(), 1e-8); + assertEquals(newPos.getLongitude(), calc.getDestinationGeographicPoint().getX(), 1e-8); + } + + @Test - public void travelling5nmNorthGivesCorrectNewCoordinates() { + public void travelling10nmEastGivesCorrectNewCoordinates() { GPSCoordinate oldPos = new GPSCoordinate(0, 0); - GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 5, 0); -// assertEquals(newPos.getLatitude(), 0.08374461297528203, ); -// assertEquals(ConstantVelocityRace.calculatePosition(oldPos, 5, 90).getLatitude(), 0.08, 1e-1); - System.out.println(ConstantVelocityRace.calculatePosition(oldPos, 5, 0).getLongitude()); + GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 10, 90); + + GeodeticCalculator calc = new GeodeticCalculator(); + calc.setStartingGeographicPoint(0, 0); + calc.setDirection(90, 10 * Constants.NMToMetersConversion); + + + assertEquals(newPos.getLatitude(), 0, 1e-8); + assertEquals(newPos.getLatitude(), calc.getDestinationGeographicPoint().getY(), 1e-8); + assertEquals(newPos.getLongitude(), calc.getDestinationGeographicPoint().getX(), 1e-8); } + + + @Test + public void travelling10nmWestGivesCorrectNewCoordinates() { + GPSCoordinate oldPos = new GPSCoordinate(0, 0); + GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 10, -90); + + GeodeticCalculator calc = new GeodeticCalculator(); + calc.setStartingGeographicPoint(0, 0); + calc.setDirection(-90, 10 * Constants.NMToMetersConversion); + + + assertEquals(newPos.getLatitude(), 0, 1e-8); + assertEquals(newPos.getLatitude(), calc.getDestinationGeographicPoint().getY(), 1e-8); + assertEquals(newPos.getLongitude(), calc.getDestinationGeographicPoint().getX(), 1e-8); + } + + + @Test + public void travelling10nmSouthGivesCorrectNewCoordinates() { + GPSCoordinate oldPos = new GPSCoordinate(0, 0); + GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 10, 180); + + GeodeticCalculator calc = new GeodeticCalculator(); + calc.setStartingGeographicPoint(0, 0); + calc.setDirection(180, 10 * Constants.NMToMetersConversion); + + + assertEquals(newPos.getLongitude(), 0, 1e-8); + assertEquals(newPos.getLatitude(), calc.getDestinationGeographicPoint().getY(), 1e-8); + assertEquals(newPos.getLongitude(), calc.getDestinationGeographicPoint().getX(), 1e-8); + } + } From 393fae2ec47fbeb9f05d4ec60766146da1a570c3 Mon Sep 17 00:00:00 2001 From: Erika Savell Date: Wed, 22 Mar 2017 11:03:16 +1300 Subject: [PATCH 03/10] Tests for calculating leg distance and updating boat positions added #story[9] #test --- .../seng302/Model/ConstantVelocityRace.java | 1 + src/main/java/seng302/Model/Leg.java | 10 +-- .../seng302/Model/ResizableRaceCanvas.java | 5 +- .../Model/ConstantVelocityRaceTest.java | 46 +++++++++++- src/test/java/seng302/Model/LegTest.java | 71 +++++++++++++++++++ src/test/java/seng302/Model/RaceTest.java | 25 ------- 6 files changed, 118 insertions(+), 40 deletions(-) create mode 100644 src/test/java/seng302/Model/LegTest.java diff --git a/src/main/java/seng302/Model/ConstantVelocityRace.java b/src/main/java/seng302/Model/ConstantVelocityRace.java index fb2afc99..1b83c92d 100644 --- a/src/main/java/seng302/Model/ConstantVelocityRace.java +++ b/src/main/java/seng302/Model/ConstantVelocityRace.java @@ -13,6 +13,7 @@ import java.util.ArrayList; * Created by cbt24 on 6/03/17. */ public class ConstantVelocityRace extends Race { + /** * Initialiser for a Race with constant velocity. * @param startingBoats array of boats diff --git a/src/main/java/seng302/Model/Leg.java b/src/main/java/seng302/Model/Leg.java index 84ee1529..3cc41743 100644 --- a/src/main/java/seng302/Model/Leg.java +++ b/src/main/java/seng302/Model/Leg.java @@ -55,15 +55,6 @@ public class Leg { return distance; } - - /** - * - * @return Returns the name of the Leg - */ - public String toString() { - return name; - } - /** * Returns the coordinates in GPSCoordinate class of the boats starting coordinate. * @return Returns the coordinate of the start of the leg. @@ -101,5 +92,6 @@ public class Leg { calc.setStartingGeographicPoint(startGPSCoordinate.getLongitude(), startGPSCoordinate.getLatitude()); calc.setDestinationGeographicPoint(endGPSCoordinate.getLongitude(), endGPSCoordinate.getLatitude()); return calc.getOrthodromicDistance() / Constants.NMToMetersConversion; + } } diff --git a/src/main/java/seng302/Model/ResizableRaceCanvas.java b/src/main/java/seng302/Model/ResizableRaceCanvas.java index bcb44e1e..ab46da00 100644 --- a/src/main/java/seng302/Model/ResizableRaceCanvas.java +++ b/src/main/java/seng302/Model/ResizableRaceCanvas.java @@ -1,6 +1,6 @@ package seng302.Model; -import com.sun.xml.internal.bind.v2.runtime.reflect.opt.Const; + import javafx.scene.canvas.Canvas; import javafx.scene.canvas.GraphicsContext; import javafx.scene.paint.Color; @@ -11,9 +11,6 @@ import seng302.GPSCoordinate; import seng302.GraphCoordinate; import seng302.RaceMap; -import java.util.ArrayList; -import java.util.Random; - /** * This creates a JavaFX Canvas that is fills it's parent. * Cannot be downsized. diff --git a/src/test/java/seng302/Model/ConstantVelocityRaceTest.java b/src/test/java/seng302/Model/ConstantVelocityRaceTest.java index 024028da..61dc66b7 100644 --- a/src/test/java/seng302/Model/ConstantVelocityRaceTest.java +++ b/src/test/java/seng302/Model/ConstantVelocityRaceTest.java @@ -1,6 +1,7 @@ package seng302.Model; +import javafx.scene.paint.Color; import org.geotools.referencing.GeodeticCalculator; import org.junit.Test; import org.opengis.geometry.coordinate.Geodesic; @@ -8,6 +9,7 @@ import seng302.Constants; import seng302.GPSCoordinate; import java.awt.geom.Point2D; +import java.util.ArrayList; import static org.junit.Assert.assertEquals; @@ -16,10 +18,50 @@ import static org.junit.Assert.assertEquals; */ public class ConstantVelocityRaceTest { -// @Test -// public void + @Test + public void updatePositionChangesDistanceTravelled() { + + BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt"); + Leg start = new Leg("Start", new GPSCoordinate(0, 0), new GPSCoordinate(50, 50), 0); + boat.setCurrentLeg(start); + boat.setDistanceTravelledInLeg(0); + int timeElapsed = 3600000; //1 hr + + ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], new ArrayList()); + + race.updatePosition(boat, timeElapsed); + assertEquals(boat.getDistanceTravelledInLeg(), boat.getVelocity() * timeElapsed / 3600000, 1e-8); + } + + @Test + public void updatePositionHandlesNoChangeToDistanceTravelled() { + + BoatInRace boat = new BoatInRace("Test", 0, Color.ALICEBLUE, "tt"); + Leg start = new Leg("Start", new GPSCoordinate(0, 0), new GPSCoordinate(50, 50), 0); + boat.setCurrentLeg(start); + boat.setDistanceTravelledInLeg(0); + int timeElapsed = 3600000; //1 hr + ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], new ArrayList()); + + race.updatePosition(boat, timeElapsed); + assertEquals(boat.getDistanceTravelledInLeg(), 0, 1e-8); + } + + @Test + public void changesToDistanceTravelledAreAdditive() { + BoatInRace boat = new BoatInRace("Test", 5, Color.ALICEBLUE, "tt"); + Leg start = new Leg("Start", new GPSCoordinate(0, 0), new GPSCoordinate(50, 50), 0); + boat.setCurrentLeg(start); + boat.setDistanceTravelledInLeg(50); + int timeElapsed = 3600000; //1 hr + + ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], new ArrayList()); + + race.updatePosition(boat, timeElapsed); + assertEquals(boat.getDistanceTravelledInLeg(), boat.getVelocity() * timeElapsed / 3600000 + 50, 1e-8); + } @Test public void travelling10nmNorthGivesCorrectNewCoordinates() { diff --git a/src/test/java/seng302/Model/LegTest.java b/src/test/java/seng302/Model/LegTest.java new file mode 100644 index 00000000..621ea98b --- /dev/null +++ b/src/test/java/seng302/Model/LegTest.java @@ -0,0 +1,71 @@ +package seng302.Model; + +import org.geotools.referencing.GeodeticCalculator; +import org.junit.Test; +import seng302.Constants; +import seng302.GPSCoordinate; + +import static junit.framework.TestCase.assertEquals; + +/** + * Created by esa46 on 22/03/17. + */ +public class LegTest { + + @Test + public void calculateDistanceHandles5nmNorth() { + GeodeticCalculator calc = new GeodeticCalculator(); + calc.setStartingGeographicPoint(0, 0); + calc.setDirection(0, 5 * Constants.NMToMetersConversion); + + GPSCoordinate startPoint = new GPSCoordinate(0, 0); + GPSCoordinate endPoint = new GPSCoordinate(calc.getDestinationGeographicPoint().getY(), calc.getDestinationGeographicPoint().getX()); + Leg test= new Leg("Test", startPoint, endPoint, 0); + assertEquals(test.getDistance(), 5, 1e-8); + } + + @Test + public void calculateDistanceHandles12nmEast() { + GeodeticCalculator calc = new GeodeticCalculator(); + calc.setStartingGeographicPoint(0, 0); + calc.setDirection(90, 12 * Constants.NMToMetersConversion); + + GPSCoordinate startPoint = new GPSCoordinate(0, 0); + GPSCoordinate endPoint = new GPSCoordinate(calc.getDestinationGeographicPoint().getY(), calc.getDestinationGeographicPoint().getX()); + Leg test= new Leg("Test", startPoint, endPoint, 0); + assertEquals(test.getDistance(), 12, 1e-8); + } + + @Test + public void calculateDistanceHandlesHalfnmSouth() { + GeodeticCalculator calc = new GeodeticCalculator(); + calc.setStartingGeographicPoint(0, 0); + calc.setDirection(180, 0.5 * Constants.NMToMetersConversion); + + GPSCoordinate startPoint = new GPSCoordinate(0, 0); + GPSCoordinate endPoint = new GPSCoordinate(calc.getDestinationGeographicPoint().getY(), calc.getDestinationGeographicPoint().getX()); + Leg test= new Leg("Test", startPoint, endPoint, 0); + assertEquals(test.getDistance(), 0.5, 1e-8); + } + + @Test + public void calculateDistanceHandlesPoint1nmWest() { + GeodeticCalculator calc = new GeodeticCalculator(); + calc.setStartingGeographicPoint(0, 0); + calc.setDirection(-90, 0.1 * Constants.NMToMetersConversion); + + GPSCoordinate startPoint = new GPSCoordinate(0, 0); + GPSCoordinate endPoint = new GPSCoordinate(calc.getDestinationGeographicPoint().getY(), calc.getDestinationGeographicPoint().getX()); + Leg test= new Leg("Test", startPoint, endPoint, 0); + assertEquals(test.getDistance(), 0.1, 1e-8); + } + + @Test + public void calculateDistanceHandlesZeroDifference() { + GPSCoordinate startPoint = new GPSCoordinate(0, 0); + GPSCoordinate endPoint = new GPSCoordinate(0, 0); + Leg test= new Leg("Test", startPoint, endPoint, 0); + assertEquals(test.getDistance(), 0, 1e-8); + } + +} diff --git a/src/test/java/seng302/Model/RaceTest.java b/src/test/java/seng302/Model/RaceTest.java index f448d092..b7a52d3d 100644 --- a/src/test/java/seng302/Model/RaceTest.java +++ b/src/test/java/seng302/Model/RaceTest.java @@ -22,31 +22,6 @@ import static org.junit.Assert.assertTrue; public class RaceTest { -// @Ignore -// @Test -// public void singleBoatRaceRunsAndFinishes(){ -// -// BoatInRace boat = new BoatInRace("NZ", 240); -// ArrayList boats = new ArrayList<>(); -// boats.add(boat); -// ArrayList legs = new ArrayList<>(); -// legs.add(new Leg("Start", new GPSCoordinate(0,0), new GPSCoordinate(1,1), 0)); -// ConstantVelocityRace race = new ConstantVelocityRace(boats, legs); -// race.run(); -// } -// -// @Test -// public void fasterBoatFinishesFirst() { -// BoatInRace fasterBoat = new BoatInRace("NZ", 2800); -// BoatInRace slowerBoat = new BoatInRace("AU", 1800); -// BoatInRace[] boats = new BoatInRace[] {slowerBoat, fasterBoat}; -// Leg leg1 = new Leg("first leg", 1, new GPSCoordinate(0, 0), new GPSCoordinate(3, 4), 0); -// ArrayList legs = new ArrayList<>(); -// legs.add(leg1); -// ConstantVelocityRace race = new ConstantVelocityRace(boats, legs); -// race.run(); -// } - @Test public void finishOrderDeterminedByVelocity() { BoatInRace[] boats = { From 71995accfbdd26e5706781f47172234d7d95afd8 Mon Sep 17 00:00:00 2001 From: Erika Savell Date: Wed, 22 Mar 2017 11:22:05 +1300 Subject: [PATCH 04/10] Refactored BoatInRace currentLegName property -Removed current leg name as current leg was already being stored so it was redundant #refactor #story[15] --- src/main/java/seng302/Model/BoatInRace.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/seng302/Model/BoatInRace.java b/src/main/java/seng302/Model/BoatInRace.java index 560feb21..c20770ea 100644 --- a/src/main/java/seng302/Model/BoatInRace.java +++ b/src/main/java/seng302/Model/BoatInRace.java @@ -20,7 +20,6 @@ public class BoatInRace extends Boat { private long timeFinished; private Color colour; private boolean finished = false; - private StringProperty currentLegName; /** * Constructor method. @@ -31,7 +30,6 @@ public class BoatInRace extends Boat { public BoatInRace(String name, double velocity, Color colour, String abbrev) { super(name, velocity, abbrev); setColour(colour); - currentLegName = new SimpleStringProperty(""); } /** @@ -92,10 +90,15 @@ public class BoatInRace extends Boat { */ public void setCurrentLeg(Leg currentLeg) { this.currentLeg = currentLeg; - this.currentLegName.setValue(currentLeg.getName()); } public StringProperty getCurrentLegName(){ + + StringProperty currentLegName = new SimpleStringProperty(""); + if (currentLeg != null) { + currentLegName.setValue(currentLeg.getName()); + } + return currentLegName; } @@ -132,7 +135,6 @@ public class BoatInRace extends Boat { this.finished = bool; } - /** * Calculates the bearing of the travel via map coordinates of the raceMarkers * @return the heading that the boat is heading towards in degrees. From 7e2804215beb174dbeb3796a974f14b856a9f2fc Mon Sep 17 00:00:00 2001 From: Erika Savell Date: Wed, 22 Mar 2017 11:38:57 +1300 Subject: [PATCH 05/10] Methods for calculating heading (instead of azimuth) added - Azimuth is necessary for geodetic calculator but is between -180 and 180 - Headings need to be displayed from 0 to 360 so conversions methods were necessary #implement #sory[24] --- src/main/java/seng302/Model/BoatInRace.java | 28 ++++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/main/java/seng302/Model/BoatInRace.java b/src/main/java/seng302/Model/BoatInRace.java index c20770ea..3e3a1065 100644 --- a/src/main/java/seng302/Model/BoatInRace.java +++ b/src/main/java/seng302/Model/BoatInRace.java @@ -98,7 +98,6 @@ public class BoatInRace extends Boat { if (currentLeg != null) { currentLegName.setValue(currentLeg.getName()); } - return currentLegName; } @@ -136,17 +135,38 @@ public class BoatInRace extends Boat { } /** - * Calculates the bearing of the travel via map coordinates of the raceMarkers - * @return the heading that the boat is heading towards in degrees. + * Calculates the azimuth of the travel via map coordinates of the raceMarkers + * @return the direction that the boat is heading towards in degrees (-180 to 180). */ public double calculateAzimuth(){ - //to be changed to coordinates when used to match reality. + GeodeticCalculator calc = new GeodeticCalculator(); calc.setStartingGeographicPoint(currentLeg.getStartGraphCoordinate().getLongitude(), currentLeg.getStartGraphCoordinate().getLatitude()); calc.setDestinationGeographicPoint(currentLeg.getEndGraphCoordinate().getLongitude(), currentLeg.getEndGraphCoordinate().getLatitude()); return calc.getAzimuth(); + } + /** + * Converts an azimuth to a bearing + * @param azimuth azimuth valuye to be converted + * @return the bearings in degrees (0 to 360). + */ + public static double calculateHeading(double azimuth) { + if (azimuth >= 0) { + return azimuth; + } + else { + return azimuth + 360; + } } + /** + * Calculates the bearing of the travel via map coordinates of the raceMarkers + * @return the direction that the boat is heading towards in degrees (0 to 360). + */ + public double calculateHeading(){ + double azimuth = this.calculateAzimuth(); + return calculateHeading(azimuth); + } } From a77f4883f3052da19cd0af3fad1aaa7b3b4167d9 Mon Sep 17 00:00:00 2001 From: Fan-Wu Yang Date: Wed, 22 Mar 2017 12:20:20 +1300 Subject: [PATCH 06/10] Create Resource XML - Created Race XML file which contains the perameters of the bermuda race for AC35 --- src/main/resources/raceXML/bermuda_AC35.xml | 182 ++++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100644 src/main/resources/raceXML/bermuda_AC35.xml diff --git a/src/main/resources/raceXML/bermuda_AC35.xml b/src/main/resources/raceXML/bermuda_AC35.xml new file mode 100644 index 00000000..57dcc08e --- /dev/null +++ b/src/main/resources/raceXML/bermuda_AC35.xml @@ -0,0 +1,182 @@ + + + + ORACLE TEAM USA + 300 + USA + BLUEVIOLET + + + Land Rover BAR + 500 + BAR + BLACK + + + SoftBank Team Japan + 400 + JAP + RED + + + Groupama Team France + 350 + FRN + ORANGE + + + Artemis Racing + 440 + ART + DARKOLIVEGREEN + + + Emirates Team New Zealand + 620 + ENZ + LIMEGREEN + + + + + Start to Mark 1 + + + 32.296577 + -64.854304 + + + + + 32.293039 + -64.843983 + + + + + Mark 1 to Leeward Gate + + + 32.293039 + -64.843983 + + + + + 32.309693 + -64.835249 + + + + + Leeward Gate to Windward Gate + + + 32.309693 + -64.835249 + + + + + 32.284680 + -64.850045 + + + + + Windward Gate to Leeward Gate + + + + 32.284680 + -64.850045 + + + + + + 32.309693 + -64.835249 + + + + + Leeward Gate to Finish + + + 32.309693 + -64.835249 + + + + + 32.317379 + -64.839291 + + + + + + + + 32.278 + -64.863 + + + 32.30989 + -64.821 + + + + Start Line + + 32.296577 + -64.854304 + + + 32.293771 + -64.855242 + + + + Mark + + 32.293039 + -64.843983 + + + + Windward Gate + + 32.284680 + -64.850045 + + + 32.280164 + -64.847591 + + + + Leeward Gate + + 32.309693 + -64.835249 + + + 32.308046 + -64.831785 + + + + Finish Line + + 32.317379 + -64.839291 + + + 32.317257 + -64.836260 + + + + From 288324ace6cbcacc30ada3fe8b9a50f228c382df Mon Sep 17 00:00:00 2001 From: Erika Savell Date: Wed, 22 Mar 2017 13:03:28 +1300 Subject: [PATCH 07/10] Back to string properties -Listeners were not working with getting values from existing properties #refactor #story[15] --- src/main/java/seng302/Model/BoatInRace.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/seng302/Model/BoatInRace.java b/src/main/java/seng302/Model/BoatInRace.java index 3e3a1065..a3de0ecb 100644 --- a/src/main/java/seng302/Model/BoatInRace.java +++ b/src/main/java/seng302/Model/BoatInRace.java @@ -20,6 +20,7 @@ public class BoatInRace extends Boat { private long timeFinished; private Color colour; private boolean finished = false; + private StringProperty currentLegName; /** * Constructor method. @@ -30,6 +31,7 @@ public class BoatInRace extends Boat { public BoatInRace(String name, double velocity, Color colour, String abbrev) { super(name, velocity, abbrev); setColour(colour); + currentLegName = new SimpleStringProperty(""); } /** @@ -90,14 +92,10 @@ public class BoatInRace extends Boat { */ public void setCurrentLeg(Leg currentLeg) { this.currentLeg = currentLeg; + this.currentLegName.setValue(currentLeg.getName()); } public StringProperty getCurrentLegName(){ - - StringProperty currentLegName = new SimpleStringProperty(""); - if (currentLeg != null) { - currentLegName.setValue(currentLeg.getName()); - } return currentLegName; } From df8b711cf504d1b33f30f36e177ce27ec4a0b6f0 Mon Sep 17 00:00:00 2001 From: Erika Savell Date: Wed, 22 Mar 2017 13:34:44 +1300 Subject: [PATCH 08/10] Tests for BoatInRace, imported Mockito #test #story[24] --- pom.xml | 9 ++ src/main/java/seng302/Model/Boat.java | 2 +- .../java/seng302/Model/BoatInRaceTest.java | 116 ++++++++++++++++++ 3 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 src/test/java/seng302/Model/BoatInRaceTest.java diff --git a/pom.xml b/pom.xml index 0cac5cc7..a3e030d6 100644 --- a/pom.xml +++ b/pom.xml @@ -21,8 +21,17 @@ gt-referencing 9.0 + + + + org.mockito + mockito-all + 1.9.5 + + + maven2-repository.dev.java.net diff --git a/src/main/java/seng302/Model/Boat.java b/src/main/java/seng302/Model/Boat.java index 4cd2503b..e2169e56 100644 --- a/src/main/java/seng302/Model/Boat.java +++ b/src/main/java/seng302/Model/Boat.java @@ -53,7 +53,7 @@ public class Boat { * @return The Name of the boat. */ public String toString(){ - return getName().getValue(); + return getName().toString(); } public StringProperty getVelocityProp() { diff --git a/src/test/java/seng302/Model/BoatInRaceTest.java b/src/test/java/seng302/Model/BoatInRaceTest.java new file mode 100644 index 00000000..74a01e52 --- /dev/null +++ b/src/test/java/seng302/Model/BoatInRaceTest.java @@ -0,0 +1,116 @@ +package seng302.Model; + +import javafx.scene.paint.Color; +import org.junit.Ignore; +import org.junit.Test; +import seng302.GPSCoordinate; + +import static junit.framework.TestCase.assertEquals; +import static junit.framework.TestCase.assertTrue; + +/** + * Created by esa46 on 22/03/17. + */ +public class BoatInRaceTest { + + + + @Test + public void calculateDueNorthAzimuthReturns0() { + BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt"); + GPSCoordinate startPoint = new GPSCoordinate(0, 0); + GPSCoordinate endPoint = new GPSCoordinate(50, 0); + Leg start = new Leg("Start", startPoint, endPoint, 0); + boat.setCurrentLeg(start); + assertEquals(boat.calculateAzimuth(), 0, 1e-8); + } + + @Test + public void calculateDueSouthAzimuthReturns180() { + BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt"); + GPSCoordinate startPoint = new GPSCoordinate(0, 0); + GPSCoordinate endPoint = new GPSCoordinate(-50, 0); + Leg start = new Leg("Start", startPoint, endPoint, 0); + boat.setCurrentLeg(start); + assertEquals(boat.calculateAzimuth(), 180, 1e-8); + } + + + @Test + public void calculateDueEastAzimuthReturns90() { + + BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt"); + GPSCoordinate startPoint = new GPSCoordinate(0, 0); + GPSCoordinate endPoint = new GPSCoordinate(0, 50); + Leg start = new Leg("Start", startPoint, endPoint, 0); + boat.setCurrentLeg(start); + assertEquals(boat.calculateAzimuth(), 90, 1e-8); + } + + + @Test + public void calculateDueWestAzimuthReturnsNegative90() { + BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt"); + GPSCoordinate startPoint = new GPSCoordinate(0, 0); + GPSCoordinate endPoint = new GPSCoordinate(0, -50); + Leg start = new Leg("Start", startPoint, endPoint, 0); + boat.setCurrentLeg(start); + assertEquals(boat.calculateAzimuth(), -90, 1e-8); + + } + + @Test + public void calculateDueNorthHeadingReturns0() { + BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt"); + GPSCoordinate startPoint = new GPSCoordinate(10, 0); + GPSCoordinate endPoint = new GPSCoordinate(50, 0); + Leg start = new Leg("Start", startPoint, endPoint, 0); + boat.setCurrentLeg(start); + assertEquals(boat.calculateHeading(), 0, 1e-8); + } + + @Test + public void calculateDueEastHeadingReturns90() { + BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt"); + GPSCoordinate startPoint = new GPSCoordinate(0, 0); + GPSCoordinate endPoint = new GPSCoordinate(0, 50); + Leg start = new Leg("Start", startPoint, endPoint, 0); + boat.setCurrentLeg(start); + assertEquals(boat.calculateHeading(), 90, 1e-8); + } + + @Test + public void calculateDueSouthHeadingReturns180() { + BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt"); + GPSCoordinate startPoint = new GPSCoordinate(10, 0); + GPSCoordinate endPoint = new GPSCoordinate(-50, 0); + Leg start = new Leg("Start", startPoint, endPoint, 0); + boat.setCurrentLeg(start); + assertEquals(boat.calculateHeading(), 180, 1e-8); + } + + @Test + public void calculateDueWestHeadingReturns270() { + BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt"); + GPSCoordinate startPoint = new GPSCoordinate(0, 10); + GPSCoordinate endPoint = new GPSCoordinate(0, -50); + Leg start = new Leg("Start", startPoint, endPoint, 0); + boat.setCurrentLeg(start); + assertEquals(boat.calculateHeading(), 270, 1e-8); + } + + @Test + public void createNewBoatCratesInstanceOfSuperClass() { + + BoatInRace testBoat = new BoatInRace("Boat", 20, Color.ALICEBLUE, "tt"); + testBoat.setName("Name can change"); + assertTrue(testBoat instanceof Boat); + assertTrue(testBoat.getCurrentLeg() == null); + assertTrue(testBoat.getCurrentPosition() == null); + assertTrue(testBoat.toString().contains("Name can change")); + assertEquals(testBoat.getVelocity(), 20.0); + //assertTrue(testBoat.getName().equals("Name can change")); + + } + +} \ No newline at end of file From 1c6bed7f37594857d765ceeb2333d9fd22ab66b4 Mon Sep 17 00:00:00 2001 From: Erika Savell Date: Wed, 22 Mar 2017 14:12:45 +1300 Subject: [PATCH 09/10] Tests for the Race class added -Mostly to do with checking positions and updating correctly #test #story 9 --- src/main/java/seng302/Model/Race.java | 1 + .../java/seng302/Model/BoatInRaceTest.java | 2 - src/test/java/seng302/Model/RaceTest.java | 57 +++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/main/java/seng302/Model/Race.java b/src/main/java/seng302/Model/Race.java index 7ae9f5c9..b44a0193 100644 --- a/src/main/java/seng302/Model/Race.java +++ b/src/main/java/seng302/Model/Race.java @@ -176,6 +176,7 @@ public abstract class Race implements Runnable { //boat has finished boatsFinished++; boat.setFinished(true); + boat.setTimeFinished(timeElapsed); } else { boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg() - boat.getCurrentLeg().getDistance()); Leg nextLeg = legs.get(boat.getCurrentLeg().getLegNumber() + 1); diff --git a/src/test/java/seng302/Model/BoatInRaceTest.java b/src/test/java/seng302/Model/BoatInRaceTest.java index 74a01e52..1e430be1 100644 --- a/src/test/java/seng302/Model/BoatInRaceTest.java +++ b/src/test/java/seng302/Model/BoatInRaceTest.java @@ -109,8 +109,6 @@ public class BoatInRaceTest { assertTrue(testBoat.getCurrentPosition() == null); assertTrue(testBoat.toString().contains("Name can change")); assertEquals(testBoat.getVelocity(), 20.0); - //assertTrue(testBoat.getName().equals("Name can change")); - } } \ No newline at end of file diff --git a/src/test/java/seng302/Model/RaceTest.java b/src/test/java/seng302/Model/RaceTest.java index b7a52d3d..efce5caf 100644 --- a/src/test/java/seng302/Model/RaceTest.java +++ b/src/test/java/seng302/Model/RaceTest.java @@ -14,6 +14,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Observable; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; /** @@ -41,4 +42,60 @@ public class RaceTest { for(int i = 0; i < boats.length; i++) assertTrue(boats[i].equals(race.getStartingBoats().get(i))); } + + + @Test + public void checkPositionUpdatesNumberFinishedBoats() { + + BoatInRace finishedBoat = new BoatInRace("Test", 1000, Color.ALICEBLUE, "tt"); + finishedBoat.setDistanceTravelledInLeg(500); + Leg leg = new Leg("Finish", new GPSCoordinate(0, 0), new GPSCoordinate(1, 1), 0); + finishedBoat.setCurrentLeg(leg); + + ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], new ArrayList()); + assertEquals(race.boatsFinished, 0); + + race.checkPosition(finishedBoat, 100); + assertEquals(race.boatsFinished, 1); + assertEquals(finishedBoat.getTimeFinished(), 100); + } + + @Test + public void checkPositionDoesntUpdateNumberFinishedBoats() { + + BoatInRace unFinishedBoat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt"); + unFinishedBoat.setDistanceTravelledInLeg(0); + Leg leg = new Leg("Finish", new GPSCoordinate(0, 0), new GPSCoordinate(1, 1), 0); + unFinishedBoat.setCurrentLeg(leg); + + ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], new ArrayList()); + assertEquals(race.boatsFinished, 0); + + race.checkPosition(unFinishedBoat, 100); + assertEquals(race.boatsFinished, 0); + } + + + @Test + public void distanceTravelledBeforeUpdatingLegIsRetained() { + + ArrayList legs = new ArrayList<>(); + + Leg leg1 = new Leg("1", new GPSCoordinate(0, 0), new GPSCoordinate(1, 1), 0); + Leg leg2 = new Leg("2", new GPSCoordinate(0, 0), new GPSCoordinate(1, 1), 1); + + legs.add(leg2); legs.add(leg2); + + ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs); + + BoatInRace unFinishedBoat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt"); + unFinishedBoat.setDistanceTravelledInLeg(100); + unFinishedBoat.setCurrentLeg(leg1); + + race.checkPosition(unFinishedBoat, 100); + assertEquals(unFinishedBoat.getCurrentLeg().getName(), "2"); + assertTrue(unFinishedBoat.getDistanceTravelledInLeg() > 0); + assertTrue(unFinishedBoat.getDistanceTravelledInLeg() < 100); + + } } From 4c82a4594e14c763b8dd8c0208a1604c16b9b4e3 Mon Sep 17 00:00:00 2001 From: Erika Savell Date: Thu, 23 Mar 2017 13:41:14 +1300 Subject: [PATCH 10/10] Added a small test for the timer function -More needed once scaling is in effect #test #story[16] --- src/main/java/seng302/Model/Race.java | 12 +++++++----- src/test/java/seng302/Model/RaceTest.java | 12 ++++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/main/java/seng302/Model/Race.java b/src/main/java/seng302/Model/Race.java index b44a0193..ed5131a0 100644 --- a/src/main/java/seng302/Model/Race.java +++ b/src/main/java/seng302/Model/Race.java @@ -25,7 +25,7 @@ public abstract class Race implements Runnable { private int SLEEP_TIME = 100; //time in milliseconds to pause in a paced loop - private int PRERACE_TIME = 10000;//Integer.MAX_VALUE; //time in milliseconds to pause during pre-race + protected int PRERACE_TIME = 10000;//Integer.MAX_VALUE; //time in milliseconds to pause during pre-race private boolean timerEnabled = true; /** @@ -80,7 +80,7 @@ public abstract class Race implements Runnable { } - private void countdownTimer() { + protected void countdownTimer() { long currentTime = System.currentTimeMillis(); long startTime = currentTime + PRERACE_TIME; long minutes; @@ -97,7 +97,9 @@ public abstract class Race implements Runnable { remainingSeconds = currentTimeInSeconds % 60; hours = minutes / 60; minutes = minutes % 60; - updateTime(String.format("Time until race starts: %02d:%02d:%02d", hours, minutes, remainingSeconds)); + if (controller != null) { + updateTime(String.format("Time until race starts: %02d:%02d:%02d", hours, minutes, remainingSeconds)); + } try { timeLoopEnded = System.currentTimeMillis(); Thread.sleep(SLEEP_TIME - (timeLoopEnded - currentTime)); @@ -108,7 +110,7 @@ public abstract class Race implements Runnable { } } - private String calcTimer() { + protected String calcTimer() { long minutes; long currentTimeInSeconds; long remainingSeconds; @@ -122,7 +124,7 @@ public abstract class Race implements Runnable { return String.format("Race clock: %02d:%02d:%02d", hours, minutes, remainingSeconds); } - private void updateTime(String time){ + protected void updateTime(String time){ Platform.runLater(() -> {controller.setTimer(time);}); } diff --git a/src/test/java/seng302/Model/RaceTest.java b/src/test/java/seng302/Model/RaceTest.java index efce5caf..5f71f764 100644 --- a/src/test/java/seng302/Model/RaceTest.java +++ b/src/test/java/seng302/Model/RaceTest.java @@ -98,4 +98,16 @@ public class RaceTest { assertTrue(unFinishedBoat.getDistanceTravelledInLeg() < 100); } + + @Test + public void timerDelaysByHalfSecond() { + ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], new ArrayList<>()); + race.PRERACE_TIME = 500; + + long timeStarted = System.currentTimeMillis(); + race.countdownTimer(); + + assertTrue(System.currentTimeMillis() - timeStarted > 500); + + } }