deadhead-space-freight-tycoon/packages/sim/test/positions.test.ts

43 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { content } from "@deadhead/content";
import { describe, expect, it } from "vitest";
import { locationPosition } from "../src/index";
const when = Date.parse("2100-03-01T00:00:00Z");
const fromSun = (id: string) => {
const { x, y } = locationPosition(content.location(id)!, when);
return Math.hypot(x, y);
};
describe("location positions", () => {
it("puts Earth about 150 million km from the Sun", () => {
expect(fromSun("earth")).toBeGreaterThan(147);
expect(fromSun("earth")).toBeLessThan(153);
});
it("puts Mars 206–250 million km from the Sun", () => {
expect(fromSun("mars")).toBeGreaterThan(206);
expect(fromSun("mars")).toBeLessThan(250);
});
it("puts Jupiter Cloud Platform 740–820 million km from the Sun", () => {
expect(fromSun("jupiter-cloud-platform")).toBeGreaterThan(740);
expect(fromSun("jupiter-cloud-platform")).toBeLessThan(820);
});
it("puts Ceres Station on its ~414 million km orbit", () => {
expect(fromSun("ceres-station")).toBeCloseTo(414, 0);
});
it("keeps the Moon within 1 million km of Earth", () => {
const earth = locationPosition(content.location("earth")!, when);
const moon = locationPosition(content.location("moon")!, when);
expect(Math.hypot(moon.x - earth.x, moon.y - earth.y)).toBeLessThan(1);
});
it("returns identical values for the same time", () => {
for (const location of content.locations) {
expect(locationPosition(location, when)).toEqual(locationPosition(location, when));
}
});
});