Tests for genreating new coordinate added

#test #story[9]
This commit is contained in:
Erika Savell
2017-03-22 10:07:14 +13:00
parent 7778e7d2b1
commit 0387bdc597
4 changed files with 78 additions and 15 deletions
@@ -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);
}
}