Created
January 26, 2020 10:04
-
-
Save debonx/a1e8de5dd12eff99e6bfd14874d35124 to your computer and use it in GitHub Desktop.
Node, Mocha: Simple factorial test suite with Mocha and Node assertion methods.
This file contains 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
const Calculate = { | |
factorial(number) { | |
if(number === 0) { | |
return 1; | |
} | |
for(let i = number - 1; i >= 1; i--) { | |
number *= i; | |
} | |
return number; | |
} | |
} | |
module.exports = Calculate; |
This file contains 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 = require("assert"); | |
var Calculate = require('../factorial.js') | |
describe('Calculate', () => { | |
describe('.factorial', () => { | |
it('test factorial 5! is 120', () => { | |
// Setup | |
const expected = 120; | |
const number = 5; | |
// Exercise | |
const actual = Calculate.factorial(number); | |
// Verify | |
assert.equal(actual, expected); | |
}); | |
it('test factorial 3! is 6', () => { | |
// Setup | |
const expected = 6; | |
const number = 3; | |
// Exercise | |
const actual = Calculate.factorial(number); | |
// Verify | |
assert.equal(actual, expected); | |
}); | |
it('return 1 when 0!', () => { | |
// Setup | |
const expected = 1; | |
const number = 0; | |
// Exercise | |
const actual = Calculate.factorial(number); | |
// Verify | |
assert.equal(actual, expected); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment