Merge pull request #9 from Wobbly-Wibbly/master

Visually display test error in MazeSolver.ts
This commit is contained in:
ThePrimeagen 2022-09-19 21:16:11 -06:00 committed by GitHub
commit 5e77566491
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,23 +10,36 @@ test("maze solver", function () {
"x xxxxxxxxxx",
];
const mazeResult = [
{ x: 10, y: 0 },
{ x: 10, y: 1 },
{ x: 10, y: 2 },
{ x: 10, y: 3 },
{ x: 10, y: 4 },
{ x: 9, y: 4 },
{ x: 8, y: 4 },
{ x: 7, y: 4 },
{ x: 6, y: 4 },
{ x: 5, y: 4 },
{ x: 4, y: 4 },
{ x: 3, y: 4 },
{ x: 2, y: 4 },
{ x: 1, y: 4 },
{ x: 1, y: 5 },
];
// there is only one path through
expect(maze_solver(maze, "x", {x: 10, y: 0}, {x: 1, y: 5})).toEqual([
{x: 10, y: 0},
{x: 10, y: 1},
{x: 10, y: 2},
{x: 10, y: 3},
{x: 10, y: 4},
{x: 9, y: 4},
{x: 8, y: 4},
{x: 7, y: 4},
{x: 6, y: 4},
{x: 5, y: 4},
{x: 4, y: 4},
{x: 3, y: 4},
{x: 2, y: 4},
{x: 1, y: 4},
{x: 1, y: 5},
]);
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(''));
}