-
Notifications
You must be signed in to change notification settings - Fork 1
/
sorting.spec.js
59 lines (51 loc) · 1.86 KB
/
sorting.spec.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
describe('Bubble Sort', function(){
it('handles an empty array', function(){
expect( bubbleSort([]) ).toEqual( [] );
});
it('handles a single item array', function(){
expect( bubbleSort([13]) ).toEqual( [13] );
});
it('handles a sorted array', function(){
expect( bubbleSort([1,2,7]) ).toEqual( [1,2,7] );
});
it('handles an unsorted array', function(){
expect( bubbleSort([9,1,3,6,-1])).toEqual( [-1,1,3,6,9]);
});
});
describe('Merge Sort', function(){
it('handles an empty array', function(){
// test the merging algorithm
expect(mergeSort([])).toEqual([]);
});
it ('handles a single item array', function() {
expect(mergeSort([13])).toEqual ([13]);
});
it ('handles a sort array', function() {
expect(mergeSort([1,2,7,9])).toEqual([1,2,7,9]);
});
it ('handles an even lenghted unsorted array', function(){
expect(mergeSort([9,1,2,-1])).toEqual([-1,1,2,9]);
});
it ('handles an odd lenghted unsorted array', function(){
expect(mergeSort([9,1,2,5,-1])).toEqual([-1,1,2,5,9]);
});
});
describe('Split Array function', function() {
it('is able to split an even lengthed array into two halves', function() {
expect(split([1,2,3,5,7,8])).toEqual([[1,2,3],[5,7,8]]);
});
it('is able to split an odd lengthed array into two halves', function() {
expect(split([-1,1,2,3,5,7,8])).toEqual([[-1,1,2,3],[5,7,8]]);
});
});
describe('Merge function', function() {
it('is able to merge two sorted array', function(){
expect(merge([1],[2])).toEqual([1,2]);
});
it('is able to merge two bigger and equal size arrays', function() {
expect(merge([3,5,7],[1,2,8])).toEqual([1,2,3,5,7,8]);
});
it('is able to merge two bigger and not equal size arrays', function() {
expect(merge([3,5,7],[-1,1,2,8])).toEqual([-1,1,2,3,5,7,8]);
});
});