From 3f32320c8524437a4bebb8c08be2521e13d136be Mon Sep 17 00:00:00 2001 From: Eric Lavault <39483232+lvlte@users.noreply.github.com> Date: Sat, 9 Oct 2021 13:25:34 +0200 Subject: [PATCH] Comply with ESM. Convert live code example to Jest test. --- Maths/PermutationAndCombination.js | 19 +------------------ Maths/test/PermutationAndCombination.test.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 18 deletions(-) create mode 100644 Maths/test/PermutationAndCombination.test.js diff --git a/Maths/PermutationAndCombination.js b/Maths/PermutationAndCombination.js index 1146230fb..ba99888ce 100644 --- a/Maths/PermutationAndCombination.js +++ b/Maths/PermutationAndCombination.js @@ -47,21 +47,4 @@ const combination = (n, r) => { } // Exports the functions to be used in other files. -module.exports.factorial = factorial -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 - */ +export { factorial, permutation, combination } diff --git a/Maths/test/PermutationAndCombination.test.js b/Maths/test/PermutationAndCombination.test.js new file mode 100644 index 000000000..92fc576c1 --- /dev/null +++ b/Maths/test/PermutationAndCombination.test.js @@ -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) + }) +})