File tree Expand file tree Collapse file tree 3 files changed +24
-17
lines changed Expand file tree Collapse file tree 3 files changed +24
-17
lines changed Original file line number Diff line number Diff line change 1- class NQueen {
1+ class NQueens {
22 constructor ( size ) {
3+ if ( size < 0 ) {
4+ throw RangeError ( 'Invalid board size' )
5+ }
36 this . board = new Array ( size ) . fill ( '.' ) . map ( ( ) => new Array ( size ) . fill ( '.' ) )
47 this . size = size
58 this . solutionCount = 0
@@ -61,4 +64,4 @@ class NQueen {
6164 }
6265}
6366
64- export { NQueen }
67+ export { NQueens }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ import { NQueens } from '../NQueens'
2+
3+ describe ( 'NQueens' , ( ) => {
4+ it ( 'should return 2 solutions for 4x4 size board' , ( ) => {
5+ const _4Queens = new NQueens ( 4 )
6+ _4Queens . solve ( )
7+ expect ( _4Queens . solutionCount ) . toEqual ( 2 )
8+ } )
9+
10+ it ( 'should return 92 solutions for 8x8 size board' , ( ) => {
11+ const _8Queens = new NQueens ( 8 )
12+ _8Queens . solve ( )
13+ expect ( _8Queens . solutionCount ) . toEqual ( 92 )
14+ } )
15+
16+ it ( 'should throw RangeError for negative size board' , ( ) => {
17+ expect ( ( ) => { return new NQueens ( - 1 ) } ) . toThrow ( RangeError )
18+ } )
19+ } )
You can’t perform that action at this time.
0 commit comments