Skip to content

Commit 08e8970

Browse files
committed
added tests
1 parent 901388c commit 08e8970

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import 'mocha';
2+
import { expect } from 'chai';
3+
import { ratInAMaze } from '../../../../src/js/index';
4+
5+
describe('Rat in a maze', () => {
6+
it('rat in a maze solver', () => {
7+
const maze = [
8+
[1, 0, 0, 0],
9+
[1, 1, 1, 1],
10+
[0, 0, 1, 0],
11+
[0, 1, 1, 1]
12+
];
13+
const solution = [
14+
[1, 0, 0, 0],
15+
[1, 1, 1, 0],
16+
[0, 0, 1, 0],
17+
[0, 0, 1, 1]
18+
];
19+
expect(ratInAMaze(maze)).to.deep.equal(solution);
20+
});
21+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import 'mocha';
2+
import { expect } from 'chai';
3+
import { sudokuSolver } from '../../../../src/js/index';
4+
5+
describe('Sudoku Solver', () => {
6+
it('sudoku solver', () => {
7+
const grid = [
8+
[3, 0, 6, 5, 0, 8, 4, 0, 0],
9+
[5, 2, 0, 0, 0, 0, 0, 0, 0],
10+
[0, 8, 7, 0, 0, 0, 0, 3, 1],
11+
[0, 0, 3, 0, 1, 0, 0, 8, 0],
12+
[9, 0, 0, 8, 6, 3, 0, 0, 5],
13+
[0, 5, 0, 0, 9, 0, 6, 0, 0],
14+
[1, 3, 0, 0, 0, 0, 2, 5, 0],
15+
[0, 0, 0, 0, 0, 0, 0, 7, 4],
16+
[0, 0, 5, 2, 0, 6, 3, 0, 0]
17+
];
18+
const solution = [
19+
[3, 1, 6, 5, 7, 8, 4, 9, 2],
20+
[5, 2, 9, 1, 3, 4, 7, 6, 8],
21+
[4, 8, 7, 6, 2, 9, 5, 3, 1],
22+
[2, 6, 3, 4, 1, 5, 9, 8, 7],
23+
[9, 7, 4, 8, 6, 3, 1, 2, 5],
24+
[8, 5, 1, 7, 9, 2, 6, 4, 3],
25+
[1, 3, 8, 9, 4, 7, 2, 5, 6],
26+
[6, 9, 2, 3, 5, 1, 8, 7, 4],
27+
[7, 4, 5, 2, 8, 6, 3, 1, 9]
28+
];
29+
expect(sudokuSolver(grid)).to.deep.equal(solution);
30+
});
31+
32+
it('sudoku solver 2', () => {
33+
const grid = [
34+
[5, 3, 0, 0, 7, 0, 0, 0, 0],
35+
[6, 0, 0, 1, 9, 5, 0, 0, 0],
36+
[0, 9, 8, 0, 0, 0, 0, 6, 0],
37+
[8, 0, 0, 0, 6, 0, 0, 0, 3],
38+
[4, 0, 0, 8, 0, 3, 0, 0, 1],
39+
[7, 0, 0, 0, 2, 0, 0, 0, 6],
40+
[0, 6, 0, 0, 0, 0, 2, 8, 0],
41+
[0, 0, 0, 4, 1, 9, 0, 0, 5],
42+
[0, 0, 0, 0, 8, 0, 0, 7, 9]
43+
];
44+
const solution = [
45+
[5, 3, 4, 6, 7, 8, 9, 1, 2],
46+
[6, 7, 2, 1, 9, 5, 3, 4, 8],
47+
[1, 9, 8, 3, 4, 2, 5, 6, 7],
48+
[8, 5, 9, 7, 6, 1, 4, 2, 3],
49+
[4, 2, 6, 8, 5, 3, 7, 9, 1],
50+
[7, 1, 3, 9, 2, 4, 8, 5, 6],
51+
[9, 6, 1, 5, 3, 7, 2, 8, 4],
52+
[2, 8, 7, 4, 1, 9, 6, 3, 5],
53+
[3, 4, 5, 2, 8, 6, 1, 7, 9]
54+
];
55+
expect(sudokuSolver(grid)).to.deep.equal(solution);
56+
});
57+
});

0 commit comments

Comments
 (0)