Tests for genreating new coordinate added
#test #story[9]
This commit is contained in:
@@ -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 )
|
||||
}
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 travelling5nmNorthGivesCorrectNewCoordinates() {
|
||||
public void travelling10nmNorthGivesCorrectNewCoordinates() {
|
||||
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, 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user