Skip to content
main
Make the player visible with a procedural 3D humanoid132be7c
JavaScript20 lines880 B
import test from "node:test";import assert from "node:assert/strict";import { lerp, clamp, interpolate, hudLayout, healthFraction, generateRoomCode } from "./render-utils.mjs";test("lerp/clamp", () => { assert.equal(lerp(0, 10, 0.5), 5); assert.equal(clamp(5, 0, 1), 1); });test("interpolate", () => {  const r = interpolate({ x: 0, y: 0 }, { x: 10, y: 20, hp: 3 }, 0.5);  assert.deepEqual(r, { x: 5, y: 10, hp: 3 });  assert.equal(interpolate({ x: 0, y: 0 }, { x: 10, y: 0 }, 9).x, 10);});test("hud", () => {  const h = hudLayout(1000, 500);  assert.equal(h.p1.w, h.p2.w);  assert.equal(h.p2.x + h.p2.w, 1000 - h.p1.x);});test("health", () => { assert.equal(healthFraction(-5), 0); assert.equal(healthFraction(50), 0.5); });test("room code", () => {  assert.equal(generateRoomCode(() => 0.999).length, 5);  assert.match(generateRoomCode(), /^[A-Z2-9]{5}$/);});