| 1 |
import { expect, test } from "bun:test"; |
| 2 |
import { moveVector } from "../../static/engine/steer.js"; |
| 3 |
|
| 4 |
test("W walks the way you are looking, whichever way that is", () => { |
| 5 |
const east = moveVector(0, -1, 0); |
| 6 |
expect(east.x).toBeCloseTo(1, 6); |
| 7 |
expect(east.y).toBeCloseTo(0, 6); |
| 8 |
const south = moveVector(0, -1, Math.PI / 2); |
| 9 |
expect(south.x).toBeCloseTo(0, 6); |
| 10 |
expect(south.y).toBeCloseTo(1, 6); |
| 11 |
}); |
| 12 |
|
| 13 |
test("D strafes across the facing, not along it", () => { |
| 14 |
const right = moveVector(1, 0, 0); |
| 15 |
expect(right.x).toBeCloseTo(0, 6); |
| 16 |
expect(right.y).toBeCloseTo(1, 6); |
| 17 |
const other = moveVector(-1, 0, 0); |
| 18 |
expect(other.y).toBeCloseTo(-1, 6); |
| 19 |
}); |
| 20 |
|
| 21 |
test("forward and strafe together keep their length", () => { |
| 22 |
const both = moveVector(1, -1, 0.7); |
| 23 |
expect(Math.hypot(both.x, both.y)).toBeCloseTo(Math.SQRT2, 6); |
| 24 |
}); |
| 25 |
|
| 26 |
test("standing still stays still", () => { |
| 27 |
const still = moveVector(0, 0, 2.2); |
| 28 |
expect(still.x).toBeCloseTo(0, 6); |
| 29 |
expect(still.y).toBeCloseTo(0, 6); |
| 30 |
}); |
| 31 |
|
| 32 |
test("it fills the object it was given, so the input loop allocates nothing", () => { |
| 33 |
const out = { x: 0, y: 0 }; |
| 34 |
expect(moveVector(0, -1, 0, out)).toBe(out); |
| 35 |
}); |