epfl-archive/Alpano/tests/ch/epfl/alpano/GeoPointTest.java

69 lines
2.2 KiB
Java
Raw Permalink Normal View History

2022-04-07 18:43:21 +02:00
package ch.epfl.alpano;
import static org.junit.Assert.*;
import org.junit.Test;
public class GeoPointTest {
@Test(expected = IllegalArgumentException.class)
public void constructorLimitTest1(){
new GeoPoint(0, 2*Math.PI);
}
@Test(expected = IllegalArgumentException.class)
public void constructorLimitTest2(){
new GeoPoint(2*Math.PI, 2*Math.PI);
}
@Test(expected = IllegalArgumentException.class)
public void constructorLimitTest3(){
new GeoPoint(2*Math.PI, 0);
}
@Test
public void distanceToTest1(){
GeoPoint london = new GeoPoint(Math.toRadians(6.631), Math.toRadians(46.521));
GeoPoint moscow = new GeoPoint( Math.toRadians(37.623), Math.toRadians(55.753));
assertEquals(2367000, london.distanceTo(moscow), 1000);//1km imprecision
assertEquals(0,london.azimuthTo(london),0);
}
@Test
public void distanceToTest2(){
GeoPoint epfl = new GeoPoint(Math.toRadians(6.56730), Math.toRadians(46.51781));
GeoPoint eiler = new GeoPoint( Math.toRadians(8.00537), Math.toRadians(46.57756));
assertEquals(110294, epfl.distanceTo(eiler), 150);//150M imprecision
}
@Test
public void distanceToTest3(){
GeoPoint p1 = new GeoPoint(Math.PI,Math.PI/2.0);
GeoPoint p2 = new GeoPoint(Math.PI,Math.PI/2.0);
GeoPoint p3 = new GeoPoint(0,Math.PI/2.0);
GeoPoint p4 = new GeoPoint(Math.PI/10.0,Math.PI/2.0);
assertEquals(p3.distanceTo(p4), p4.distanceTo(p3), 10);
assertEquals(p2.distanceTo(p1), p1.distanceTo(p2), 10);
assertEquals(p3.distanceTo(p4), p1.distanceTo(p2), 10);
}
@Test
public void distanceToTest4(){
GeoPoint p1 = new GeoPoint(Math.PI/2.0,Math.PI/2.0);
GeoPoint p2 = new GeoPoint(-Math.PI/2.0,Math.PI/2.0);
GeoPoint p3 = new GeoPoint(-Math.PI/2.0,Math.PI/2.0);
GeoPoint p4 = new GeoPoint(Math.PI/10.0,Math.PI/2.0);
assertEquals(p3.distanceTo(p4), p4.distanceTo(p3), 10);
assertEquals(p2.distanceTo(p1), p1.distanceTo(p2), 10);
assertEquals(p3.distanceTo(p4), p1.distanceTo(p2), 10);
}
@Test
public void toStringTest(){
GeoPoint g = new GeoPoint(Math.toRadians(-7.6543), Math.toRadians(54.3210));
assertEquals("(-7.6543,54.3210)", g.toString());
}
}