Visually display test error in MazeSolver.ts
This commit is contained in:
parent
c04ba25515
commit
e143675e7f
1 changed files with 30 additions and 17 deletions
|
|
@ -10,8 +10,7 @@ test("maze solver", function () {
|
||||||
"x xxxxxxxxxx",
|
"x xxxxxxxxxx",
|
||||||
];
|
];
|
||||||
|
|
||||||
// there is only one path through
|
const mazeResult = [
|
||||||
expect(maze_solver(maze, "x", {x: 10, y: 0}, {x: 1, y: 5})).toEqual([
|
|
||||||
{ x: 10, y: 0 },
|
{ x: 10, y: 0 },
|
||||||
{ x: 10, y: 1 },
|
{ x: 10, y: 1 },
|
||||||
{ x: 10, y: 2 },
|
{ x: 10, y: 2 },
|
||||||
|
|
@ -27,6 +26,20 @@ test("maze solver", function () {
|
||||||
{ x: 2, y: 4 },
|
{ x: 2, y: 4 },
|
||||||
{ x: 1, y: 4 },
|
{ x: 1, y: 4 },
|
||||||
{ x: 1, y: 5 },
|
{ 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(''));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue