@@ -34,43 +34,38 @@ function checkForZeroIndex(nestArr) {
3434}
3535
3636// **** TESTS ****:
37- let actual = zeroMatrix ( [ [ ] ] ) ;
38- let expected = [ [ ] ] ;
39- isEqual ( actual , expected ) ;
37+ const assert = require ( 'assert' ) ;
4038
41- actual = zeroMatrix ( [ [ 3 , 5 , 6 ] , [ 1 , 0 , 2 ] , [ 4 , 4 , 5 ] , [ 2 , 2 , 2 ] ] ) ;
42- expected = [ [ 3 , 0 , 6 ] , [ 0 , 0 , 0 ] , [ 4 , 0 , 5 ] , [ 2 , 0 , 2 ] ] ;
43- isEqual ( actual , expected ) ;
39+ describe ( module . filename , ( ) => {
40+ it ( 'should correctly zero out matrices' , ( ) => {
41+ let actual = zeroMatrix ( [ [ ] ] ) ;
42+ let expected = [ [ ] ] ;
43+ assert . deepEqual ( actual , expected ) ;
4444
45- actual = zeroMatrix ( [ [ 3 , 5 , 6 ] , [ 1 , 0 , 2 ] , [ 4 , 4 , 0 ] , [ 2 , 0 , 2 ] ] ) ;
46- expected = [ [ 3 , 0 , 0 ] , [ 0 , 0 , 0 ] , [ 0 , 0 , 0 ] , [ 0 , 0 , 0 ] ] ;
47- isEqual ( actual , expected ) ;
45+ actual = zeroMatrix ( [ [ 3 , 5 , 6 ] , [ 1 , 0 , 2 ] , [ 4 , 4 , 5 ] , [ 2 , 2 , 2 ] ] ) ;
46+ expected = [ [ 3 , 0 , 6 ] , [ 0 , 0 , 0 ] , [ 4 , 0 , 5 ] , [ 2 , 0 , 2 ] ] ;
47+ assert . deepEqual ( actual , expected ) ;
4848
49- actual = zeroMatrix ( [ [ 3 , 5 , 6 ] , [ 0 , 0 , 2 ] , [ 4 , 4 , 0 ] , [ 2 , 0 , 2 ] ] ) ;
50- expected = [ [ 0 , 0 , 0 ] , [ 0 , 0 , 0 ] , [ 0 , 0 , 0 ] , [ 0 , 0 , 0 ] ] ;
51- isEqual ( actual , expected ) ;
49+ actual = zeroMatrix ( [ [ 3 , 5 , 6 ] , [ 1 , 0 , 2 ] , [ 4 , 4 , 0 ] , [ 2 , 0 , 2 ] ] ) ;
50+ expected = [ [ 3 , 0 , 0 ] , [ 0 , 0 , 0 ] , [ 0 , 0 , 0 ] , [ 0 , 0 , 0 ] ] ;
51+ assert . deepEqual ( actual , expected ) ;
5252
53- function isEqual ( actual , expected ) {
54- console . log ( JSON . stringify ( actual ) === JSON . stringify ( expected ) ) ;
55- }
56-
57- // ****HELPER FUNCTION TESTS ****:
58- actual = checkForZeroIndex ( [ [ 1 , 2 , 0 ] ] ) ;
59- expected = { rows : { 0 : true } , columns : { 2 : true } } ;
60- testCheckForZeroIndex ( actual , expected ) ;
53+ actual = zeroMatrix ( [ [ 3 , 5 , 6 ] , [ 0 , 0 , 2 ] , [ 4 , 4 , 0 ] , [ 2 , 0 , 2 ] ] ) ;
54+ expected = [ [ 0 , 0 , 0 ] , [ 0 , 0 , 0 ] , [ 0 , 0 , 0 ] , [ 0 , 0 , 0 ] ] ;
55+ assert . deepEqual ( actual , expected ) ;
56+ } ) ;
6157
62- actual = checkForZeroIndex ( [ [ 0 ] ] ) ;
63- expected = { rows : { 0 : true } , columns : { 0 : true } } ;
64- testCheckForZeroIndex ( actual , expected ) ;
58+ it ( 'should correctly find zero indices' , ( ) => {
59+ actual = checkForZeroIndex ( [ [ 1 , 2 , 0 ] ] ) ;
60+ expected = { rows : { 0 : true } , columns : { 2 : true } } ;
61+ assert . deepEqual ( actual , expected ) ;
6562
66- actual = checkForZeroIndex ( [ [ 1 , 2 , 3 ] , [ 4 , 0 , 5 ] , [ 6 , 0 , 8 ] ] ) ;
67- expected = { rows : { 1 : true , 2 : true } , columns : { 1 : true } } ;
68- testCheckForZeroIndex ( actual , expected ) ;
63+ actual = checkForZeroIndex ( [ [ 0 ] ] ) ;
64+ expected = { rows : { 0 : true } , columns : { 0 : true } } ;
65+ assert . deepEqual ( actual , expected ) ;
6966
70- function testCheckForZeroIndex ( actual , expected ) {
71- let rows = JSON . stringify ( actual . rows ) ;
72- let cols = JSON . stringify ( actual . columns ) ;
73- let expRows = JSON . stringify ( expected . rows ) ;
74- let expCols = JSON . stringify ( expected . columns ) ;
75- console . log ( rows === expRows && cols === expCols ) ;
76- }
67+ actual = checkForZeroIndex ( [ [ 1 , 2 , 3 ] , [ 4 , 0 , 5 ] , [ 6 , 0 , 8 ] ] ) ;
68+ expected = { rows : { 1 : true , 2 : true } , columns : { 1 : true } } ;
69+ assert . deepEqual ( actual , expected ) ;
70+ } ) ;
71+ } ) ;
0 commit comments