From 254f90bca1855d7d09db8c18d26bc04e9e45703e Mon Sep 17 00:00:00 2001 From: Chiranjeev <6258860@gmail.com> Date: Wed, 6 Oct 2021 14:03:27 +0530 Subject: [PATCH] added tests for Backtracking/AllCombinationsOfSizeK --- Backtracking/AllCombinationsOfSizeK.js | 17 ++--------------- .../tests/AllCombinationsOfSizeK.test.mjs | 13 +++++++++++++ 2 files changed, 15 insertions(+), 15 deletions(-) create mode 100644 Backtracking/tests/AllCombinationsOfSizeK.test.mjs diff --git a/Backtracking/AllCombinationsOfSizeK.js b/Backtracking/AllCombinationsOfSizeK.js index 3415cf777..61a1d55c3 100644 --- a/Backtracking/AllCombinationsOfSizeK.js +++ b/Backtracking/AllCombinationsOfSizeK.js @@ -38,20 +38,7 @@ class Combinations { this.findCombinations(high, total - 1, i + 1) this.combinationArray.pop() } - }; + } } -/* - Driver Code - - Test Case 1: n = 3, k = 2 - Test Case 2: n = 4, k = 2 -*/ - -console.log('\nFirst Test Case') -const test1 = new Combinations(3, 2) -test1.findCombinations() - -console.log('\nSecond Test Case') -const test2 = new Combinations(4, 2) -test2.findCombinations() +export { Combinations } diff --git a/Backtracking/tests/AllCombinationsOfSizeK.test.mjs b/Backtracking/tests/AllCombinationsOfSizeK.test.mjs new file mode 100644 index 000000000..0fb3ec1b7 --- /dev/null +++ b/Backtracking/tests/AllCombinationsOfSizeK.test.mjs @@ -0,0 +1,13 @@ +import { Combinations } from '../AllCombinationsOfSizeK' + +describe('AllCombinationsOfSizeK', () => { + it('should return 3x2 matrix solution for n = 3 and k = 2', () => { + const test1 = new Combinations(3, 2) + expect(test1.findCombinations).toEqual([[1, 2], [1, 3], [2, 3]]) + }) + + it('should return 6x2 matrix solution for n = 3 and k = 2', () => { + const test2 = new Combinations(4, 2) + expect(test2.findCombinations).toEqual([[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]]) + }) +})