Skip to content

Commit b07797c

Browse files
authored
Add unit tests for DistanceCalculator (#44)
1 parent 3ffdaf2 commit b07797c

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.nitri.opentopo
2+
3+
import org.junit.Assert.assertEquals
4+
import org.junit.Test
5+
import org.nitri.opentopo.util.DistanceCalculator
6+
7+
class DistanceCalculatorTest {
8+
9+
@Test
10+
fun distanceReturnsZeroForIdenticalPoints() {
11+
val latitude = 48.8566
12+
val longitude = 2.3522
13+
14+
val distance = DistanceCalculator.distance(latitude, longitude, latitude, longitude)
15+
16+
assertEquals(0.0, distance, 0.0)
17+
}
18+
19+
@Test
20+
fun distanceMatchesExpectedValueForKnownCoordinates() {
21+
val parisLat = 48.8566
22+
val parisLon = 2.3522
23+
val londonLat = 51.5074
24+
val londonLon = -0.1278
25+
26+
val distance = DistanceCalculator.distance(parisLat, parisLon, londonLat, londonLon)
27+
28+
val expectedDistanceMeters = 343_556.0
29+
val toleranceMeters = 1_000.0
30+
31+
assertEquals(expectedDistanceMeters, distance, toleranceMeters)
32+
}
33+
}

0 commit comments

Comments
 (0)