diff --git a/androidTest/java/org/aprsdroid/app/CoordinateTest.java b/androidTest/java/org/aprsdroid/app/CoordinateTest.java new file mode 100644 index 00000000..415b91e9 --- /dev/null +++ b/androidTest/java/org/aprsdroid/app/CoordinateTest.java @@ -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 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 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 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 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)); + } +} \ No newline at end of file diff --git a/test/java/org/aprsdroid/app/CoordinateTest.java b/test/java/org/aprsdroid/app/CoordinateTest.java index 208b23ee..3c812aba 100644 --- a/test/java/org/aprsdroid/app/CoordinateTest.java +++ b/test/java/org/aprsdroid/app/CoordinateTest.java @@ -1,21 +1,11 @@ package org.aprsdroid.app; -import android.util.Log; -import android.view.View; -import android.widget.TextView; - +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.closeTo; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; -import static org.hamcrest.MatcherAssert.assertThat; import org.aprsdroid.app.testing.CoordinateMatcher; -import org.junit.Assert; import org.junit.Test; -import java.util.Objects; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - public class CoordinateTest { // Reference data generated from https://www.pgc.umn.edu/apps/convert/ private static final String providedNLatitude = "77° 15' 30\" N"; @@ -30,24 +20,24 @@ public class CoordinateTest { @Test public void givenDMSLatitudeInN_whenParsingString_ThenShouldMatchDecimal() { float value = CoordinateMatcher.matchLatitude(providedNLatitude); - assertThat("Latitude", (double)value, closeTo((double)expectedNLatitude, 1e-7)); + assertThat("Latitude", (double) value, closeTo((double) expectedNLatitude, 1e-7)); } @Test public void givenDMSLongitudeInE_whenParsingString_ThenShouldMatchDecimal() { float value = CoordinateMatcher.matchLongitude(providedELongitude); - assertThat("Longitude", (double)value, closeTo((double)expectedELongitude, 1e-7)); + assertThat("Longitude", (double) value, closeTo((double) expectedELongitude, 1e-7)); } @Test public void givenDMSLatitudeInS_whenParsingString_ThenShouldMatchDecimal() { float value = CoordinateMatcher.matchLatitude(providedSLatitude); - assertThat("Latitude", (double)value, closeTo((double)expectedSLatitude, 1e-7)); + assertThat("Latitude", (double) value, closeTo((double) expectedSLatitude, 1e-7)); } @Test public void givenDMSLongitudeInW_whenParsingString_ThenShouldMatchDecimal() { float value = CoordinateMatcher.matchLongitude(providedWLongitude); - assertThat("Longitude", (double)value, closeTo((double)expectedWLongitude, 1e-7)); + assertThat("Longitude", (double) value, closeTo((double) expectedWLongitude, 1e-7)); } }