summaryrefslogtreecommitdiff
path: root/android-app/app/src/test/kotlin
diff options
context:
space:
mode:
authorClaudomator Agent <agent@claudomator>2026-03-14 02:23:25 +0000
committerClaudomator Agent <agent@claudomator>2026-03-14 02:23:25 +0000
commite53fbe4e984f0f57f3ed73297adf8273bb523808 (patch)
treeb9a8a81900a07be819e328788bf3f5dc10bd91e2 /android-app/app/src/test/kotlin
parentf391940495f40f00794214be5d1a440cc14a8915 (diff)
Add GpsPosition data class and NMEA RMC parser with tests
- NmeaParser: parses $GPRMC (and any *RMC) sentence → GpsPosition - Null for void status (V), malformed input, non-RMC sentence - SOG/COG default to 0.0 when empty; S/W give negative lat/lon - Timestamp from HHMMSS + DDMMYY fields as Unix epoch millis UTC - No Android dependencies - GpsPositionTest: value holding and data-class equality (2 tests) - NmeaParserTest: 11 tests covering valid parse, void/malformed/empty, hemisphere signs, decimal precision - All 22 unit tests verified GREEN via kotlinc + JUnitCore Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'android-app/app/src/test/kotlin')
-rw-r--r--android-app/app/src/test/kotlin/org/terst/nav/gps/GpsPositionTest.kt33
-rw-r--r--android-app/app/src/test/kotlin/org/terst/nav/nmea/NmeaParserTest.kt103
2 files changed, 136 insertions, 0 deletions
diff --git a/android-app/app/src/test/kotlin/org/terst/nav/gps/GpsPositionTest.kt b/android-app/app/src/test/kotlin/org/terst/nav/gps/GpsPositionTest.kt
new file mode 100644
index 0000000..52e8348
--- /dev/null
+++ b/android-app/app/src/test/kotlin/org/terst/nav/gps/GpsPositionTest.kt
@@ -0,0 +1,33 @@
+package org.terst.nav.gps
+
+import org.junit.Assert.*
+import org.junit.Test
+
+class GpsPositionTest {
+
+ @Test
+ fun `GpsPosition holds correct values`() {
+ val pos = GpsPosition(
+ latitude = 41.5,
+ longitude = -71.0,
+ sog = 5.2,
+ cog = 180.0,
+ timestampMs = 1_000L
+ )
+ assertEquals(41.5, pos.latitude, 0.0)
+ assertEquals(-71.0, pos.longitude, 0.0)
+ assertEquals(5.2, pos.sog, 0.0)
+ assertEquals(180.0, pos.cog, 0.0)
+ assertEquals(1_000L, pos.timestampMs)
+ }
+
+ @Test
+ fun `GpsPosition equality works as expected for data class`() {
+ val pos1 = GpsPosition(41.5, -71.0, 5.2, 180.0, 1_000L)
+ val pos2 = GpsPosition(41.5, -71.0, 5.2, 180.0, 1_000L)
+ val pos3 = GpsPosition(42.0, -70.0, 3.0, 90.0, 2_000L)
+
+ assertEquals(pos1, pos2)
+ assertNotEquals(pos1, pos3)
+ }
+}
diff --git a/android-app/app/src/test/kotlin/org/terst/nav/nmea/NmeaParserTest.kt b/android-app/app/src/test/kotlin/org/terst/nav/nmea/NmeaParserTest.kt
new file mode 100644
index 0000000..e43b7ab
--- /dev/null
+++ b/android-app/app/src/test/kotlin/org/terst/nav/nmea/NmeaParserTest.kt
@@ -0,0 +1,103 @@
+package org.terst.nav.nmea
+
+import org.junit.Assert.*
+import org.junit.Before
+import org.junit.Test
+
+class NmeaParserTest {
+
+ private lateinit var parser: NmeaParser
+
+ @Before
+ fun setUp() {
+ parser = NmeaParser()
+ }
+
+ // $GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A
+ // lat: 48 + 7.038/60 = 48.1173°N, lon: 11 + 31.000/60 = 11.51667°E
+ // SOG 22.4 kn, COG 84.4°
+
+ @Test
+ fun `valid RMC sentence parses latitude and longitude`() {
+ val sentence = "\$GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A"
+ val pos = parser.parseRmc(sentence)
+ assertNotNull(pos)
+ assertEquals(48.1173, pos!!.latitude, 0.0001)
+ assertEquals(11.51667, pos.longitude, 0.0001)
+ }
+
+ @Test
+ fun `valid RMC sentence parses SOG and COG`() {
+ val sentence = "\$GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A"
+ val pos = parser.parseRmc(sentence)
+ assertNotNull(pos)
+ assertEquals(22.4, pos!!.sog, 0.001)
+ assertEquals(84.4, pos.cog, 0.001)
+ }
+
+ @Test
+ fun `void status V returns null`() {
+ val sentence = "\$GPRMC,123519,V,4807.038,N,01131.000,E,,,230394,003.1,W"
+ assertNull(parser.parseRmc(sentence))
+ }
+
+ @Test
+ fun `malformed sentence with too few fields returns null`() {
+ assertNull(parser.parseRmc("\$GPRMC,123519,A"))
+ }
+
+ @Test
+ fun `empty string returns null`() {
+ assertNull(parser.parseRmc(""))
+ }
+
+ @Test
+ fun `non-NMEA string returns null`() {
+ assertNull(parser.parseRmc("NOT_NMEA_DATA"))
+ }
+
+ @Test
+ fun `south latitude is negative`() {
+ // lat: -(42 + 50.5589/60) = -42.84265
+ val sentence = "\$GPRMC,092204.999,A,4250.5589,S,14718.5084,E,0.00,89.68,211200,,"
+ val pos = parser.parseRmc(sentence)
+ assertNotNull(pos)
+ assertTrue("South latitude must be negative", pos!!.latitude < 0)
+ assertEquals(-42.84265, pos.latitude, 0.0001)
+ }
+
+ @Test
+ fun `west longitude is negative`() {
+ // lon: -(11 + 31.000/60) = -11.51667
+ val sentence = "\$GPRMC,123519,A,4807.038,N,01131.000,W,022.4,084.4,230394,003.1,E"
+ val pos = parser.parseRmc(sentence)
+ assertNotNull(pos)
+ assertTrue("West longitude must be negative", pos!!.longitude < 0)
+ assertEquals(-11.51667, pos.longitude, 0.0001)
+ }
+
+ @Test
+ fun `SOG and COG parse with decimal precision`() {
+ // lon: -(118 + 1.5678/60) = -118.02613, lat: 33 + 52.1234/60 = 33.86872
+ val sentence = "\$GPRMC,093456,A,3352.1234,N,11801.5678,W,12.345,270.5,140326,,"
+ val pos = parser.parseRmc(sentence)
+ assertNotNull(pos)
+ assertEquals(12.345, pos!!.sog, 0.0001)
+ assertEquals(270.5, pos.cog, 0.0001)
+ }
+
+ @Test
+ fun `empty SOG and COG fields default to zero`() {
+ val sentence = "\$GPRMC,123519,A,4807.038,N,01131.000,E,,,230394,003.1,W"
+ val pos = parser.parseRmc(sentence)
+ assertNotNull(pos)
+ assertEquals(0.0, pos!!.sog, 0.001)
+ assertEquals(0.0, pos.cog, 0.001)
+ }
+
+ @Test
+ fun `non-RMC sentence returns null`() {
+ val sentence = "\$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,"
+ assertNull(parser.parseRmc(sentence))
+ }
+}