Skip to content

Commit 85bdf71

Browse files
committed
Add tests for the max sum of subarray
1 parent fc1efae commit 85bdf71

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
3+
var maxSubArray =
4+
require('../../../src/searching/subarray/maximum-subarray-divide-and-conquer')
5+
.maxSubarray;
6+
7+
describe('Maximum subarray implemented with divide and conquer', function () {
8+
9+
it('should work with empty arrays', function () {
10+
expect(isNaN(maxSubArray([]))).toBeTruthy();
11+
});
12+
13+
it('should return the only element when an array with' +
14+
'single element is passed', function () {
15+
expect(maxSubArray([42])).toBe(42);
16+
});
17+
18+
it('should return the only negative element when an array with' +
19+
'single element is passed', function () {
20+
expect(maxSubArray([-42])).toBe(-42);
21+
});
22+
23+
it('should return the zero when an array with' +
24+
'single element, which is zero is passed', function () {
25+
expect(maxSubArray([0])).toBe(0);
26+
});
27+
28+
it('should return the max sum of a subarray', function () {
29+
expect(maxSubArray([1, -1, 2, 3, -1])).toBe(5);
30+
});
31+
32+
it('should return the max nevative number when array' +
33+
'with nevative numbers is provided', function () {
34+
expect(maxSubArray([-10, -1, -2, -3, -1])).toBe(-1);
35+
});
36+
37+
});

0 commit comments

Comments
 (0)