@@ -8,7 +8,7 @@ global.console.log = console.log = jest.fn((text) => _buffer += text + "\n");
8
8
9
9
const app_content = fs . readFileSync ( path . resolve ( __dirname , './app.js' ) , 'utf8' ) ;
10
10
11
- test ( "You should create a function named matrixBuilder" , function ( ) {
11
+ test ( "You should create a function named matrixBuilder. " , function ( ) {
12
12
const file = rewire ( "./app.js" ) ;
13
13
const myFunc = file . __get__ ( 'matrixBuilder' ) ;
14
14
expect ( myFunc ) . toBeTruthy ( ) ;
@@ -19,25 +19,23 @@ test('You have to use the console.log function to print the correct output.', fu
19
19
expect ( console . log . mock . calls . length > 0 ) . toBe ( true ) ;
20
20
} ) ;
21
21
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' ) ;
42
25
26
+ let _test = myFunc ( 5 ) ;
27
+ expect ( _test . length . toString ( ) ) . toMatch ( "5" ) ;
28
+ expect ( _test [ 0 ] . length . toString ( ) ) . toMatch ( "5" ) ;
29
+ } ) ;
43
30
31
+ test ( 'The matrix should only have 0 or 1 as values.' , function ( ) {
32
+ for ( let i = 0 ; i < 5 ; i ++ ) {
33
+ for ( let j = 0 ; j < 5 ; j ++ ) {
34
+ let condition = false ;
35
+ if ( _test [ i ] [ j ] == 0 || _test [ i ] [ j ] == 1 ) {
36
+ condition = true ;
37
+ }
38
+ expect ( condition ) . toBeTruthy ( ) ;
39
+ }
40
+ }
41
+ } ) ;
0 commit comments