Merge remote-tracking branch 'origin/story9' into story9
# Conflicts: # src/main/java/seng302/Constants.java # src/main/java/seng302/Model/Race.java # src/main/java/seng302/Model/ResizableRaceCanvas.java
This commit is contained in:
@@ -21,8 +21,17 @@
|
|||||||
<artifactId>gt-referencing</artifactId>
|
<artifactId>gt-referencing</artifactId>
|
||||||
<version>9.0</version>
|
<version>9.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-all -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-all</artifactId>
|
||||||
|
<version>1.9.5</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
<id>maven2-repository.dev.java.net</id>
|
<id>maven2-repository.dev.java.net</id>
|
||||||
|
|||||||
@@ -25,12 +25,12 @@ public class Constants {
|
|||||||
public static final GPSCoordinate finishLineMarker2 = new GPSCoordinate(32.317257, -64.836260);
|
public static final GPSCoordinate finishLineMarker2 = new GPSCoordinate(32.317257, -64.836260);
|
||||||
|
|
||||||
public static final BoatInRace[] OFFICIAL_AC35_COMPETITORS = new BoatInRace[]
|
public static final BoatInRace[] OFFICIAL_AC35_COMPETITORS = new BoatInRace[]
|
||||||
{new BoatInRace("Oracle Team USA", 700.0, Color.BLUEVIOLET, "USA"),
|
{new BoatInRace("Oracle Team USA", 300.0, Color.BLUEVIOLET, "USA"),
|
||||||
new BoatInRace("Land Rover BAR", 680.0, Color.BLACK, "BAR"),
|
new BoatInRace("Land Rover BAR", 500.0, Color.BLACK, "BAR"),
|
||||||
new BoatInRace("SoftBank Team Japan", 690.0, Color.RED, "JAP"),
|
new BoatInRace("SoftBank Team Japan", 400.0, Color.RED, "JAP"),
|
||||||
new BoatInRace("Groupama Team France", 710.0, Color.ORANGE, "FRN"),
|
new BoatInRace("Groupama Team France", 350.0, Color.ORANGE, "FRN"),
|
||||||
new BoatInRace("Artemis Racing", 720.0, Color.DARKOLIVEGREEN, "ART"),
|
new BoatInRace("Artemis Racing", 440.0, Color.DARKOLIVEGREEN, "ART"),
|
||||||
new BoatInRace("Emirates Team New Zealand", 810, Color.LIMEGREEN, "ENZ")};
|
new BoatInRace("Emirates Team New Zealand", 620, Color.LIMEGREEN, "ENZ")};
|
||||||
|
|
||||||
//public static final Leg bermudaCourseStartToMark1 = new Leg(0, , new )
|
//public static final Leg bermudaCourseStartToMark1 = new Leg(0, , new )
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public class Boat {
|
|||||||
* @return The Name of the boat.
|
* @return The Name of the boat.
|
||||||
*/
|
*/
|
||||||
public String toString(){
|
public String toString(){
|
||||||
return getName().getValue();
|
return getName().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public StringProperty getVelocityProp() {
|
public StringProperty getVelocityProp() {
|
||||||
|
|||||||
@@ -132,19 +132,39 @@ public class BoatInRace extends Boat {
|
|||||||
this.finished = bool;
|
this.finished = bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the bearing of the travel via map coordinates of the raceMarkers
|
* Calculates the azimuth of the travel via map coordinates of the raceMarkers
|
||||||
* @return the heading that the boat is heading towards in degrees.
|
* @return the direction that the boat is heading towards in degrees (-180 to 180).
|
||||||
*/
|
*/
|
||||||
public double calculateAzimuth(){
|
public double calculateAzimuth(){
|
||||||
//to be changed to coordinates when used to match reality.
|
|
||||||
GeodeticCalculator calc = new GeodeticCalculator();
|
GeodeticCalculator calc = new GeodeticCalculator();
|
||||||
calc.setStartingGeographicPoint(currentLeg.getStartGraphCoordinate().getLongitude(), currentLeg.getStartGraphCoordinate().getLatitude());
|
calc.setStartingGeographicPoint(currentLeg.getStartGraphCoordinate().getLongitude(), currentLeg.getStartGraphCoordinate().getLatitude());
|
||||||
calc.setDestinationGeographicPoint(currentLeg.getEndGraphCoordinate().getLongitude(), currentLeg.getEndGraphCoordinate().getLatitude());
|
calc.setDestinationGeographicPoint(currentLeg.getEndGraphCoordinate().getLongitude(), currentLeg.getEndGraphCoordinate().getLatitude());
|
||||||
|
|
||||||
return calc.getAzimuth();
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import java.util.ArrayList;
|
|||||||
* Created by cbt24 on 6/03/17.
|
* Created by cbt24 on 6/03/17.
|
||||||
*/
|
*/
|
||||||
public class ConstantVelocityRace extends Race {
|
public class ConstantVelocityRace extends Race {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialiser for a Race with constant velocity.
|
* Initialiser for a Race with constant velocity.
|
||||||
* @param startingBoats array of boats
|
* @param startingBoats array of boats
|
||||||
@@ -35,13 +36,13 @@ public class ConstantVelocityRace extends Race {
|
|||||||
double distanceTravelled = boat.getVelocity() * millisecondsElapsed/3600000;
|
double distanceTravelled = boat.getVelocity() * millisecondsElapsed/3600000;
|
||||||
double totalDistanceTravelled = distanceTravelled + boat.getDistanceTravelledInLeg();
|
double totalDistanceTravelled = distanceTravelled + boat.getDistanceTravelledInLeg();
|
||||||
|
|
||||||
if (!boat.getCurrentLeg().getName().equals("Finish")) {
|
boolean finish = boat.getCurrentLeg().getName().equals("Finish");
|
||||||
|
if (!finish) {
|
||||||
|
|
||||||
boat.setDistanceTravelledInLeg(totalDistanceTravelled);
|
boat.setDistanceTravelledInLeg(totalDistanceTravelled);
|
||||||
boat.setCurrentPosition(calculatePosition(boat.getCurrentLeg().getStartGraphCoordinate(),
|
boat.setCurrentPosition(calculatePosition(boat.getCurrentLeg().getStartGraphCoordinate(),
|
||||||
totalDistanceTravelled, boat.calculateAzimuth()));
|
totalDistanceTravelled, boat.calculateAzimuth()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -55,15 +55,6 @@ public class Leg {
|
|||||||
return distance;
|
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.
|
* Returns the coordinates in GPSCoordinate class of the boats starting coordinate.
|
||||||
* @return Returns the coordinate of the start of the leg.
|
* @return Returns the coordinate of the start of the leg.
|
||||||
@@ -101,5 +92,6 @@ public class Leg {
|
|||||||
calc.setStartingGeographicPoint(startGPSCoordinate.getLongitude(), startGPSCoordinate.getLatitude());
|
calc.setStartingGeographicPoint(startGPSCoordinate.getLongitude(), startGPSCoordinate.getLatitude());
|
||||||
calc.setDestinationGeographicPoint(endGPSCoordinate.getLongitude(), endGPSCoordinate.getLatitude());
|
calc.setDestinationGeographicPoint(endGPSCoordinate.getLongitude(), endGPSCoordinate.getLatitude());
|
||||||
return calc.getOrthodromicDistance() / Constants.NMToMetersConversion;
|
return calc.getOrthodromicDistance() / Constants.NMToMetersConversion;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ public abstract class Race implements Runnable {
|
|||||||
protected long totalTimeElapsed;
|
protected long totalTimeElapsed;
|
||||||
|
|
||||||
|
|
||||||
private int SLEEP_TIME = 25; //time in milliseconds to pause in a paced loop
|
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;
|
private boolean timerEnabled = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -86,7 +86,7 @@ public abstract class Race implements Runnable {
|
|||||||
/**
|
/**
|
||||||
* Countdown timer until race starts. Use PRERACE_TIME to set countdown duration.
|
* Countdown timer until race starts. Use PRERACE_TIME to set countdown duration.
|
||||||
*/
|
*/
|
||||||
private void countdownTimer() {
|
protected void countdownTimer() {
|
||||||
long currentTime = System.currentTimeMillis();
|
long currentTime = System.currentTimeMillis();
|
||||||
long startTime = currentTime + PRERACE_TIME;
|
long startTime = currentTime + PRERACE_TIME;
|
||||||
long minutes;
|
long minutes;
|
||||||
@@ -103,7 +103,9 @@ public abstract class Race implements Runnable {
|
|||||||
remainingSeconds = currentTimeInSeconds % 60;
|
remainingSeconds = currentTimeInSeconds % 60;
|
||||||
hours = minutes / 60;
|
hours = minutes / 60;
|
||||||
minutes = minutes % 60;
|
minutes = minutes % 60;
|
||||||
|
if (controller != null) {
|
||||||
updateTime(String.format("Time until race starts: %02d:%02d:%02d", hours, minutes, remainingSeconds));
|
updateTime(String.format("Time until race starts: %02d:%02d:%02d", hours, minutes, remainingSeconds));
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
timeLoopEnded = System.currentTimeMillis();
|
timeLoopEnded = System.currentTimeMillis();
|
||||||
Thread.sleep(SLEEP_TIME - (timeLoopEnded - currentTime));
|
Thread.sleep(SLEEP_TIME - (timeLoopEnded - currentTime));
|
||||||
@@ -118,7 +120,7 @@ public abstract class Race implements Runnable {
|
|||||||
* Takes total time elapsed and format to hour:minute:second
|
* Takes total time elapsed and format to hour:minute:second
|
||||||
* @return Formatted time as string
|
* @return Formatted time as string
|
||||||
*/
|
*/
|
||||||
private String calcTimer() {
|
protected String calcTimer() {
|
||||||
long minutes;
|
long minutes;
|
||||||
long currentTimeInSeconds;
|
long currentTimeInSeconds;
|
||||||
long remainingSeconds;
|
long remainingSeconds;
|
||||||
@@ -136,7 +138,7 @@ public abstract class Race implements Runnable {
|
|||||||
* Updates the calculated time to the timer label
|
* Updates the calculated time to the timer label
|
||||||
* @param time The calculated time from calcTimer() method
|
* @param time The calculated time from calcTimer() method
|
||||||
*/
|
*/
|
||||||
private void updateTime(String time){
|
protected void updateTime(String time){
|
||||||
Platform.runLater(() -> {controller.setTimer(time);});
|
Platform.runLater(() -> {controller.setTimer(time);});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,11 +211,13 @@ public abstract class Race implements Runnable {
|
|||||||
*/
|
*/
|
||||||
protected void checkPosition(BoatInRace boat, long timeElapsed) {
|
protected void checkPosition(BoatInRace boat, long timeElapsed) {
|
||||||
if (boat.getDistanceTravelledInLeg() > boat.getCurrentLeg().getDistance()){
|
if (boat.getDistanceTravelledInLeg() > boat.getCurrentLeg().getDistance()){
|
||||||
|
// updateController();
|
||||||
//boat has passed onto new leg
|
//boat has passed onto new leg
|
||||||
if (boat.getCurrentLeg().getName().equals("Finish")) {
|
if (boat.getCurrentLeg().getName().equals("Finish")) {
|
||||||
//boat has finished
|
//boat has finished
|
||||||
boatsFinished++;
|
boatsFinished++;
|
||||||
boat.setFinished(true);
|
boat.setFinished(true);
|
||||||
|
boat.setTimeFinished(timeElapsed);
|
||||||
} else {
|
} else {
|
||||||
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg() - boat.getCurrentLeg().getDistance());
|
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg() - boat.getCurrentLeg().getDistance());
|
||||||
Leg nextLeg = legs.get(boat.getCurrentLeg().getLegNumber() + 1);
|
Leg nextLeg = legs.get(boat.getCurrentLeg().getLegNumber() + 1);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package seng302.Model;
|
package seng302.Model;
|
||||||
|
|
||||||
import com.sun.xml.internal.bind.v2.runtime.reflect.opt.Const;
|
|
||||||
import javafx.scene.canvas.Canvas;
|
import javafx.scene.canvas.Canvas;
|
||||||
import javafx.scene.canvas.GraphicsContext;
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
@@ -25,8 +25,6 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
private GraphicsContext gc;
|
private GraphicsContext gc;
|
||||||
private RaceMap map;
|
private RaceMap map;
|
||||||
private BoatInRace[] boats;
|
private BoatInRace[] boats;
|
||||||
private Graphics graphics;
|
|
||||||
private Font font;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the boats that are to be displayed in this race.
|
* Sets the boats that are to be displayed in this race.
|
||||||
@@ -154,8 +152,6 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
*/
|
*/
|
||||||
public void drawRaceMap() {
|
public void drawRaceMap() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
double width = getWidth();
|
double width = getWidth();
|
||||||
double height = getHeight();
|
double height = getHeight();
|
||||||
|
|
||||||
@@ -187,12 +183,13 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
|
|
||||||
displayLine(startline1, startline2, Color.GREEN);
|
displayLine(startline1, startline2, Color.GREEN);
|
||||||
|
|
||||||
|
|
||||||
if (boats != null) {
|
if (boats != null) {
|
||||||
for (BoatInRace boat : boats) {
|
for (BoatInRace boat : boats) {
|
||||||
if (boat != null) {
|
if (boat != null) {
|
||||||
// System.out.print("Drawing Boat At: " + boat.getCurrentPosition());
|
// System.out.print("Drawing Boat At: " + boat.getCurrentPosition());
|
||||||
displayMark(this.map.convertGPS(boat.getCurrentPosition()), boat.getColour());
|
displayMark(this.map.convertGPS(boat.getCurrentPosition()), boat.getColour());
|
||||||
displayText(boat.getName().getValue(), boat.getVelocity()* 1.94384, this.map.convertGPS(boat.getCurrentPosition()));
|
displayText(boat.getAbbrev(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,182 @@
|
|||||||
|
<race>
|
||||||
|
<boats>
|
||||||
|
<boat>
|
||||||
|
<name>ORACLE TEAM USA</name>
|
||||||
|
<speed>300</speed>
|
||||||
|
<abbr>USA</abbr>
|
||||||
|
<colour>BLUEVIOLET</colour>
|
||||||
|
</boat>
|
||||||
|
<boat>
|
||||||
|
<name>Land Rover BAR</name>
|
||||||
|
<speed>500</speed>
|
||||||
|
<abbr>BAR</abbr>
|
||||||
|
<colour>BLACK</colour>
|
||||||
|
</boat>
|
||||||
|
<boat>
|
||||||
|
<name>SoftBank Team Japan</name>
|
||||||
|
<speed>400</speed>
|
||||||
|
<abbr>JAP</abbr>
|
||||||
|
<colour>RED</colour>
|
||||||
|
</boat>
|
||||||
|
<boat>
|
||||||
|
<name>Groupama Team France</name>
|
||||||
|
<speed>350</speed>
|
||||||
|
<abbr>FRN</abbr>
|
||||||
|
<colour>ORANGE</colour>
|
||||||
|
</boat>
|
||||||
|
<boat>
|
||||||
|
<name>Artemis Racing</name>
|
||||||
|
<speed>440</speed>
|
||||||
|
<abbr>ART</abbr>
|
||||||
|
<colour>DARKOLIVEGREEN</colour>
|
||||||
|
</boat>
|
||||||
|
<boat>
|
||||||
|
<name>Emirates Team New Zealand</name>
|
||||||
|
<speed>620</speed>
|
||||||
|
<abbr>ENZ</abbr>
|
||||||
|
<colour>LIMEGREEN</colour>
|
||||||
|
</boat>
|
||||||
|
</boats>
|
||||||
|
<legs>
|
||||||
|
<leg>
|
||||||
|
<name>Start to Mark 1</name>
|
||||||
|
<start>
|
||||||
|
<coordinate>
|
||||||
|
<latitude>32.296577</latitude>
|
||||||
|
<longitude>-64.854304</longitude>
|
||||||
|
</coordinate>
|
||||||
|
</start>
|
||||||
|
<finish>
|
||||||
|
<coordinate>
|
||||||
|
<latitude>32.293039</latitude>
|
||||||
|
<longitude>-64.843983</longitude>
|
||||||
|
</coordinate>
|
||||||
|
</finish>
|
||||||
|
</leg>
|
||||||
|
<leg>
|
||||||
|
<name>Mark 1 to Leeward Gate</name>
|
||||||
|
<start>
|
||||||
|
<coordinate>
|
||||||
|
<latitude>32.293039</latitude>
|
||||||
|
<longitude>-64.843983</longitude>
|
||||||
|
</coordinate>
|
||||||
|
</start>
|
||||||
|
<finish>
|
||||||
|
<coordinate>
|
||||||
|
<latitude>32.309693</latitude>
|
||||||
|
<longitude>-64.835249</longitude>
|
||||||
|
</coordinate>
|
||||||
|
</finish>
|
||||||
|
</leg>
|
||||||
|
<leg>
|
||||||
|
<name>Leeward Gate to Windward Gate</name>
|
||||||
|
<start>
|
||||||
|
<coordinate>
|
||||||
|
<latitude>32.309693</latitude>
|
||||||
|
<longitude>-64.835249</longitude>
|
||||||
|
</coordinate>
|
||||||
|
</start>
|
||||||
|
<finish>
|
||||||
|
<coordinate>
|
||||||
|
<latitude>32.284680</latitude>
|
||||||
|
<longitude>-64.850045</longitude>
|
||||||
|
</coordinate>
|
||||||
|
</finish>
|
||||||
|
</leg>
|
||||||
|
<leg>
|
||||||
|
<name>Windward Gate to Leeward Gate</name>
|
||||||
|
<start>
|
||||||
|
<coordinate>
|
||||||
|
<coordinate>
|
||||||
|
<latitude>32.284680</latitude>
|
||||||
|
<longitude>-64.850045</longitude>
|
||||||
|
</coordinate>
|
||||||
|
</coordinate>
|
||||||
|
</start>
|
||||||
|
<finish>
|
||||||
|
<coordinate>
|
||||||
|
<latitude>32.309693</latitude>
|
||||||
|
<longitude>-64.835249</longitude>
|
||||||
|
</coordinate>
|
||||||
|
</finish>
|
||||||
|
</leg>
|
||||||
|
<leg>
|
||||||
|
<name>Leeward Gate to Finish</name>
|
||||||
|
<start>
|
||||||
|
<coordinate>
|
||||||
|
<latitude>32.309693</latitude>
|
||||||
|
<longitude>-64.835249</longitude>
|
||||||
|
</coordinate>
|
||||||
|
</start>
|
||||||
|
<finish>
|
||||||
|
<coordinate>
|
||||||
|
<latitude>32.317379</latitude>
|
||||||
|
<longitude>-64.839291</longitude>
|
||||||
|
</coordinate>
|
||||||
|
</finish>
|
||||||
|
</leg>
|
||||||
|
</legs>
|
||||||
|
<course>
|
||||||
|
<boundaries>
|
||||||
|
<coordinate>
|
||||||
|
<latitude>32.278</latitude>
|
||||||
|
<longitude>-64.863</longitude>
|
||||||
|
</coordinate>
|
||||||
|
<coordinate>
|
||||||
|
<latitude>32.30989</latitude>
|
||||||
|
<longitude>-64.821</longitude>
|
||||||
|
</coordinate>
|
||||||
|
</boundaries>
|
||||||
|
<marker>
|
||||||
|
<name>Start Line</name>
|
||||||
|
<coordinate>
|
||||||
|
<latitude>32.296577</latitude>
|
||||||
|
<longitude>-64.854304</longitude>
|
||||||
|
</coordinate>
|
||||||
|
<coordinate>
|
||||||
|
<latitude>32.293771</latitude>
|
||||||
|
<longitude>-64.855242</longitude>
|
||||||
|
</coordinate>
|
||||||
|
</marker>
|
||||||
|
<marker>
|
||||||
|
<name>Mark</name>
|
||||||
|
<coordinate>
|
||||||
|
<latitude>32.293039</latitude>
|
||||||
|
<longitude>-64.843983</longitude>
|
||||||
|
</coordinate>
|
||||||
|
</marker>
|
||||||
|
<marker>
|
||||||
|
<name>Windward Gate</name>
|
||||||
|
<coordinate>
|
||||||
|
<latitude>32.284680</latitude>
|
||||||
|
<longitude>-64.850045</longitude>
|
||||||
|
</coordinate>
|
||||||
|
<coordinate>
|
||||||
|
<latitude>32.280164</latitude>
|
||||||
|
<longitude>-64.847591</longitude>
|
||||||
|
</coordinate>
|
||||||
|
</marker>
|
||||||
|
<marker>
|
||||||
|
<name>Leeward Gate</name>
|
||||||
|
<coordinate>
|
||||||
|
<latitude>32.309693</latitude>
|
||||||
|
<longitude>-64.835249</longitude>
|
||||||
|
</coordinate>
|
||||||
|
<coordinate>
|
||||||
|
<latitude>32.308046</latitude>
|
||||||
|
<longitude>-64.831785</longitude>
|
||||||
|
</coordinate>
|
||||||
|
</marker>
|
||||||
|
<marker>
|
||||||
|
<name>Finish Line</name>
|
||||||
|
<coordinate>
|
||||||
|
<latitude>32.317379</latitude>
|
||||||
|
<longitude>-64.839291</longitude>
|
||||||
|
</coordinate>
|
||||||
|
<coordinate>
|
||||||
|
<latitude>32.317257</latitude>
|
||||||
|
<longitude>-64.836260</longitude>
|
||||||
|
</coordinate>
|
||||||
|
</marker>
|
||||||
|
</course>
|
||||||
|
</race>
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,10 +1,15 @@
|
|||||||
package seng302.Model;
|
package seng302.Model;
|
||||||
|
|
||||||
|
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
import org.geotools.referencing.GeodeticCalculator;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.opengis.geometry.coordinate.Geodesic;
|
||||||
|
import seng302.Constants;
|
||||||
import seng302.GPSCoordinate;
|
import seng302.GPSCoordinate;
|
||||||
|
|
||||||
import java.awt.geom.Point2D;
|
import java.awt.geom.Point2D;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
@@ -13,12 +18,112 @@ import static org.junit.Assert.assertEquals;
|
|||||||
*/
|
*/
|
||||||
public class ConstantVelocityRaceTest {
|
public class ConstantVelocityRaceTest {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void travelling5nmNorthGivesCorrectNewCoordinates() {
|
public void updatePositionChangesDistanceTravelled() {
|
||||||
GPSCoordinate oldPos = new GPSCoordinate(0, 0);
|
|
||||||
GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 5, 0);
|
BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
|
||||||
// assertEquals(newPos.getLatitude(), 0.08374461297528203, );
|
Leg start = new Leg("Start", new GPSCoordinate(0, 0), new GPSCoordinate(50, 50), 0);
|
||||||
// assertEquals(ConstantVelocityRace.calculatePosition(oldPos, 5, 90).getLatitude(), 0.08, 1e-1);
|
boat.setCurrentLeg(start);
|
||||||
System.out.println(ConstantVelocityRace.calculatePosition(oldPos, 5, 0).getLongitude());
|
boat.setDistanceTravelledInLeg(0);
|
||||||
|
int timeElapsed = 3600000; //1 hr
|
||||||
|
|
||||||
|
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], new ArrayList<Leg>());
|
||||||
|
|
||||||
|
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<Leg>());
|
||||||
|
|
||||||
|
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<Leg>());
|
||||||
|
|
||||||
|
race.updatePosition(boat, timeElapsed);
|
||||||
|
assertEquals(boat.getDistanceTravelledInLeg(), boat.getVelocity() * timeElapsed / 3600000 + 50, 1e-8);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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 travelling10nmEastGivesCorrectNewCoordinates() {
|
||||||
|
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 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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Observable;
|
import java.util.Observable;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -22,31 +23,6 @@ import static org.junit.Assert.assertTrue;
|
|||||||
public class RaceTest {
|
public class RaceTest {
|
||||||
|
|
||||||
|
|
||||||
// @Ignore
|
|
||||||
// @Test
|
|
||||||
// public void singleBoatRaceRunsAndFinishes(){
|
|
||||||
//
|
|
||||||
// BoatInRace boat = new BoatInRace("NZ", 240);
|
|
||||||
// ArrayList<BoatInRace> boats = new ArrayList<>();
|
|
||||||
// boats.add(boat);
|
|
||||||
// ArrayList<Leg> 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<Leg> legs = new ArrayList<>();
|
|
||||||
// legs.add(leg1);
|
|
||||||
// ConstantVelocityRace race = new ConstantVelocityRace(boats, legs);
|
|
||||||
// race.run();
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void finishOrderDeterminedByVelocity() {
|
public void finishOrderDeterminedByVelocity() {
|
||||||
BoatInRace[] boats = {
|
BoatInRace[] boats = {
|
||||||
@@ -66,4 +42,72 @@ public class RaceTest {
|
|||||||
for(int i = 0; i < boats.length; i++)
|
for(int i = 0; i < boats.length; i++)
|
||||||
assertTrue(boats[i].equals(race.getStartingBoats().get(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<Leg>());
|
||||||
|
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<Leg>());
|
||||||
|
assertEquals(race.boatsFinished, 0);
|
||||||
|
|
||||||
|
race.checkPosition(unFinishedBoat, 100);
|
||||||
|
assertEquals(race.boatsFinished, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void distanceTravelledBeforeUpdatingLegIsRetained() {
|
||||||
|
|
||||||
|
ArrayList<Leg> 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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user