From 28f13bb260e95b5939571edbf3be2a3ddcb477d4 Mon Sep 17 00:00:00 2001 From: Roland Hummel Date: Sun, 3 Oct 2021 16:04:06 +0200 Subject: [PATCH] Apply standard code style Sadly, standard does not support private fields (yet) --- Backtracking/RatInAMaze.js | 23 +++++------------------ Backtracking/tests/RatInAMaze.test.js | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/Backtracking/RatInAMaze.js b/Backtracking/RatInAMaze.js index 8ebdd7f44..33095e358 100644 --- a/Backtracking/RatInAMaze.js +++ b/Backtracking/RatInAMaze.js @@ -108,13 +108,6 @@ function getPath (grid) { * Creates an instance of the "rat in a maze" based on a given grid (maze). */ export class RatInAMaze { - - /** Path from the source [0, 0] to the target [N-1, N-1]. */ - #_path = '' - - /** Whether the rat could find a way to the target or not. */ - #_solved = false - constructor (grid) { // first, let's do some error checking on the input validateGrid(grid) @@ -123,17 +116,11 @@ export class RatInAMaze { const solution = getPath(grid) if (solution !== false) { - this.#_path = solution - this.#_solved = true + this.path = solution + this.solved = true + } else { + this.path = '' + this.solved = false } } - - get solved () { - return this.#_solved - } - - get path () { - return this.#_path - } - } diff --git a/Backtracking/tests/RatInAMaze.test.js b/Backtracking/tests/RatInAMaze.test.js index fed6d1bef..5f071096d 100644 --- a/Backtracking/tests/RatInAMaze.test.js +++ b/Backtracking/tests/RatInAMaze.test.js @@ -5,12 +5,16 @@ describe('RatInAMaze', () => { const values = [undefined, null, {}, 42, 'hello, world'] for (const value of values) { - expect(() => {new RatInAMaze(value)}).toThrow() + // we deliberately want to check whether this constructor call fails or not + // eslint-disable-next-line no-new + expect(() => { new RatInAMaze(value) }).toThrow() } }) it('should fail for an empty array', () => { - expect(() => {new RatInAMaze([])}).toThrow() + // we deliberately want to check whether this constructor call fails or not + // eslint-disable-next-line no-new + expect(() => { new RatInAMaze([]) }).toThrow() }) it('should fail for a non-square array', () => { @@ -19,14 +23,18 @@ describe('RatInAMaze', () => { [0, 0] ] - expect(() => {new RatInAMaze(array)}).toThrow() + // we deliberately want to check whether this constructor call fails or not + // eslint-disable-next-line no-new + expect(() => { new RatInAMaze(array) }).toThrow() }) it('should fail for arrays containing invalid values', () => { const values = [[[2]], [['a']]] for (const value of values) { - expect(() => {new RatInAMaze(value)}).toThrow() + // we deliberately want to check whether this constructor call fails or not + // eslint-disable-next-line no-new + expect(() => { new RatInAMaze(value) }).toThrow() } })