forked from dirkriehle/wahlzeit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Photo.location, Coordinate, CoordinateTest
- Loading branch information
Stefan Pfennig
committed
Oct 25, 2015
1 parent
3c24d48
commit fa601ce
Showing
4 changed files
with
209 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,9 @@ | |
/classes | ||
/src/main/webapp/WEB-INF/lib/ | ||
/.settings/ | ||
/WEB-INF/ | ||
*.iml | ||
.gradle | ||
.idea | ||
.project | ||
.classpath | ||
.classpath |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* | ||
*/ | ||
package org.wahlzeit.model; | ||
|
||
|
||
public class Coordinate | ||
{ | ||
private double latitude; | ||
private double longitude; | ||
|
||
Coordinate(double latitude, double longitude) | ||
{ | ||
if(boundsOK(latitude)) | ||
{ | ||
this.latitude = latitude; | ||
} | ||
if(boundsOK(longitude)) | ||
{ | ||
this.longitude = longitude; | ||
} | ||
} | ||
|
||
private boolean boundsOK(double var) | ||
{ | ||
if(-90 <= var && var <= 90) | ||
{ | ||
return true; | ||
} | ||
throw new IllegalArgumentException("-90 <= lat|lon <= 90"); | ||
} | ||
|
||
public double getLatitude() | ||
{ | ||
return latitude; | ||
} | ||
|
||
public double getLongitude() | ||
{ | ||
return longitude; | ||
} | ||
|
||
|
||
|
||
public double getLatitudinalDistance(Coordinate coordinate) | ||
{ | ||
return Math.abs(coordinate.getLatitude() - latitude); | ||
} | ||
|
||
public double getLongitudinalDistance(Coordinate coordinate) | ||
{ | ||
return Math.abs(coordinate.getLongitude() - longitude); | ||
} | ||
|
||
public Coordinate getDistance(Coordinate coordinate) | ||
{ | ||
return new Coordinate( getLatitudinalDistance(coordinate), | ||
getLongitudinalDistance(coordinate)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
|
||
package org.wahlzeit.model; | ||
|
||
import org.junit.Test; | ||
import org.junit.Before; | ||
import org.junit.Assert; | ||
|
||
/** | ||
* | ||
*/ | ||
public class CoordinateTest { | ||
private Coordinate testCoordinate; | ||
|
||
private Coordinate paramLessCoordinate; | ||
private Coordinate paramGreaterCoordinate; | ||
private Coordinate paramMixed1Coordinate; | ||
private Coordinate paramMixed2Coordinate; | ||
|
||
private final double Epsilon = 1e-5; | ||
|
||
|
||
@Before | ||
public void setUp() | ||
{ | ||
testCoordinate = new Coordinate(5.5, 5.5); | ||
|
||
paramLessCoordinate = new Coordinate(4.4, 4.4); | ||
paramGreaterCoordinate = new Coordinate(6.6, 6.6); | ||
paramMixed1Coordinate = new Coordinate(4.4, 6.6); | ||
paramMixed2Coordinate = new Coordinate(6.6, 4.4); | ||
} | ||
|
||
|
||
@Test | ||
public void testGetter() | ||
{ | ||
Assert.assertEquals(5.5, testCoordinate.getLatitude(), Epsilon); | ||
Assert.assertEquals(5.5, testCoordinate.getLongitude(), Epsilon); | ||
} | ||
|
||
@Test | ||
public void testLatitudeDistance() | ||
{ | ||
Assert.assertEquals(1.1, testCoordinate.getLatitudinalDistance(paramLessCoordinate), Epsilon); | ||
Assert.assertEquals(1.1, testCoordinate.getLatitudinalDistance(paramGreaterCoordinate), Epsilon); | ||
Assert.assertEquals(1.1, testCoordinate.getLatitudinalDistance(paramMixed1Coordinate), Epsilon); | ||
Assert.assertEquals(1.1, testCoordinate.getLatitudinalDistance(paramMixed2Coordinate), Epsilon); | ||
} | ||
|
||
@Test | ||
public void testLongitudeDistance() | ||
{ | ||
Assert.assertEquals(1.1, testCoordinate.getLongitudinalDistance(paramLessCoordinate), Epsilon); | ||
Assert.assertEquals(1.1, testCoordinate.getLatitudinalDistance(paramGreaterCoordinate), Epsilon); | ||
Assert.assertEquals(1.1, testCoordinate.getLatitudinalDistance(paramMixed1Coordinate), Epsilon); | ||
Assert.assertEquals(1.1, testCoordinate.getLatitudinalDistance(paramMixed2Coordinate), Epsilon); | ||
} | ||
|
||
@Test | ||
public void testDistance() | ||
{ | ||
Coordinate returnCoordinate; | ||
|
||
returnCoordinate = testCoordinate.getDistance(paramLessCoordinate); | ||
Assert.assertEquals(1.1, returnCoordinate.getLatitude(), Epsilon); | ||
Assert.assertEquals(1.1, returnCoordinate.getLongitude(), Epsilon); | ||
|
||
returnCoordinate = testCoordinate.getDistance(paramGreaterCoordinate); | ||
Assert.assertEquals(1.1, returnCoordinate.getLatitude(), Epsilon); | ||
Assert.assertEquals(1.1, returnCoordinate.getLongitude(), Epsilon); | ||
|
||
returnCoordinate = testCoordinate.getDistance(paramMixed1Coordinate); | ||
Assert.assertEquals(1.1, returnCoordinate.getLatitude(), Epsilon); | ||
Assert.assertEquals(1.1, returnCoordinate.getLongitude(), Epsilon); | ||
|
||
returnCoordinate = testCoordinate.getDistance(paramMixed2Coordinate); | ||
Assert.assertEquals(1.1, returnCoordinate.getLatitude(), Epsilon); | ||
Assert.assertEquals(1.1, returnCoordinate.getLongitude(), Epsilon); | ||
} | ||
|
||
@Test(expected = NullPointerException.class) | ||
public void testDistanceArgumentNull() | ||
{ | ||
testCoordinate.getDistance(null); | ||
} | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void testArgumentlessBoundaries() | ||
{ | ||
Coordinate c = new Coordinate(-90.1, -90.1); | ||
} | ||
@Test(expected = IllegalArgumentException.class) | ||
public void testArgumentGreaterBoundaries() | ||
{ | ||
Coordinate c = new Coordinate(90.1, 90.1); | ||
} | ||
@Test(expected = IllegalArgumentException.class) | ||
public void testArgumentMixed1Boundaries() | ||
{ | ||
Coordinate c = new Coordinate(-90.1, 0); | ||
} | ||
@Test(expected = IllegalArgumentException.class) | ||
public void testArgumentMixed2Boundaries() | ||
{ | ||
Coordinate c = new Coordinate(90.1, 0); | ||
} | ||
@Test(expected = IllegalArgumentException.class) | ||
public void testArgumentMixed3Boundaries() | ||
{ | ||
Coordinate c = new Coordinate(0, -90.1); | ||
} | ||
@Test(expected = IllegalArgumentException.class) | ||
public void testArgumentMixed4Boundaries() | ||
{ | ||
Coordinate c = new Coordinate(0, 90.1); | ||
} | ||
@Test(expected = IllegalArgumentException.class) | ||
public void testArgumentMixed5Boundaries() | ||
{ | ||
Coordinate cLess = new Coordinate(-90.1, 90.1); | ||
} | ||
@Test(expected = IllegalArgumentException.class) | ||
public void testArgumentMixed6Boundaries() | ||
{ | ||
Coordinate cLess = new Coordinate(90.1, -90.1); | ||
} | ||
} |