Skip to content

Issue #151 fixed, test improved and README.md example changed #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions exercises/22-Matrix-Builder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ This number represents the amount of rows and columns for the matrix. Example:
This function should return an array of arrays that represents the matrix. Example: 3 should return:
```md
[
[1, 1, 1],
[1, 1, 1],
[1, 1, 1]
[0, 1, 1],
[1, 0, 1],
[0, 0, 0]
]
```

Expand Down
40 changes: 19 additions & 21 deletions exercises/22-Matrix-Builder/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ global.console.log = console.log = jest.fn((text) => _buffer += text + "\n");

const app_content = fs.readFileSync(path.resolve(__dirname, './app.js'), 'utf8');

test("You should create a function named matrixBuilder", function(){
test("You should create a function named matrixBuilder.", function(){
const file = rewire("./app.js");
const myFunc = file.__get__('matrixBuilder');
expect(myFunc).toBeTruthy();
Expand All @@ -19,25 +19,23 @@ test('You have to use the console.log function to print the correct output.', fu
expect(console.log.mock.calls.length > 0).toBe(true);
});

test('The output in the console should match the one in the instructions!', function () {
const _app = rewire('./app.js');

function matrixBuilder(matrix){
let newMatrix = [];
let newArray = [];
for (let x =0; x < matrix; x++){
newMatrix.push(newArray)
}
for (let i =0; i < matrix; i++){
newArray.push(1)
}
return newMatrix
}

let _test = matrixBuilder(5)
expect(_buffer).toMatch(_test.map(n => n).join(","));
});


test('The matrix should have the ammount of rows and columns required as parameter.', function () {
const file = rewire("./app.js");
const myFunc = file.__get__('matrixBuilder');

let _test = myFunc(5);
expect(_test.length.toString()).toMatch("5");
expect(_test[0].length.toString()).toMatch("5");
});

test('The matrix should only have 0 or 1 as values.', function(){
for(let i = 0; i < 5; i++){
for(let j = 0; j < 5; j++){
let condition = false;
if(_test[i][j] == 0 || _test[i][j]== 1){
condition = true;
}
expect(condition).toBeTruthy();
}
}
});