Initial Commit

This commit is contained in:
2026-05-27 23:47:53 +01:00
parent fbc70f96e6
commit 9b28db724f
18103 changed files with 1600554 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
import { describe, expect, it } from "@suaveplan/testing/runner";
import {
clamp,
isFiniteNumber,
roundAlpha,
roundChannel,
roundPercent,
} from "./utils.js";
describe("utils", () => {
it("clamp restricts to range", { timeout: 5000 }, () => {
expect(clamp(5, 0, 10)).toBe(5);
expect(clamp(-5, 0, 10)).toBe(0);
expect(clamp(15, 0, 10)).toBe(10);
});
it("isFiniteNumber rejects non-finite", { timeout: 5000 }, () => {
expect(isFiniteNumber(5)).toBe(true);
expect(isFiniteNumber(Number.NaN)).toBe(false);
expect(isFiniteNumber(Number.POSITIVE_INFINITY)).toBe(false);
expect(isFiniteNumber("5")).toBe(false);
});
it("roundChannel clamps to 0-255", { timeout: 5000 }, () => {
expect(roundChannel(128.6)).toBe(129);
expect(roundChannel(-10)).toBe(0);
expect(roundChannel(300)).toBe(255);
});
it("roundPercent clamps to 0-100", { timeout: 5000 }, () => {
expect(roundPercent(50.4)).toBe(50);
expect(roundPercent(-5)).toBe(0);
expect(roundPercent(105)).toBe(100);
});
it("roundAlpha clamps to 0-1", { timeout: 5000 }, () => {
expect(roundAlpha(0.5)).toBe(0.5);
expect(roundAlpha(-0.1)).toBe(0);
expect(roundAlpha(1.1)).toBe(1);
});
});