mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Fix lat-long format and add tests
Currently the lat-long string in the gallery still contains negative numbers. Also W values do not work correctly. This commit fixes the calculations and adds tests for the LatLng class.
This commit is contained in:
parent
825cdafe7b
commit
bc60cff5fe
2 changed files with 70 additions and 3 deletions
64
app/src/test/java/fr/free/nrw/commons/LatLngTests.java
Normal file
64
app/src/test/java/fr/free/nrw/commons/LatLngTests.java
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
package fr.free.nrw.commons;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import fr.free.nrw.commons.location.LatLng;
|
||||
|
||||
public class LatLngTests {
|
||||
@Test public void testZeroZero() {
|
||||
LatLng place = new LatLng(0, 0);
|
||||
String prettyString = place.getPrettyCoordinateString();
|
||||
Assert.assertThat(prettyString, is("0.0 N, 0.0 E"));
|
||||
}
|
||||
|
||||
@Test public void testAntipode() {
|
||||
LatLng place = new LatLng(0, 180);
|
||||
String prettyString = place.getPrettyCoordinateString();
|
||||
Assert.assertThat(prettyString, is("0.0 N, 180.0 W"));
|
||||
}
|
||||
|
||||
@Test public void testNorthPole() {
|
||||
LatLng place = new LatLng(90, 0);
|
||||
String prettyString = place.getPrettyCoordinateString();
|
||||
Assert.assertThat(prettyString, is("90.0 N, 0.0 E"));
|
||||
}
|
||||
|
||||
@Test public void testSouthPole() {
|
||||
LatLng place = new LatLng(-90, 0);
|
||||
String prettyString = place.getPrettyCoordinateString();
|
||||
Assert.assertThat(prettyString, is("90.0 S, 0.0 E"));
|
||||
}
|
||||
|
||||
@Test public void testLargerNumbers() {
|
||||
LatLng place = new LatLng(120, 380);
|
||||
String prettyString = place.getPrettyCoordinateString();
|
||||
Assert.assertThat(prettyString, is("90.0 N, 20.0 E"));
|
||||
}
|
||||
|
||||
@Test public void testNegativeNumbers() {
|
||||
LatLng place = new LatLng(-120, -30);
|
||||
String prettyString = place.getPrettyCoordinateString();
|
||||
Assert.assertThat(prettyString, is("90.0 S, 30.0 W"));
|
||||
}
|
||||
|
||||
@Test public void testTooBigWestValue() {
|
||||
LatLng place = new LatLng(20, -190);
|
||||
String prettyString = place.getPrettyCoordinateString();
|
||||
Assert.assertThat(prettyString, is("20.0 N, 170.0 E"));
|
||||
}
|
||||
|
||||
@Test public void testRounding() {
|
||||
LatLng place = new LatLng(0.1234567, -0.33333333);
|
||||
String prettyString = place.getPrettyCoordinateString();
|
||||
Assert.assertThat(prettyString, is("0.1235 N, 0.3333 W"));
|
||||
}
|
||||
|
||||
@Test public void testRoundingAgain() {
|
||||
LatLng place = new LatLng(-0.000001, -0.999999);
|
||||
String prettyString = place.getPrettyCoordinateString();
|
||||
Assert.assertThat(prettyString, is("0.0 S, 1.0 W"));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue