Skip to content

Commit 254f90b

Browse files
added tests for Backtracking/AllCombinationsOfSizeK
1 parent 6919e85 commit 254f90b

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

Backtracking/AllCombinationsOfSizeK.js

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,7 @@ class Combinations {
3838
this.findCombinations(high, total - 1, i + 1)
3939
this.combinationArray.pop()
4040
}
41-
};
41+
}
4242
}
4343

44-
/*
45-
Driver Code
46-
47-
Test Case 1: n = 3, k = 2
48-
Test Case 2: n = 4, k = 2
49-
*/
50-
51-
console.log('\nFirst Test Case')
52-
const test1 = new Combinations(3, 2)
53-
test1.findCombinations()
54-
55-
console.log('\nSecond Test Case')
56-
const test2 = new Combinations(4, 2)
57-
test2.findCombinations()
44+
export { Combinations }
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Combinations } from '../AllCombinationsOfSizeK'
2+
3+
describe('AllCombinationsOfSizeK', () => {
4+
it('should return 3x2 matrix solution for n = 3 and k = 2', () => {
5+
const test1 = new Combinations(3, 2)
6+
expect(test1.findCombinations).toEqual([[1, 2], [1, 3], [2, 3]])
7+
})
8+
9+
it('should return 6x2 matrix solution for n = 3 and k = 2', () => {
10+
const test2 = new Combinations(4, 2)
11+
expect(test2.findCombinations).toEqual([[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]])
12+
})
13+
})

0 commit comments

Comments
 (0)