BlueGit

timfa questward

Files

questward / server / tests / astar.test.js

astar.test.js

astar.test.js 617 B Download Raw
1import test from "node:test";
2import assert from "node:assert/strict";
3import { findPath } from "../src/navigation/astar.js";
4
5test("A* walks around an impassable tile", () =>
6{
7 const blocked = new Set(["1,0"]);
8 const path = findPath(0, 0, 2, 0, (x, y) => !blocked.has(`${x},${y}`), -4, -4, 4, 4);
9 assert.ok(path.length > 0);
10 assert.deepEqual(path.at(-1), { x: 2, y: 0 });
11 assert.ok(!path.some((step) => step.x === 1 && step.y === 0));
12});
13
14test("A* returns empty when the goal is blocked", () =>
15{
16 const path = findPath(0, 0, 1, 0, (x, y) => x === 0 && y === 0, -2, -2, 2, 2);
17 assert.deepEqual(path, []);
18});