Visually display test error in MazeSolver.ts

This commit is contained in:
Wibbly 2022-09-16 15:04:13 +02:00
parent c04ba25515
commit e143675e7f

View file

@ -10,8 +10,7 @@ test("maze solver", function () {
"x xxxxxxxxxx",
];
// there is only one path through
expect(maze_solver(maze, "x", {x: 10, y: 0}, {x: 1, y: 5})).toEqual([
const mazeResult = [
{ x: 10, y: 0 },
{ x: 10, y: 1 },
{ x: 10, y: 2 },
@ -27,6 +26,20 @@ test("maze solver", function () {
{ x: 2, y: 4 },
{ x: 1, y: 4 },
{ x: 1, y: 5 },
]);
];
// there is only one path through
const result = maze_solver(maze, "x", { x: 10, y: 0 }, { x: 1, y: 5 });
expect(drawPath(maze, result)).toEqual(drawPath(maze, mazeResult));
});
function drawPath(data: string[], path: Point[]) {
const data2 = data.map((row) => row.split(''));
path.forEach((p) => {
if (data2[p.y] && data2[p.y][p.x]) {
data2[p.y][p.x] = '*';
}
});
return data2.map(d => d.join(''));
}