-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbubblesort.spec.js
More file actions
49 lines (38 loc) · 1.32 KB
/
bubblesort.spec.js
File metadata and controls
49 lines (38 loc) · 1.32 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
41
42
43
44
45
46
47
48
49
/*describe('spy', function() {
beforeEach(function() {
swap(value1, value2, arr) = {
}
};
it("tracks that the spy was called", function() {
expect(swap).toHaveBeenCalled(6);
});
});*/
describe('Bubble Sort', function(){
let singleItemArray = [1];
let multipleItemArray = [3, 2, 5, 4, 1];
beforeAll(function () {
singleItemArray = [1];
multipleItemArray = [3, 2, 5, 4, 1];
});
it('handles an empty array', function(){
expect( bubbleSort([]) ).toEqual( [] );
});
it('handles an array with a single item', function(){
expect( bubbleSort(singleItemArray)).toEqual( [1] );
});
it('handles an array with multiple items', function(){
expect( bubbleSort(multipleItemArray)).toEqual( [1, 2, 3, 4, 5] );
});
it('when sorting an array with one item, swap is called only once', function () {
bubbleSort(singleItemArray);
expect(swap.calls.count()).toEqual(0);
});
it('when sorting an array with multiple items, swap is called the appropriate amount of times', function () {
bubbleSort(singleItemArray);
expect(swap.calls.count(multipleItemArray)).toEqual(6);
});
it('when sorting an array with multiple items, comparison is called the appropriate amount of times', function () {
bubbleSort(singleItemArray);
expect(compare.calls.count(multipleItemArray)).toEqual(16);
});
});