mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Added document and unit tests for GeoUtility class.
- three methods in GeoUtility have been tested and passed. #story[828]
This commit is contained in:
@@ -24,6 +24,4 @@ public class App extends Application
|
||||
new Thread(new Simulator(1000)).run();
|
||||
launch(args);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -33,8 +33,14 @@ public class GeoUtility {
|
||||
*
|
||||
* @param p1 the first geographical position, start point
|
||||
* @param p2 the second geographical position, end point
|
||||
* @return the bearing in degree from p1 to p2, value range (0 ~ 360 deg.).
|
||||
* @return the initial bearing in degree from p1 to p2, value range (0 ~ 360 deg.).
|
||||
* vertical up is 0 deg. horizontal right is 90 deg.
|
||||
*
|
||||
* NOTE:
|
||||
* The final bearing will differ from the initial bearing by varying degrees
|
||||
* according to distance and latitude (if you were to go from say 35°N,45°E
|
||||
* (≈ Baghdad) to 35°N,135°E (≈ Osaka), you would start on a heading of 60°
|
||||
* and end up on a heading of 120°
|
||||
*/
|
||||
public static Double getBearing(Position p1, Position p2) {
|
||||
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
package seng302.server.simulator;
|
||||
|
||||
import org.junit.Test;
|
||||
import seng302.server.simulator.mark.Position;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* To test methods in GeoUtility.
|
||||
* Created by Haoming on 28/04/17.
|
||||
*/
|
||||
public class GeoUtilityTest {
|
||||
|
||||
private Position p1 = new Position(57.670333, 11.827833);
|
||||
private Position p2 = new Position(57.671524, 11.844495);
|
||||
private Position p3 = new Position(57.670822, 11.843392);
|
||||
private Position p4 = new Position(25.694829, 98.392049);
|
||||
|
||||
private double toleranceRate = 0.01;
|
||||
|
||||
@Test
|
||||
public void getDistance() throws Exception {
|
||||
double expected, actual;
|
||||
|
||||
actual = GeoUtility.getDistance(p1, p2);
|
||||
expected = 1000;
|
||||
assertEquals(expected, actual, expected * toleranceRate);
|
||||
|
||||
actual = GeoUtility.getDistance(p1, p3);
|
||||
expected = 927;
|
||||
assertEquals(expected, actual, expected * toleranceRate);
|
||||
|
||||
actual = GeoUtility.getDistance(p2, p4);
|
||||
expected = 7430180;
|
||||
assertEquals(expected, actual, expected * toleranceRate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBearing() throws Exception {
|
||||
double expected, actual;
|
||||
|
||||
actual = GeoUtility.getBearing(p1, p2);
|
||||
expected = 82;
|
||||
assertEquals(expected, actual, expected * toleranceRate);
|
||||
|
||||
actual = GeoUtility.getBearing(p1, p3);
|
||||
expected = 86;
|
||||
assertEquals(expected, actual, expected * toleranceRate);
|
||||
|
||||
actual = GeoUtility.getBearing(p2, p4);
|
||||
expected = 78;
|
||||
assertEquals(expected, actual, expected * toleranceRate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getGeoCoordinate() throws Exception {
|
||||
Position expected, actual;
|
||||
|
||||
actual = GeoUtility.getGeoCoordinate(p1, 82.0, 1000.0);
|
||||
expected = p2;
|
||||
assertEquals(expected.getLat(), actual.getLat(), expected.getLat() * toleranceRate);
|
||||
assertEquals(expected.getLng(), actual.getLng(), expected.getLng() * toleranceRate);
|
||||
|
||||
actual = GeoUtility.getGeoCoordinate(p1, 86.0, 927.0);
|
||||
expected = p3;
|
||||
assertEquals(expected.getLat(), actual.getLat(), expected.getLat() * toleranceRate);
|
||||
assertEquals(expected.getLng(), actual.getLng(), expected.getLng() * toleranceRate);
|
||||
|
||||
actual = GeoUtility.getGeoCoordinate(p2, 78.0, 7430180.0);
|
||||
expected = p4;
|
||||
assertEquals(expected.getLat(), actual.getLat(), expected.getLat() * toleranceRate);
|
||||
assertEquals(expected.getLng(), actual.getLng(), expected.getLng() * toleranceRate);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user