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/SunTests.swift

45 lines · 2014 bytes

5 symbols in this file
 1import Foundation
 2import Testing
 3@testable import Feeds
 4
 5@Test func flareClasses() {
 6    #expect(XRay.flareClass(1.5261429098245571e-06) == "C1.5")
 7    #expect(XRay.flareClass(6.587599727936322e-07) == "B6.6")
 8    #expect(XRay.flareClass(2.3e-4) == "X2.3")
 9    #expect(XRay.flareClass(4e-9) == "A0.4")
10}
11
12@Test func decodesLongChannelOnly() throws {
13    // Shape copied from xrays-6-hour.json on 2026-10-17.
14    let data = Data("""
15    [{"time_tag": "2026-10-17T17:43:00Z", "satellite": 18, "flux": 1.195e-08, "observed_flux": 3.2e-08, "electron_correction": 2.0e-08, "electron_contaminaton": true, "energy": "0.05-0.4nm"},
16     {"time_tag": "2026-10-17T17:43:00Z", "satellite": 18, "flux": 6.5876e-07, "observed_flux": 6.9e-07, "electron_correction": 3.1e-08, "electron_contaminaton": false, "energy": "0.1-0.8nm"},
17     {"time_tag": "2026-10-17T17:44:00Z", "satellite": 18, "flux": null, "energy": "0.1-0.8nm"}]
18    """.utf8)
19    let samples = try XRay.decode(data)
20    #expect(samples.count == 1)
21    #expect(samples[0].flux == 6.5876e-07)
22}
23
24@Test func kpBarsMarkPredicted() throws {
25    let bars = try SpaceWeather.decodeKpBars(forecast)
26    #expect(bars.count == 4)
27    #expect(bars.first?.predicted == false)
28    #expect(bars.last?.predicted == true)
29}
30
31@Test func solarImageURL() {
32    #expect(SolarImage.corona.url().absoluteString == "https://sdo.gsfc.nasa.gov/assets/img/latest/latest_1024_0171.jpg")
33}
34
35@Test func ovationKeepsNonZeroCells() throws {
36    // Shape from ovation_aurora_latest.json on 2026-10-17.
37    let data = Data("""
38    {"Observation Time": "2026-10-17T23:38:00Z", "Forecast Time": "2026-10-18T00:37:00Z", "Data Format": "[Longitude, Latitude, Aurora]",
39     "coordinates": [[0, -90, 3], [0, -89, 0], [0, 65, 12]], "type": "MultiPoint"}
40    """.utf8)
41    let o = try Ovation.decode(data)
42    #expect(o.cells.count == 2)
43    #expect(o.cells.last == Ovation.Cell(lon: 0, lat: 65, probability: 12))
44    #expect(o.forecastTime == (try Date("2026-10-18T00:37:00Z", strategy: .iso8601)))
45}