import { expect, test } from "bun:test"; import { moveVector } from "../static/steer.js"; test("W walks the way you are looking, whichever way that is", () => { const east = moveVector(0, -1, 0); expect(east.x).toBeCloseTo(1, 6); expect(east.y).toBeCloseTo(0, 6); const south = moveVector(0, -1, Math.PI / 2); expect(south.x).toBeCloseTo(0, 6); expect(south.y).toBeCloseTo(1, 6); }); test("D strafes across the facing, not along it", () => { const right = moveVector(1, 0, 0); expect(right.x).toBeCloseTo(0, 6); expect(right.y).toBeCloseTo(1, 6); const other = moveVector(-1, 0, 0); expect(other.y).toBeCloseTo(-1, 6); }); test("forward and strafe together keep their length", () => { const both = moveVector(1, -1, 0.7); expect(Math.hypot(both.x, both.y)).toBeCloseTo(Math.SQRT2, 6); }); test("standing still stays still", () => { const still = moveVector(0, 0, 2.2); expect(still.x).toBeCloseTo(0, 6); expect(still.y).toBeCloseTo(0, 6); }); test("it fills the object it was given, so the input loop allocates nothing", () => { const out = { x: 0, y: 0 }; expect(moveVector(0, -1, 0, out)).toBe(out); });