krz/moonrise

Night-sky companion for iPhone, Apple Watch and Vision Pro: what's up tonight, the Moon, planets, launches and missions, and a Library of the solar system. SwiftUI app with a Cloudflare Workers backend. astronomy cloudflare-workers ios night-sky space swiftui visionos watchos

Packages/MoonriseKit/Tests/FeedsTests/SpaceWeatherTests.swift

30 lines · 1228 bytes

2 symbols in this file
 1import Foundation
 2import Testing
 3@testable import Feeds
 4
 5// Shapes copied from the live SWPC feeds on 2026-10-17.
 6let minutes = Data("""
 7[{"time_tag": "2026-10-17T23:32:00", "kp_index": 0, "estimated_kp": 0.33, "kp": "0P"},
 8 {"time_tag": "2026-10-17T23:33:00", "kp_index": 0, "estimated_kp": 0.67, "kp": "1M"}]
 9""".utf8)
10
11let forecast = Data("""
12[{"time_tag": "2026-10-17T18:00:00", "kp": 2.33, "observed": "observed", "noaa_scale": null},
13 {"time_tag": "2026-10-18T00:00:00", "kp": 3.67, "observed": "predicted", "noaa_scale": null},
14 {"time_tag": "2026-10-18T09:00:00", "kp": 5.33, "observed": "predicted", "noaa_scale": "G1"},
15 {"time_tag": "2026-10-19T21:00:00", "kp": 7.0, "observed": "predicted", "noaa_scale": "G3"}]
16""".utf8)
17
18@Test func decodesLatestKpAndNext24hMaximum() throws {
19    let at = try #require(SpaceWeather.parse("2026-10-17T23:34:00"))
20    let w = try SpaceWeather.decode(now: minutes, forecast: forecast, at: at)
21    #expect(w.kpNow == 0.67)
22    #expect(w.observedAt == SpaceWeather.parse("2026-10-17T23:33:00"))
23    #expect(w.kpNext24h == 5.33)
24}
25
26@Test func gScale() {
27    #expect(SpaceWeather.gScale(4.67) == nil)
28    #expect(SpaceWeather.gScale(5.33) == 1)
29    #expect(SpaceWeather.gScale(9) == 5)
30}