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/SkyRendererTests/OrreryTests.swift

04b2b1d914788057bcd20945b876847386eb8f65
moonrise/Packages/MoonriseKit/Tests/SkyRendererTests/OrreryTests.swift history · blame · raw

38 lines · 1486 bytes

4 symbols in this file
 1import Foundation
 2import SkyEngine
 3import Testing
 4@testable import SkyRenderer
 5
 6let october2026 = Date(timeIntervalSince1970: 1_792_195_200) // 2026-10-17T00:00:00Z
 7
 8@Test func spacecraftLoadAndInterpolate() throws {
 9    #expect(Spacecraft.all.map(\.name) == ["Voyager 1", "Voyager 2", "Pioneer 10", "Pioneer 11", "New Horizons"])
10    let v1 = try #require(Spacecraft.all.first { $0.name == "Voyager 1" })
11    let p = try #require(v1.position(at: october2026))
12    let au = (p * p).sum().squareRoot()
13    // Voyager 1 is about 170 AU from the Sun in late 2026 and about 35° north of the
14    // ecliptic, so its distance projected on the ecliptic plane is about 140 AU.
15    #expect(au > 130 && au < 150, "\(au) AU")
16    #expect(v1.position(at: Date(timeIntervalSince1970: 0)) == nil)
17}
18
19@Test func earthIsOneAUFromTheSun() throws {
20    let e = try SkyEngine.heliocentricEarth(at: october2026)
21    let au = (e * e).sum().squareRoot()
22    #expect(abs(au - 1) < 0.02)
23    #expect(abs(e.z) < 1e-3)
24}
25
26@Test func orreryScaleIsMonotonic() {
27    let s = OrreryScale(size: CGSize(width: 400, height: 400))
28    #expect(s.radius(0.5) < s.radius(1))
29    #expect(s.radius(1) < s.radius(5))
30    #expect(s.radius(30) < s.radius(170))
31    #expect(abs(s.radius(230) - 192) < 1e-9)
32}
33
34@Test func voyager1TrueDistance() throws {
35    let v1 = try #require(Spacecraft.all.first { $0.name == "Voyager 1" })
36    let d = try #require(v1.distance(at: october2026))
37    #expect(d > 165 && d < 175, "\(d) AU")
38}