diff options
| author | Claude Agent <agent@claude.ai> | 2026-03-25 01:57:17 +0000 |
|---|---|---|
| committer | Peter Stone <thepeterstone@gmail.com> | 2026-03-25 04:55:58 +0000 |
| commit | 0294c6fccc5a1dac7d4fb0ac084b273683e47d32 (patch) | |
| tree | cd2f23567324a1881835444ab4022efd6e2ed575 /android-app/app/src/test/kotlin | |
| parent | e5cd0ce6bf65fff1bbbb5d8e12c4076da088ebe1 (diff) | |
feat(safety): log wind and current conditions at MOB activation (Section 4.6)
Per COMPONENT_DESIGN.md Section 4.6, the MOB navigation view must display
wind and current conditions at the time of the event.
- MobEvent: add nullable windSpeedKt, windDirectionDeg, currentSpeedKt,
currentDirectionDeg fields captured at the exact moment of activation
- MobAlarmManager.activate(): accept optional wind/current params and
forward them into MobEvent (defaults to null for backward compatibility)
- LocationService (new): aggregates live SensorData (resolves true wind via
TrueWindCalculator) and marine-forecast current conditions; snapshot()
provides a point-in-time EnvironmentalSnapshot for safety-critical logging
- MobAlarmManagerTest: add tests for wind/current storage and null defaults
- LocationServiceTest (new): covers snapshot, true-wind resolution,
current-condition updates, and the latestSensor flow
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/com/example/androidapp/gps/LocationServiceTest.kt | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/android-app/app/src/test/kotlin/com/example/androidapp/gps/LocationServiceTest.kt b/android-app/app/src/test/kotlin/com/example/androidapp/gps/LocationServiceTest.kt new file mode 100644 index 0000000..d9192c6 --- /dev/null +++ b/android-app/app/src/test/kotlin/com/example/androidapp/gps/LocationServiceTest.kt @@ -0,0 +1,117 @@ +package com.example.androidapp.gps + +import com.example.androidapp.data.model.SensorData +import kotlinx.coroutines.flow.first +import kotlinx.coroutines.runBlocking +import org.junit.Assert.* +import org.junit.Test + +class LocationServiceTest { + + private fun service() = LocationService() + + // ── snapshot with no data ───────────────────────────────────────────────── + + @Test + fun snapshot_noData_allFieldsNull() { + val snap = service().snapshot() + assertNull(snap.windSpeedKt) + assertNull(snap.windDirectionDeg) + assertNull(snap.currentSpeedKt) + assertNull(snap.currentDirectionDeg) + } + + // ── true-wind resolution ────────────────────────────────────────────────── + + @Test + fun updateSensorData_withFullReading_resolvesTrueWind() = runBlocking { + val svc = service() + // Head north (hdg = 0°), AWS = 10 kt coming from ahead (AWA = 0°), BSP = 5 kt + // → TW comes FROM ahead at 5 kt + svc.updateSensorData( + SensorData( + headingTrueDeg = 0.0, + apparentWindSpeedKt = 10.0, + apparentWindAngleDeg = 0.0, + speedOverGroundKt = 5.0 + ) + ) + val tw = svc.latestTrueWind.first() + assertNotNull(tw) + assertTrue("Expected TWS > 0", tw!!.speedKt > 0.0) + } + + @Test + fun updateSensorData_missingHeading_doesNotResolveTrueWind() = runBlocking { + val svc = service() + svc.updateSensorData( + SensorData( + apparentWindSpeedKt = 10.0, + apparentWindAngleDeg = 45.0, + speedOverGroundKt = 5.0 + // headingTrueDeg omitted + ) + ) + assertNull(svc.latestTrueWind.first()) + } + + // ── current conditions ──────────────────────────────────────────────────── + + @Test + fun updateCurrentConditions_reflectedInSnapshot() { + val svc = service() + svc.updateCurrentConditions(speedKt = 1.5, directionDeg = 135.0) + + val snap = svc.snapshot() + assertEquals(1.5, snap.currentSpeedKt!!, 0.001) + assertEquals(135.0, snap.currentDirectionDeg!!, 0.001) + } + + @Test + fun updateCurrentConditions_nullClears() { + val svc = service() + svc.updateCurrentConditions(speedKt = 2.0, directionDeg = 90.0) + svc.updateCurrentConditions(speedKt = null, directionDeg = null) + + val snap = svc.snapshot() + assertNull(snap.currentSpeedKt) + assertNull(snap.currentDirectionDeg) + } + + // ── combined snapshot ───────────────────────────────────────────────────── + + @Test + fun snapshot_afterFullUpdate_populatesAllFields() = runBlocking { + val svc = service() + + // Head east (hdg = 90°), wind from starboard bow, BSP proxy = 6 kt + svc.updateSensorData( + SensorData( + headingTrueDeg = 90.0, + apparentWindSpeedKt = 12.0, + apparentWindAngleDeg = 45.0, + speedOverGroundKt = 6.0 + ) + ) + svc.updateCurrentConditions(speedKt = 0.8, directionDeg = 270.0) + + val snap = svc.snapshot() + assertNotNull(snap.windSpeedKt) + assertNotNull(snap.windDirectionDeg) + assertEquals(0.8, snap.currentSpeedKt!!, 0.001) + assertEquals(270.0, snap.currentDirectionDeg!!, 0.001) + } + + // ── latestSensor flow ───────────────────────────────────────────────────── + + @Test + fun updateSensorData_updatesLatestSensorFlow() = runBlocking { + val svc = service() + assertNull(svc.latestSensor.first()) + + val data = SensorData(latitude = 41.5, longitude = -71.3) + svc.updateSensorData(data) + + assertEquals(data, svc.latestSensor.first()) + } +} |
