mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-12-19 06:58:15 +08:00
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:
36
Bit-Manipulation/test/GenerateSubSets.test.js
Normal file
36
Bit-Manipulation/test/GenerateSubSets.test.js
Normal 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')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user