Adjust tests to use vitest + jsdom
This commit is contained in:
@@ -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);
|
||||
});
|
||||
Reference in New Issue
Block a user