lawsynth/apps/docs-site/tests/equations.test.ts
2026-08-16 23:40:41 +03:00

24 lines
1.4 KiB
TypeScript
Raw Permalink 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 type { Law, WorldDefinition } from "@lawsynth/world-schema";
import { equationReference, renderEquation, worldEquationReferences } from "../src/equations.js";
import { contains, deepEqual, equal, test } from "./assertions.js";
const growthLaw: Law = {
id: "population-growth",
kind: "continuous",
target: "population",
expression: { kind: "binary", operator: "mul", left: { kind: "symbol", id: "rate" }, right: { kind: "symbol", id: "population" } },
description: "Exponential population growth.",
};
test("equation references preserve executable law semantics in accessible HTML", () => {
const reference = equationReference(growthLaw, "τ");
equal(reference.plainText, "dpopulation/dτ = rate × population");
contains(reference.html, 'aria-label="dpopulation/dτ = rate × population"');
contains(renderEquation({ kind: "binary", operator: "add", left: { kind: "symbol", id: "x" }, right: { kind: "constant", value: 1 } }), "x + 1");
});
test("world equation references use the world's declared time symbol", () => {
const world: WorldDefinition = { formatVersion: "0.1.0", id: "growth", time: { kind: "continuous", symbol: "time" }, variables: [{ id: "population", role: "state" }], laws: [growthLaw] };
deepEqual(worldEquationReferences(world).map((entry) => [entry.id, entry.plainText]), [["population-growth", "dpopulation/dtime = rate × population"]]);
});