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

29 lines · 1355 bytes

 1import Foundation
 2import Testing
 3@testable import Feeds
 4
 5// Fixtures saved from the mars.nasa.gov raw image feeds on 2026-10-18, trimmed.
 6
 7@Test func perseveranceKeepsLeftEyeFullFramesWithoutSkycam() throws {
 8    let url = try #require(Bundle.module.url(forResource: "Fixtures/m2020-raw", withExtension: "json"))
 9    let images = try MarsImage.decodePerseverance(Data(contentsOf: url))
10    #expect(images.count == 24)
11    #expect(Set(images.map(\.camera)) == ["Mastcam-Z", "Navcam"])
12    #expect(images.allSatisfy { $0.sol == 2012 && $0.rover == "Perseverance" })
13    #expect(zip(images, images.dropFirst()).allSatisfy { $0.taken >= $1.taken })
14    #expect(images[0].image.absoluteString.hasSuffix("_1200.jpg"))
15}
16
17@Test func curiosityKeepsFullFramesOnly() throws {
18    let url = try #require(Bundle.module.url(forResource: "Fixtures/msl-raw", withExtension: "json"))
19    let images = try MarsImage.decodeCuriosity(Data(contentsOf: url))
20    #expect(images.count == 8)
21    #expect(Set(images.map(\.camera)).isSubset(of: ["Navcam", "Front Hazcam", "Rear Hazcam"]))
22    #expect(images.allSatisfy { $0.sol == 5047 })
23}
24
25@Test func parsesBothTimestampForms() {
26    #expect(MarsImage.parseUTC("2026-10-18T04:09:00.977") != nil)
27    #expect(MarsImage.parseUTC("2026-10-18T12:08:53.000Z") != nil)
28    #expect(MarsImage.parseUTC("2026-10-18T12:08:53Z") != nil)
29}