Skip to content

Commit 28f13bb

Browse files
committed
Apply standard code style
Sadly, standard does not support private fields (yet)
1 parent 08effc8 commit 28f13bb

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

Backtracking/RatInAMaze.js

+5-18
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,6 @@ function getPath (grid) {
108108
* Creates an instance of the "rat in a maze" based on a given grid (maze).
109109
*/
110110
export class RatInAMaze {
111-
112-
/** Path from the source [0, 0] to the target [N-1, N-1]. */
113-
#_path = ''
114-
115-
/** Whether the rat could find a way to the target or not. */
116-
#_solved = false
117-
118111
constructor (grid) {
119112
// first, let's do some error checking on the input
120113
validateGrid(grid)
@@ -123,17 +116,11 @@ export class RatInAMaze {
123116
const solution = getPath(grid)
124117

125118
if (solution !== false) {
126-
this.#_path = solution
127-
this.#_solved = true
119+
this.path = solution
120+
this.solved = true
121+
} else {
122+
this.path = ''
123+
this.solved = false
128124
}
129125
}
130-
131-
get solved () {
132-
return this.#_solved
133-
}
134-
135-
get path () {
136-
return this.#_path
137-
}
138-
139126
}

Backtracking/tests/RatInAMaze.test.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ describe('RatInAMaze', () => {
55
const values = [undefined, null, {}, 42, 'hello, world']
66

77
for (const value of values) {
8-
expect(() => {new RatInAMaze(value)}).toThrow()
8+
// we deliberately want to check whether this constructor call fails or not
9+
// eslint-disable-next-line no-new
10+
expect(() => { new RatInAMaze(value) }).toThrow()
911
}
1012
})
1113

1214
it('should fail for an empty array', () => {
13-
expect(() => {new RatInAMaze([])}).toThrow()
15+
// we deliberately want to check whether this constructor call fails or not
16+
// eslint-disable-next-line no-new
17+
expect(() => { new RatInAMaze([]) }).toThrow()
1418
})
1519

1620
it('should fail for a non-square array', () => {
@@ -19,14 +23,18 @@ describe('RatInAMaze', () => {
1923
[0, 0]
2024
]
2125

22-
expect(() => {new RatInAMaze(array)}).toThrow()
26+
// we deliberately want to check whether this constructor call fails or not
27+
// eslint-disable-next-line no-new
28+
expect(() => { new RatInAMaze(array) }).toThrow()
2329
})
2430

2531
it('should fail for arrays containing invalid values', () => {
2632
const values = [[[2]], [['a']]]
2733

2834
for (const value of values) {
29-
expect(() => {new RatInAMaze(value)}).toThrow()
35+
// we deliberately want to check whether this constructor call fails or not
36+
// eslint-disable-next-line no-new
37+
expect(() => { new RatInAMaze(value) }).toThrow()
3038
}
3139
})
3240

0 commit comments

Comments
 (0)