Skip to content

Instantly share code, notes, and snippets.

@ShilpiMaurya
Last active Sep 1, 2019
Embed
What would you like to do?
Test Driven Development
const Calculator = {
add: (num1, num2) => {
return num1 + num2;
},
sub: (num1, num2) => {
return num1 - num2;
},
multiply: (num1, num2) => {
return num1 * num2;
}
};
const testAdd = () => {
const num1 = 2;
const num2 = 2;
const expectedOutput = 4;
const actualOutput = Calculator.add(num1, num2);
if (actualOutput === expectedOutput) {
console.log("test result: success");
} else {
console.log("test result: failed");
}
};
const testSub = () => {
const num1 = 4;
const num2 = 2;
const expectedOutput = 2;
const actualOutput = Calculator.sub(num1, num2);
if (actualOutput === expectedOutput) {
console.log("test result: success");
} else {
console.log("test result: failed");
}
};
const testMultiply = () => {
const num1 = 2;
const num2 = 2;
const expectedOutput = 4;
const actualOutput = Calculator.multiply(num1, num2);
if (actualOutput === expectedOutput) {
console.log("test result: success");
} else {
console.log("test result: failed");
}
};
testAdd();
testSub();
testMultiply();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment