import { describe, expect, it } from "@suaveplan/testing/runner"; import type { AtmosphericObserver, ObserverPosition, SpaceObserver, SurfaceObserver, } from "./observer.js"; describe("Observer types", () => { it("surface observer has kind surface", { timeout: 5000 }, () => { const o: SurfaceObserver = { kind: "surface", planet: { name: "Earth", mass: 1, radius: 1, polarRadius: 1, surfaceGravity: 1, rotationPeriod: 1, axialTilt: 0, atmosphere: null, satellites: [], }, coord: { latitude: 0, longitude: 0 }, }; expect(o.kind).toBe("surface"); }); it("atmospheric observer has kind atmospheric", { timeout: 5000 }, () => { const o: AtmosphericObserver = { kind: "atmospheric", planet: { name: "Earth", mass: 1, radius: 1, polarRadius: 1, surfaceGravity: 1, rotationPeriod: 1, axialTilt: 0, atmosphere: null, satellites: [], }, coord: { latitude: 0, longitude: 0 }, altitudeMetres: 100, }; expect(o.kind).toBe("atmospheric"); }); it("space observer has kind space", { timeout: 5000 }, () => { const o: SpaceObserver = { kind: "space", heliocentricVec: { x: 0, y: 0, z: 0 }, frame: "icrs", }; expect(o.kind).toBe("space"); }); it("discriminated union narrows correctly", { timeout: 5000 }, () => { const observers: ObserverPosition[] = [ { kind: "surface", planet: { name: "Earth", mass: 1, radius: 1, polarRadius: 1, surfaceGravity: 1, rotationPeriod: 1, axialTilt: 0, atmosphere: null, satellites: [], }, coord: { latitude: 0, longitude: 0 }, }, { kind: "atmospheric", planet: { name: "Earth", mass: 1, radius: 1, polarRadius: 1, surfaceGravity: 1, rotationPeriod: 1, axialTilt: 0, atmosphere: null, satellites: [], }, coord: { latitude: 0, longitude: 0 }, altitudeMetres: 100, }, { kind: "space", heliocentricVec: { x: 1, y: 0, z: 0 }, frame: "icrs", }, ]; expect(observers.filter((o) => o.kind === "surface")).toHaveLength(1); expect(observers.filter((o) => o.kind === "atmospheric")).toHaveLength( 1 ); expect(observers.filter((o) => o.kind === "space")).toHaveLength(1); }); });