Skip to content

Commit dd81a89

Browse files
authored
Merge pull request #14 from tommygonzaleza/master
Issue #151 fixed, test improved and README.md example changed
2 parents d77d78d + 564fd40 commit dd81a89

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

exercises/22-Matrix-Builder/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ This number represents the amount of rows and columns for the matrix. Example:
1111
This function should return an array of arrays that represents the matrix. Example: 3 should return:
1212
```md
1313
[
14-
[1, 1, 1],
15-
[1, 1, 1],
16-
[1, 1, 1]
14+
[0, 1, 1],
15+
[1, 0, 1],
16+
[0, 0, 0]
1717
]
1818
```
1919

exercises/22-Matrix-Builder/test.js

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ global.console.log = console.log = jest.fn((text) => _buffer += text + "\n");
88

99
const 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,23 @@ 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+
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

Comments
 (0)