| 1 | import test from "node:test"; |
| 2 | import assert from "node:assert/strict"; |
| 3 | import { findPath } from "../src/navigation/astar.js"; |
| 4 | |
| 5 | test("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 | |
| 14 | test("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 | }); |