mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-12-19 06:58:15 +08:00
Implemented Partition Problem, Recursive problem (#1582)
* Add Tug of War solution using backtracking
* Updated Documentation in README.md
* Added Tug of war problem link
* Updated Documentation in README.md
* Updated Documentation in README.md
* Refactor tugOfWar: remove unused vars, optimize initialization, and remove redundant checks
* Added Function Export Statment
* Updated Documentation in README.md
* Resolved Code Style --Prettier
* Rename "backtrack" to "recurse"
* Fix test case: The difference needs to be exactly 1.
* Code Modification: subsets should have sizes as close to n/2 as possible
* Updated test-case of TugOfWar
* Changed TugOfWar problem to Partition
* Modified partition problem
* Updated Documentation in README.md
* fixed code style
---------
Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Co-authored-by: Lars Müller <34514239+appgurueu@users.noreply.github.com>
This commit is contained in:
24
Recursive/test/Partition.test.js
Normal file
24
Recursive/test/Partition.test.js
Normal file
@@ -0,0 +1,24 @@
|
||||
import { canPartition } from '../Partition'
|
||||
|
||||
describe('Partition (Recursive)', () => {
|
||||
it('expects to return true for an array that can be partitioned', () => {
|
||||
const result = canPartition([1, 5, 11, 5])
|
||||
expect(result).toBe(true)
|
||||
})
|
||||
|
||||
it('expects to return false for an array that cannot be partitioned', () => {
|
||||
const result = canPartition([1, 2, 3, 5])
|
||||
expect(result).toBe(false)
|
||||
})
|
||||
|
||||
it('expects to return true for an empty array (0 elements)', () => {
|
||||
const result = canPartition([])
|
||||
expect(result).toBe(true)
|
||||
})
|
||||
|
||||
it('Throw Error for Invalid Input', () => {
|
||||
expect(() => canPartition(123)).toThrow('Invalid Input')
|
||||
expect(() => canPartition(null)).toThrow('Invalid Input')
|
||||
expect(() => canPartition(undefined)).toThrow('Invalid Input')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user