@@ -8,7 +8,7 @@ global.console.log = console.log = jest.fn((text) => _buffer += text + "\n");
88
99const app_content = fs . readFileSync ( path . resolve ( __dirname , './app.js' ) , 'utf8' ) ;
1010
11- test ( "You should create a function named matrixBuilder" , function ( ) {
11+ test ( "You should create a function named matrixBuilder. " , function ( ) {
1212 const file = rewire ( "./app.js" ) ;
1313 const myFunc = file . __get__ ( 'matrixBuilder' ) ;
1414 expect ( myFunc ) . toBeTruthy ( ) ;
@@ -19,25 +19,28 @@ test('You have to use the console.log function to print the correct output.', fu
1919 expect ( console . log . mock . calls . length > 0 ) . toBe ( true ) ;
2020} ) ;
2121
22- test ( 'The output in the console should match the one in the instructions!' , function ( ) {
23- const _app = rewire ( './app.js' ) ;
24-
25- function matrixBuilder ( matrix ) {
26- let newMatrix = [ ] ;
27- let newArray = [ ] ;
28- for ( let x = 0 ; x < matrix ; x ++ ) {
29- newMatrix . push ( newArray )
30- }
31- for ( let i = 0 ; i < matrix ; i ++ ) {
32- newArray . push ( 1 )
33- }
34- return newMatrix
35- }
36-
37- let _test = matrixBuilder ( 5 )
38- expect ( _buffer ) . toMatch ( _test . map ( n => n ) . join ( "," ) ) ;
39- } ) ;
40-
41-
22+ test ( 'The matrix should have the ammount of rows and columns required as parameter.' , function ( ) {
23+ const file = rewire ( "./app.js" ) ;
24+ const myFunc = file . __get__ ( 'matrixBuilder' ) ;
4225
26+ let _test = myFunc ( 5 ) ;
27+ expect ( _test . length . toString ( ) ) . toMatch ( "5" ) ;
28+ expect ( _test [ 0 ] . length . toString ( ) ) . toMatch ( "5" ) ;
29+ } ) ;
4330
31+ test ( 'The matrix should only have 0 or 1 as values.' , function ( ) {
32+ const file = rewire ( "./app.js" ) ;
33+ const myFunc = file . __get__ ( 'matrixBuilder' ) ;
34+ let _test = myFunc ( 5 ) ;
35+ let findCero = false ;
36+ let findOne = false ;
37+ _test . forEach ( row => {
38+ row . forEach ( item => {
39+ if ( item == 0 ) findCero = true ;
40+ else if ( item == 1 ) findOne = true ;
41+ else throw new Exception ( "The matrix contains other items rather than 0 and 1" )
42+ } )
43+ } )
44+ expect ( findCero ) . toBe ( true ) ;
45+ expect ( findOne ) . toBe ( true ) ;
46+ } ) ;
0 commit comments