test: add tests for NumberOfSubsetEqualToGivenSum (#1661)

This commit is contained in:
Piotr Idzik
2024-05-25 13:01:54 +02:00
committed by GitHub
parent 3623e4270f
commit 1554ba5f9c
2 changed files with 33 additions and 7 deletions

View File

@ -0,0 +1,25 @@
import { NumberOfSubsetSum } from '../NumberOfSubsetEqualToGivenSum'
describe('Testing NumberOfSubsetSum', () => {
it.each([
[[], 0, 1],
[[], 1, 0],
[[1], 2, 0],
[[1, 2, 3, 4, 5], 0, 1],
[[1, 1, 1, 1, 1], 5, 1],
[[1, 1, 1, 1, 1], 4, 5],
[[1, 2, 3, 3], 6, 3],
[[10, 20, 30, 1], 31, 2],
[[1, 1, 2, 2, 3, 1, 1], 4, 18]
])('check with %j and %i', (arr, sum, expected) => {
expect(NumberOfSubsetSum(arr, sum)).toBe(expected)
})
it.each([
[[1, 2], -1],
[[0, 2], 2],
[[1, -1], 0]
])('throws for %j and %i', (arr, sum) => {
expect(() => NumberOfSubsetSum(arr, sum)).toThrowError()
})
})