parent
74a9b1499c
commit
393fae2ec4
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in new issue