feat: added find subsets algorithm using bitmanipulation (#1514)

* feat: added find subsets algorithm using bitmanipulation

* file name fix

* test file name fix

* fix: codespell fix

* error handled

* added test cases for error
This commit is contained in:
Nikunj Bisht
2023-10-26 19:08:19 +05:30
committed by GitHub
parent f67cdc3cad
commit d671327ebe
2 changed files with 70 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
import { generateSubSets } from '../GenerateSubSets'
describe('subSets', () => {
it('find the subsets', () => {
expect(generateSubSets([1, 2, 3])).toEqual([
[],
[1],
[2],
[1, 2],
[3],
[1, 3],
[2, 3],
[1, 2, 3]
])
expect(generateSubSets([1, 2])).toEqual([[], [1], [2], [1, 2]])
expect(generateSubSets([1, 2, 3])).toEqual([
[],
[1],
[2],
[1, 2],
[3],
[1, 3],
[2, 3],
[1, 2, 3]
])
expect(() => generateSubSets('invalid')).toThrow(
'Provided input is not an array'
)
expect(() =>
generateSubSets([
1, 2, 2, 1, 2, 3, 4, 3, 2, 3, 4, 3, 2, 2, 2, 3, 12, 11, 4, 2, 2, 2, 2,
1, 2, 3, 5, 6, 7, 7, 8, 6, 5, 6, 7, 8, 9, 8, 0, 6
])
).toThrow('Error size should be less than equal to 32')
})
})