Adjust tests to use vitest + jsdom

This commit is contained in:
Schluffe
2026-08-08 18:35:57 +02:00
parent ae8c63ce11
commit 9bdffd06e4
20 changed files with 196 additions and 150 deletions
+34
View File
@@ -0,0 +1,34 @@
import { expect, test } from "vitest";
import { lerp, lerpPrecice } from "./lerp.ts";
test("lerp", () => {
const a = 0;
const b = 0.1;
expect(lerp(a, b, 0.2)).toBe(0.020000000000000004);
expect(lerp(a, b, 0.5)).toBe(0.05);
});
test("lerpPrecice", () => {
const a = 0;
const b = 0.1;
expect(lerpPrecice(a, b, 0.2)).toBe(0.020000000000000004);
expect(lerpPrecice(a, b, 0.5)).toBe(0.05);
});
test("lerp vs lerpPrecice", () => {
// a and b with very different magnitudes expose
// catastrophic cancellation in lerp's `(b - a)` term
const a = 1e16;
const b = 1;
// lerp loses b at t = 1
expect(lerp(a, b, 1)).toBe(0);
// lerpPrecice keeps b at t = 1
expect(lerpPrecice(a, b, 1)).toBe(b);
expect(lerp(a, b, 0)).toBe(a);
expect(lerpPrecice(a, b, 0)).toBe(a);
});