SPB Git

spb/earth-now Public License

earth-now.co — real-time planetary dashboard: live world metrics modeled, not streamed.

TypeScript 93% Shell 2.3% SQL 1.4% JavaScript 1.3% Dockerfile 1.2% CSS 0.8%
1.8 KB · 53 lines typescript
Raw Blame History
1/**2 * earth-now.co3 * Author:  Simon-Pierre Boucher4 * Contact: contact@spboucher.ai5 * File:    apps/web/test/consistency.node.test.ts6 * Purpose: Client/server consistency — counterValue in the NODE environment must match the closed-form values bit-for-bit (Object.is)7 */89import { describe, expect, it } from "vitest";10import { counterValue, parseIsoUtc } from "@earth-now/counter";11import {12  INSTANTS,13  LINEAR_MODEL,14  SEASONAL_MODEL,15  linearClosedForm,16  seasonalClosedForm,17} from "./consistency-shared";1819describe("counterValue consistency (node environment)", () => {20  it("runs in a server-like environment (no DOM)", () => {21    expect(typeof globalThis.window).toBe("undefined");22  });2324  it("value(anchorTime) === anchorValue exactly", () => {25    const anchorMs = parseIsoUtc(LINEAR_MODEL.anchorTime);26    expect(Object.is(counterValue(LINEAR_MODEL, anchorMs), LINEAR_MODEL.anchorValue)).toBe(true);27    expect(Object.is(counterValue(SEASONAL_MODEL, anchorMs), SEASONAL_MODEL.anchorValue)).toBe(28      true,29    );30  });3132  it("matches the linear closed form bit-for-bit at all five instants", () => {33    for (const t of INSTANTS) {34      expect(Object.is(counterValue(LINEAR_MODEL, t), linearClosedForm(t))).toBe(true);35    }36  });3738  it("matches the seasonal closed form bit-for-bit at all five instants", () => {39    for (const t of INSTANTS) {40      expect(Object.is(counterValue(SEASONAL_MODEL, t), seasonalClosedForm(t))).toBe(true);41    }42  });4344  it("is deterministic: re-evaluation yields Object.is-identical numbers", () => {45    for (const t of INSTANTS) {46      expect(Object.is(counterValue(LINEAR_MODEL, t), counterValue(LINEAR_MODEL, t))).toBe(true);47      expect(Object.is(counterValue(SEASONAL_MODEL, t), counterValue(SEASONAL_MODEL, t))).toBe(48        true,49      );50    }51  });52});53