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