-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickSort.spec.ts
More file actions
41 lines (35 loc) · 1.45 KB
/
quickSort.spec.ts
File metadata and controls
41 lines (35 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
41
import quickSort from './quickSort';
const sortLowToHigh = (a: number, b: number): boolean => (a < b);
const sortHighToLow = (a: number, b: number): boolean => (a > b);
describe('quick sort', () => {
it('should return an empty array when the array for sorting is empty', () => {
const arrayToSort: number[] = [];
const expectedArray: number[] = [];
expect(quickSort(arrayToSort, sortLowToHigh))
.toEqual(expectedArray);
});
it('should return an array with the element', () => {
const arrayToSort: number[] = [14];
const expectedArray: number[] = [14];
expect(quickSort(arrayToSort, sortLowToHigh))
.toEqual(expectedArray);
});
it('should return an array with two elements sorted from lowest to highest', () => {
const arrayToSort = [65, 43];
const expectedArray = [43, 65];
expect(quickSort(arrayToSort, sortLowToHigh))
.toEqual(expectedArray);
});
it('should return an array sorted from lowest to highest', () => {
const arrayToSort = [43, 65, 44, 12, 67, 1, 9, 33, 21];
const expectedArray = [1, 9, 12, 21, 33, 43, 44, 65, 67];
expect(quickSort(arrayToSort, sortLowToHigh))
.toEqual(expectedArray);
});
it('should return an array sorted from highest to lowest', () => {
const arrayToSort = [43, 65, 44, 12, 67, 1, 9, 33, 21];
const expectedArray = [67, 65, 44, 43, 33, 21, 12, 9, 1];
expect(quickSort(arrayToSort, sortHighToLow))
.toEqual(expectedArray);
});
});