forked from kiaramand/sorting
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmergesort.spec.js
More file actions
40 lines (40 loc) · 1.45 KB
/
mergesort.spec.js
File metadata and controls
40 lines (40 loc) · 1.45 KB
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
35
36
37
38
39
40
describe('Merge Sort', function(){
it('handles an empty array', function (){
expect(mergeSort([])).toEqual([]);
})
it('outputs an array of the same length as the input array', function (){
expect(mergeSort([1, 3, 2]).length).toEqual(3)
})
it('sorts an array', function () {
// expect(mergeSort([1, 3, 2])).toEqual([1, 2, 3])
// expect(mergeSort([4, 1])).toEqual([1, 4])
expect(mergeSort([4, 8, 2, 0, 3, 1, 9])).toEqual([0, 1, 2, 3, 4, 8, 9])
})
})
describe('Split Array function', function() {
it('is able to split an even array into two halves', function() {
// your code here
const testEvenArr = [1,2,3,4,5,6];
expect(split(testEvenArr)).toEqual([[1,2,3],[4,5,6]]);
});
it('is able to split an odd array into two halves', function() {
// your code here
const testOddArr = [1,2,3,4,5,6,7,8,9]
expect(split(testOddArr)).toEqual([[1,2,3,4,5],[6,7,8,9]]);
});
});
describe('Merge Array function', function() {
it('is able to merge two even arrays into a sorted array', function() {
// your code here
const first = [2,4,6];
const second = [1,3,5];
expect(merge(first,second)).toEqual([1,2,3,4,5,6]);
});
it('is able to merge two odd arrays into a sorted array', function() {
// your code here
const first = [1,3,5,7,9];
const second = [2,4,6,8];
// expect(merge(first, second)).toEqual([1,2,3,4,5,6,7,8,9]);
expect(merge([2,3,9,20],[5,8,15])).toEqual([2,3,5,8,9,15,20]);
});
});