mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Add some tests for the LengthUtils class
Currently the LengthUtils class has no tests. This commit adds some basic tests for the distance computations.
This commit is contained in:
parent
19eddb7d26
commit
d5bba99faa
1 changed files with 46 additions and 0 deletions
46
app/src/test/java/fr/free/nrw/commons/LengthUtilsTest.java
Normal file
46
app/src/test/java/fr/free/nrw/commons/LengthUtilsTest.java
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
package fr.free.nrw.commons;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
|
||||
import fr.free.nrw.commons.location.LatLng;
|
||||
import fr.free.nrw.commons.utils.LengthUtils;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class LengthUtilsTest {
|
||||
@Test public void testZeroDistance() {
|
||||
LatLng pointA = new LatLng(0, 0);
|
||||
LatLng pointB = new LatLng(0, 0);
|
||||
String distance = LengthUtils.formatDistanceBetween(pointA, pointB);
|
||||
Assert.assertThat(distance, is("0m"));
|
||||
}
|
||||
|
||||
@Test public void testOneDegreeOnEquator() {
|
||||
LatLng pointA = new LatLng(0, 0);
|
||||
LatLng pointB = new LatLng(0, 1);
|
||||
String distance = LengthUtils.formatDistanceBetween(pointA, pointB);
|
||||
Assert.assertThat(distance, is("111.2km"));
|
||||
}
|
||||
|
||||
@Test public void testOneDegreeFortyFiveDegrees() {
|
||||
LatLng pointA = new LatLng(45, 0);
|
||||
LatLng pointB = new LatLng(45, 1);
|
||||
String distance = LengthUtils.formatDistanceBetween(pointA, pointB);
|
||||
Assert.assertThat(distance, is("78.6km"));
|
||||
}
|
||||
|
||||
@Test public void testOneDegreeSouthPole() {
|
||||
LatLng pointA = new LatLng(-90, 0);
|
||||
LatLng pointB = new LatLng(-90, 1);
|
||||
String distance = LengthUtils.formatDistanceBetween(pointA, pointB);
|
||||
Assert.assertThat(distance, is("0m"));
|
||||
}
|
||||
|
||||
@Test public void testPoleToPole() {
|
||||
LatLng pointA = new LatLng(90, 0);
|
||||
LatLng pointB = new LatLng(-90, 0);
|
||||
String distance = LengthUtils.formatDistanceBetween(pointA, pointB);
|
||||
Assert.assertThat(distance, is("20,015.1km"));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue