mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-05 00:01:37 +08:00
Comply with ESM. Convert live code example to Jest test.
This commit is contained in:
@ -47,21 +47,4 @@ const combination = (n, r) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Exports the functions to be used in other files.
|
// Exports the functions to be used in other files.
|
||||||
module.exports.factorial = factorial
|
export { factorial, permutation, combination }
|
||||||
module.exports.permutation = permutation
|
|
||||||
module.exports.combination = combination
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @example
|
|
||||||
|
|
||||||
const funcs = require("./PermutationAndCombination.js");
|
|
||||||
|
|
||||||
console.log(funcs.factorial(5));
|
|
||||||
console.log(funcs.permutation(5, 2));
|
|
||||||
console.log(funcs.combination(5, 2));
|
|
||||||
|
|
||||||
* @output
|
|
||||||
120
|
|
||||||
20
|
|
||||||
10
|
|
||||||
*/
|
|
||||||
|
19
Maths/test/PermutationAndCombination.test.js
Normal file
19
Maths/test/PermutationAndCombination.test.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import { factorial, permutation, combination } from '../PermutationAndCombination'
|
||||||
|
|
||||||
|
describe('Factorial', () => {
|
||||||
|
it('factorial(5)', () => {
|
||||||
|
expect(factorial(5)).toBe(120)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('Permutation', () => {
|
||||||
|
it('permutation(5, 2)', () => {
|
||||||
|
expect(permutation(5, 2)).toBe(20)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('Combination', () => {
|
||||||
|
it('combination(5, 2)', () => {
|
||||||
|
expect(combination(5, 2)).toBe(10)
|
||||||
|
})
|
||||||
|
})
|
Reference in New Issue
Block a user