mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-05 00:01:37 +08:00

* 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>
25 lines
796 B
JavaScript
25 lines
796 B
JavaScript
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')
|
|
})
|
|
})
|