pr_01m47d24b0e6n91zwymwxg0vpx/apps/web/app/lib/art.test.ts
| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | |
| 4 | import { iso, isoPath, pts, stagger, timing } from "./art.ts"; |
| 5 | |
| 6 | test("iso projects the floor axes and lifts by z", () => { |
| 7 | assert.deepEqual(iso(0, 0), [0, 0]); |
| 8 | const [x, y] = iso(10, 0); |
| 9 | assert.ok(Math.abs(x - 8.660254) < 1e-5); |
| 10 | assert.equal(y, 5); |
| 11 | assert.deepEqual(iso(0, 0, 7), [0, -7]); |
| 12 | // Equal steps along x and y cancel sideways. |
| 13 | assert.equal(iso(4, 4)[0], 0); |
| 14 | }); |
| 15 | |
| 16 | test("pts and isoPath round to one decimal place", () => { |
| 17 | assert.equal(pts([[1.234, 5.678], [0, 0]]), "1.2,5.7 0.0,0.0"); |
| 18 | assert.equal(isoPath([[0, 0], [10, 0]], 2), "M0.0 -2.0 L8.7 3.0"); |
| 19 | }); |
| 20 | |
| 21 | test("stagger spreads starts evenly inside the loop", () => { |
| 22 | assert.deepEqual(stagger(4, 8), ["0s", "2s", "4s", "6s"]); |
| 23 | assert.deepEqual(stagger(3, 4, 1), ["1s", "2s", "3s"]); |
| 24 | assert.deepEqual(stagger(0, 5), []); |
| 25 | assert.deepEqual(stagger(3, 1), ["0s", "0.33s", "0.67s"]); |
| 26 | }); |
| 27 | |
| 28 | test("timing names the custom properties the stylesheet reads", () => { |
| 29 | assert.deepEqual(timing(6, 1.5), { "--dur": "6s", "--delay": "1.5s" }); |
| 30 | assert.deepEqual(timing(3.333, "2s"), { "--dur": "3.33s", "--delay": "2s" }); |
| 31 | }); |