File tree 2 files changed +23
-5
lines changed
2 files changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -293,4 +293,22 @@ describe("BitMatrix", function () {
293
293
expect ( bs . getRowIndexes ( 31 ) ) . toEqual ( [ 6 , 31 ] ) ;
294
294
expect ( bs . getRowIndexes ( 32 ) ) . toEqual ( [ 6 , 32 ] ) ;
295
295
} ) ;
296
+ it ( "be able to get set bits per column when column count < row count" , function ( ) {
297
+ const bm = new BitMatrix ( 100 , 10 ) ;
298
+ bm . set ( 2 , 1 , true ) ;
299
+ bm . set ( 3 , 9 , true ) ;
300
+ expect ( bm . getIndexes ( true ) [ 0 ] ) . toEqual ( [ ] ) ;
301
+ expect ( bm . getIndexes ( true ) [ 1 ] ) . toEqual ( [ 2 ] ) ;
302
+ expect ( bm . getIndexes ( true ) [ 9 ] ) . toEqual ( [ 3 ] ) ;
303
+ bm . set ( 4 , 8 , true ) ;
304
+ expect ( bm . getIndexes ( true ) [ 0 ] ) . toEqual ( [ ] ) ;
305
+ expect ( bm . getIndexes ( true ) [ 1 ] ) . toEqual ( [ 2 ] ) ;
306
+ expect ( bm . getIndexes ( true ) [ 8 ] ) . toEqual ( [ 4 ] ) ;
307
+ expect ( bm . getIndexes ( true ) [ 9 ] ) . toEqual ( [ 3 ] ) ;
308
+ bm . set ( 4 , 8 , false ) ;
309
+ expect ( bm . getIndexes ( true ) [ 0 ] ) . toEqual ( [ ] ) ;
310
+ expect ( bm . getIndexes ( true ) [ 1 ] ) . toEqual ( [ 2 ] ) ;
311
+ expect ( bm . getIndexes ( true ) [ 8 ] ) . toEqual ( [ ] ) ;
312
+ expect ( bm . getIndexes ( true ) [ 9 ] ) . toEqual ( [ 3 ] ) ;
313
+ } ) ;
296
314
} ) ;
Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ export class BitMatrix implements IBitMatrix {
54
54
let result : number [ ] [ ] = [ ] ;
55
55
let index : number = 0 ;
56
56
if ( resultPerColumn ) {
57
- while ( index < this . rowCount ) {
57
+ while ( index < this . colCount ) {
58
58
result . push ( this . getColIndexes ( index ) ) ;
59
59
index ++ ;
60
60
}
@@ -180,11 +180,11 @@ export class BitMatrix implements IBitMatrix {
180
180
}
181
181
182
182
private validateIndex ( rowIndex : number , colIndex : number ) {
183
- if ( rowIndex > this . rowCount - 1 || rowIndex < 0 ) {
184
- throw new RangeError ( " Row index is incorrect." ) ;
183
+ if ( rowIndex >= this . rowCount || rowIndex < 0 ) {
184
+ throw new RangeError ( ` Row index is incorrect. Maximum allowed index: ${ this . rowCount - 1 } . Actual index ${ rowIndex } ` ) ;
185
185
}
186
- if ( colIndex > this . colCount - 1 || colIndex < 0 ) {
187
- throw new RangeError ( " Column index is incorrect." ) ;
186
+ if ( colIndex >= this . colCount || colIndex < 0 ) {
187
+ throw new RangeError ( ` Column index is incorrect. Maximum allowed index: ${ this . colCount - 1 } . Actual index ${ colIndex } ` ) ;
188
188
}
189
189
}
190
190
}
You can’t perform that action at this time.
0 commit comments