Skip to content
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

9 iterations done #89

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
28 changes: 25 additions & 3 deletions calculator.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@
function sum(a, b) {
return;
if (b === undefined) {
b = 0;
}
if (a === undefined) {
a = 0;
}
return a + b;
}

function subtract(a, b) {
return;
if (b === undefined) {
b = 0;
}
if (a === undefined) {
a = 0;
}
return a - b;
}

function divide(a, b) {
return;
if (b === 0) {
throw new Error('Cannot divide by 0');
}
return a / b;
}

function multiply(a, b) {
if(a === 0) {
return 0;
}
if(b === 0) {
return 0;
}

return a * b;
}

Expand Down
23 changes: 23 additions & 0 deletions tests/multiply.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const { multiply } = require("../calculator");

describe("Multiply", () => {
test("should multiply two positive integers correctly", () => {
const result = multiply(2, 4);
expect(result).toBe(8);
});

test("should multiply two numbers, one positive and one negative, correctly", () => {
const result = multiply(4, -2);
expect(result).toBe(-8);
});

test("should multiply one number with zero and return 0", () => {
const result = multiply(4, 0);
expect(result).toBe(0);
});

/*test("should throw an error when multiplying by 0", () => {
expect(() => multiply(1.35, 0)).toThrow();
});
*/
});