-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added code for directly testing the back-end formatting of coordinates
This code is finding the same bug already detected by the MapModeTests albeit in a much more direct way without needing to instantiate the user interface. Ideally, this should be a unit test that can be executed on the host-side, but the code depends on the Location.convert() for the actual coordinate conversions which is only available on the Android platform itself.
- Loading branch information
1 parent
d4b1335
commit f8051fa
Showing
2 changed files
with
62 additions
and
15 deletions.
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.aprsdroid.app; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.closeTo; | ||
|
||
import org.aprsdroid.app.testing.CoordinateMatcher; | ||
import org.junit.Test; | ||
|
||
import scala.Tuple2; | ||
|
||
public class CoordinateTest { | ||
// Reference data generated from https://www.pgc.umn.edu/apps/convert/ | ||
private static final String providedNLatitude = "77° 15' 30\" N"; | ||
private static final float expectedNLatitude = 77.258333f; | ||
private static final String providedELongitude = "164° 45' 15\" E"; | ||
private static final float expectedELongitude = 164.754167f; | ||
private static final String providedSLatitude = "45° 30' 45\" S"; | ||
private static final float expectedSLatitude = -45.5125f; | ||
private static final String providedWLongitude = "97° 20' 40\" W"; | ||
private static final float expectedWLongitude = -97.344444f; | ||
|
||
@Test | ||
public void givenLocationInNEHemisphere_whenFormattedAsDMSString_thenParseBackIntoDecimalValue() { | ||
Tuple2<String, String> actual = AprsPacket$.MODULE$.formatCoordinates(expectedNLatitude, expectedELongitude); | ||
float floatLatitude = CoordinateMatcher.matchLatitude(actual._1); | ||
float floatLongitude = CoordinateMatcher.matchLongitude(actual._2); | ||
assertThat("Latitude", (double) floatLatitude, closeTo((double) expectedNLatitude, 1e-7)); | ||
assertThat("Longitude", (double) floatLongitude, closeTo((double) expectedELongitude, 1e-7)); | ||
} | ||
|
||
@Test | ||
public void givenLocationInNWHemisphere_whenFormattedAsDMSString_thenParseBackIntoDecimalValue() { | ||
Tuple2<String, String> actual = AprsPacket$.MODULE$.formatCoordinates(expectedNLatitude, expectedWLongitude); | ||
float floatLatitude = CoordinateMatcher.matchLatitude(actual._1); | ||
float floatLongitude = CoordinateMatcher.matchLongitude(actual._2); | ||
assertThat("Latitude", (double) floatLatitude, closeTo((double) expectedNLatitude, 1e-7)); | ||
assertThat("Longitude", (double) floatLongitude, closeTo((double) expectedWLongitude, 1e-7)); | ||
} | ||
|
||
@Test | ||
public void givenLocationInSEHemisphere_whenFormattedAsDMSString_thenParseBackIntoDecimalValue() { | ||
Tuple2<String, String> actual = AprsPacket$.MODULE$.formatCoordinates(expectedSLatitude, expectedELongitude); | ||
float floatLatitude = CoordinateMatcher.matchLatitude(actual._1); | ||
float floatLongitude = CoordinateMatcher.matchLongitude(actual._2); | ||
assertThat("Latitude", (double) floatLatitude, closeTo((double) expectedSLatitude, 1e-7)); | ||
assertThat("Longitude", (double) floatLongitude, closeTo((double) expectedELongitude, 1e-7)); | ||
} | ||
|
||
@Test | ||
public void givenLocationInSWHemisphere_whenFormattedAsDMSString_thenParseBackIntoDecimalValue() { | ||
Tuple2<String, String> actual = AprsPacket$.MODULE$.formatCoordinates(expectedSLatitude, expectedWLongitude); | ||
float floatLatitude = CoordinateMatcher.matchLatitude(actual._1); | ||
float floatLongitude = CoordinateMatcher.matchLongitude(actual._2); | ||
assertThat("Latitude", (double) floatLatitude, closeTo((double) expectedSLatitude, 1e-7)); | ||
assertThat("Longitude", (double) floatLongitude, closeTo((double) expectedWLongitude, 1e-7)); | ||
} | ||
} |
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