Skip to content

Renamed NQueen algorithm files, variables to NQueens #1162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Backtracking/NQueen.js → Backtracking/NQueens.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
class NQueen {
class NQueens {
constructor (size) {
if (size < 0) {
throw RangeError('Invalid board size')
}
this.board = new Array(size).fill('.').map(() => new Array(size).fill('.'))
this.size = size
this.solutionCount = 0
Expand Down Expand Up @@ -61,4 +64,4 @@ class NQueen {
}
}

export { NQueen }
export { NQueens }
15 changes: 0 additions & 15 deletions Backtracking/tests/NQueen.test.js

This file was deleted.

19 changes: 19 additions & 0 deletions Backtracking/tests/NQueens.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { NQueens } from '../NQueens'

describe('NQueens', () => {
it('should return 2 solutions for 4x4 size board', () => {
const _4Queens = new NQueens(4)
_4Queens.solve()
expect(_4Queens.solutionCount).toEqual(2)
})

it('should return 92 solutions for 8x8 size board', () => {
const _8Queens = new NQueens(8)
_8Queens.solve()
expect(_8Queens.solutionCount).toEqual(92)
})

it('should throw RangeError for negative size board', () => {
expect(() => { return new NQueens(-1) }).toThrow(RangeError)
})
})