Skip to content

Instantly share code, notes, and snippets.

@suhailgupta03
Created November 22, 2023 16:28
Show Gist options
  • Save suhailgupta03/f97a2cf1f1fbfcacd0e869707069b240 to your computer and use it in GitHub Desktop.
Save suhailgupta03/f97a2cf1f1fbfcacd0e869707069b240 to your computer and use it in GitHub Desktop.
function sum(a, b) {
return a + b;
}
function divide(a, b) {
return a / b;
}
function calculatePercentage(a, b) {
return divide(a, b) * 100;
}
module.exports = {
sum,
divide,
calculatePercentage
}
const {
sum,
divide,
calculatePercentage
} = require("./calc"); // import the function
// This function tests the sum() function
// and prints a message to the console
// depending on whether the test passed or failed.
function testSum() { // This is the unit test
// because it tests a single unit of code.
const result = sum(7, 3);
const expected = 10;
if(result !== expected) {
console.log("TEST FAILED x_x");
}else {
console.log("TEST PASSED :)");
}
}
function testPercentage() {
// This is the integration test
// because it tests the integration of
// the divide() and calculatePercentage()
// functions.
const result = calculatePercentage(5, 20);
const expected = 25;
if(result !== expected) {
console.log("TEST FAILED x_x");
}else {
console.log("TEST PASSED :)");
}
}
testSum();
testPercentage();
@suhailgupta03
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment