|
| 1 | +package fr.free.nrw.commons; |
| 2 | + |
| 3 | +import static org.hamcrest.CoreMatchers.is; |
| 4 | + |
| 5 | +import fr.free.nrw.commons.location.LatLng; |
| 6 | +import fr.free.nrw.commons.utils.LengthUtils; |
| 7 | + |
| 8 | +import org.junit.Assert; |
| 9 | +import org.junit.Test; |
| 10 | + |
| 11 | +public class LengthUtilsTest { |
| 12 | + @Test public void testZeroDistance() { |
| 13 | + LatLng pointA = new LatLng(0, 0); |
| 14 | + LatLng pointB = new LatLng(0, 0); |
| 15 | + String distance = LengthUtils.formatDistanceBetween(pointA, pointB); |
| 16 | + Assert.assertThat(distance, is("0m")); |
| 17 | + } |
| 18 | + |
| 19 | + @Test public void testOneDegreeOnEquator() { |
| 20 | + LatLng pointA = new LatLng(0, 0); |
| 21 | + LatLng pointB = new LatLng(0, 1); |
| 22 | + String distance = LengthUtils.formatDistanceBetween(pointA, pointB); |
| 23 | + Assert.assertThat(distance, is("111.2km")); |
| 24 | + } |
| 25 | + |
| 26 | + @Test public void testOneDegreeFortyFiveDegrees() { |
| 27 | + LatLng pointA = new LatLng(45, 0); |
| 28 | + LatLng pointB = new LatLng(45, 1); |
| 29 | + String distance = LengthUtils.formatDistanceBetween(pointA, pointB); |
| 30 | + Assert.assertThat(distance, is("78.6km")); |
| 31 | + } |
| 32 | + |
| 33 | + @Test public void testOneDegreeSouthPole() { |
| 34 | + LatLng pointA = new LatLng(-90, 0); |
| 35 | + LatLng pointB = new LatLng(-90, 1); |
| 36 | + String distance = LengthUtils.formatDistanceBetween(pointA, pointB); |
| 37 | + Assert.assertThat(distance, is("0m")); |
| 38 | + } |
| 39 | + |
| 40 | + @Test public void testPoleToPole() { |
| 41 | + LatLng pointA = new LatLng(90, 0); |
| 42 | + LatLng pointB = new LatLng(-90, 0); |
| 43 | + String distance = LengthUtils.formatDistanceBetween(pointA, pointB); |
| 44 | + Assert.assertThat(distance, is("20,015.1km")); |
| 45 | + } |
| 46 | +} |
0 commit comments