-
Notifications
You must be signed in to change notification settings - Fork 270
/
Copy pathget-mazePath.test.js
41 lines (30 loc) · 1.32 KB
/
get-mazePath.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const { getMazePath } = require('.');
describe('Get maze path', () => {
it('returns all possible solutions for a 2x2 grid', () => {
const expectedSolutions = ['HHVV', 'HVHV', 'HVVH', 'VHHV', 'VHVH', 'VVHH'];
expect(getMazePath(0, 0, 2, 2)).toEqual(expectedSolutions);
});
it('returns an even amount of horizontal and vertical movements', () => {
const solutions = getMazePath(0, 0, 3, 3);
solutions.forEach((solution) => {
expect(solution.length).toEqual(6);
expect(solution.match(/H/g).length).toEqual(3);
expect(solution.match(/V/g).length).toEqual(3);
});
});
it('returns the expected number of solutions based on given grids', () => {
expect(getMazePath(0, 0, 1, 1).length).toEqual(2);
expect(getMazePath(0, 0, 2, 2).length).toEqual(6);
expect(getMazePath(0, 0, 3, 3).length).toEqual(20);
expect(getMazePath(0, 0, 4, 4).length).toEqual(70);
expect(getMazePath(1, 1, 4, 4).length).toEqual(20);
});
it('returns an empty array when the start and end coordinates are equal', () => {
const solutions = getMazePath(2, 2, 2, 2);
expect(solutions).toEqual(['']);
});
it('returns an empty array when the start coordinates are greater than the end coordinates', () => {
const solutions = getMazePath(2, 2, 1, 1);
expect(solutions).toEqual([]);
});
});