forked from ShoaibEHI/problem-solving-javascript
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfind-2-nums-adding-to-n.test.js
34 lines (28 loc) · 1.25 KB
/
find-2-nums-adding-to-n.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const { findTwoNumsAddingToN, findTwoNumsAddingToN2 } = require('.');
describe('Find two numbers adding to N', () => {
[findTwoNumsAddingToN, findTwoNumsAddingToN2].forEach((func) => {
describe(func.name, () => {
it('Should return an array with length two', () => {
expect(findTwoNumsAddingToN2([1, 2], 3).length).toBe(2);
});
it('Should return false when there is no solution', () => {
expect(findTwoNumsAddingToN2([1, 2], 5)).toBe(false);
});
it('Should return false input array length is less than 2', () => {
expect(findTwoNumsAddingToN2([5], 5)).toBe(false);
});
it('Should return negative values', () => {
expect(findTwoNumsAddingToN2([-2, 1, 2, 6, 7], 5)).toEqual(expect.arrayContaining([-2, 7]));
});
it('Should return two numbers that sum to N', () => {
expect(findTwoNumsAddingToN([1, 2, 3, 5], 5)).toEqual(expect.arrayContaining([2, 3]));
});
});
});
describe('function differences findTwoNumsAddingToN and findTwoNumsAddingToN2', () => {
it('Should return different arrays', () => {
expect(findTwoNumsAddingToN([1, 2, 3, 4], 5))
.toEqual(expect.not.arrayContaining(findTwoNumsAddingToN2([1, 2, 3, 4], 5)));
});
});
});