Forked from adnanrahic/additionWithOurOwnAssertion.js
Last active
May 6, 2024 16:47
-
-
Save hemanth22/03d2d638d183c9dbd4d3a7209864cee5 to your computer and use it in GitHub Desktop.
additionWithOurOwnAssertion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var assert = { | |
equal: function(firstValue, secondValue) { | |
if (firstValue != secondValue) | |
throw new Error('Assert failed, ' + firstValue + ' is not equal to ' + secondValue + '.'); | |
} | |
}; | |
function addTwoNumbers(x, y) { | |
return x + y; | |
} | |
function testAddTwoNumbers() { | |
// 1. ARRANGE | |
var x = 5; | |
var y = 1; | |
var sum1 = x + y; | |
// 2. ACT | |
var sum2 = addTwoNumbers(x, y); | |
console.log('addTwoNumbers() should return the sum of its two parameters.'); | |
console.log('Expect ' + sum1 + ' to equal ' + sum2 + '.'); | |
// 3. ASSERT | |
try { | |
assert.equal(sum1, sum2); | |
console.log('Passed.'); | |
} catch (error) { | |
console.log(error.message); | |
} | |
} | |
testAddTwoNumbers(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment