summaryrefslogtreecommitdiff
path: root/android-app/app/src/test/kotlin/org
diff options
context:
space:
mode:
Diffstat (limited to 'android-app/app/src/test/kotlin/org')
-rw-r--r--android-app/app/src/test/kotlin/org/terst/nav/data/model/GribFileTest.kt63
-rw-r--r--android-app/app/src/test/kotlin/org/terst/nav/data/model/GribRegionTest.kt36
2 files changed, 99 insertions, 0 deletions
diff --git a/android-app/app/src/test/kotlin/org/terst/nav/data/model/GribFileTest.kt b/android-app/app/src/test/kotlin/org/terst/nav/data/model/GribFileTest.kt
new file mode 100644
index 0000000..ef8bf7f
--- /dev/null
+++ b/android-app/app/src/test/kotlin/org/terst/nav/data/model/GribFileTest.kt
@@ -0,0 +1,63 @@
+package org.terst.nav.data.model
+
+import org.junit.Assert.*
+import org.junit.Test
+import java.time.Instant
+
+class GribFileTest {
+
+ private val region = GribRegion(
+ name = "Test Region",
+ latMin = 40.0,
+ latMax = 60.0,
+ lonMin = -10.0,
+ lonMax = 10.0
+ )
+
+ private val modelRun = Instant.parse("2026-03-15T00:00:00Z")
+ private val downloadedAt = Instant.parse("2026-03-15T01:00:00Z")
+
+ private fun makeFile(forecastHours: Int = 48) = GribFile(
+ region = region,
+ modelRunTime = modelRun,
+ forecastHours = forecastHours,
+ downloadedAt = downloadedAt,
+ filePath = "/data/grib/test.grib2",
+ sizeBytes = 1_000_000L
+ )
+
+ @Test
+ fun `validUntil_equalsModelRunPlusForecastHours`() {
+ val file = makeFile(forecastHours = 48)
+ val expected = modelRun.plusSeconds(48L * 3600)
+ assertEquals(expected, file.validUntil())
+ }
+
+ @Test
+ fun `isStale_returnsFalse_whenNowBeforeValidUntil`() {
+ val file = makeFile(forecastHours = 48)
+ val now = modelRun.plusSeconds(24L * 3600) // 24h in, still 24h to go
+ assertFalse(file.isStale(now))
+ }
+
+ @Test
+ fun `isStale_returnsTrue_whenNowAfterValidUntil`() {
+ val file = makeFile(forecastHours = 48)
+ val now = modelRun.plusSeconds(49L * 3600) // 1h past expiry
+ assertTrue(file.isStale(now))
+ }
+
+ @Test
+ fun `isStale_returnsFalse_whenNowExactlyAtValidUntil`() {
+ val file = makeFile(forecastHours = 48)
+ val now = file.validUntil() // exactly at boundary — not yet stale
+ assertFalse(file.isStale(now))
+ }
+
+ @Test
+ fun `ageSeconds_computesElapsedTime`() {
+ val file = makeFile()
+ val now = downloadedAt.plusSeconds(3600) // 1h after download
+ assertEquals(3600L, file.ageSeconds(now))
+ }
+}
diff --git a/android-app/app/src/test/kotlin/org/terst/nav/data/model/GribRegionTest.kt b/android-app/app/src/test/kotlin/org/terst/nav/data/model/GribRegionTest.kt
new file mode 100644
index 0000000..a9a0334
--- /dev/null
+++ b/android-app/app/src/test/kotlin/org/terst/nav/data/model/GribRegionTest.kt
@@ -0,0 +1,36 @@
+package org.terst.nav.data.model
+
+import org.junit.Assert.*
+import org.junit.Test
+
+class GribRegionTest {
+
+ private val region = GribRegion(
+ name = "Test Region",
+ latMin = 40.0,
+ latMax = 60.0,
+ lonMin = -10.0,
+ lonMax = 10.0
+ )
+
+ @Test
+ fun `contains_returnsTrue_whenPointInsideBounds`() {
+ assertTrue(region.contains(50.0, 0.0))
+ }
+
+ @Test
+ fun `contains_returnsFalse_whenLatOutOfRange`() {
+ assertFalse(region.contains(70.0, 0.0))
+ }
+
+ @Test
+ fun `contains_returnsFalse_whenLonOutOfRange`() {
+ assertFalse(region.contains(50.0, 20.0))
+ }
+
+ @Test
+ fun `areaDegrees_computesCorrectly`() {
+ val area = region.areaDegrees()
+ assertEquals(400.0, area, 0.0001)
+ }
+}