-
Notifications
You must be signed in to change notification settings - Fork 931
/
Copy pathsorting.spec.js
51 lines (41 loc) · 1.24 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
const {
selectionSort, insertionSort, bubbleSort, mergeSort, quickSort,
} = require('../../index');
const sortingAlgorithms = [
selectionSort,
insertionSort,
bubbleSort,
mergeSort,
quickSort,
];
sortingAlgorithms.forEach((sort) => {
describe(`Sorting with ${sort.name}`, () => {
it('should work with zero numbers', () => {
expect(sort([])).toEqual([]);
});
it('should work with one number', () => {
expect(sort([3])).toEqual([3]);
});
it('should sort numbers', () => {
expect(sort([3, 5, 0])).toEqual([0, 3, 5]);
});
it('should sort with negative numbers', () => {
expect(sort([3, -5, 0])).toEqual([-5, 0, 3]);
});
it('should sort with inverse array', () => {
expect(sort([3, 2, 1])).toEqual([1, 2, 3]);
});
it('should sort with already sorted array', () => {
expect(sort([1, 2, 3])).toEqual([1, 2, 3]);
});
it('should sort a set', () => {
expect(sort(new Set([3, 1, 2]))).toEqual([1, 2, 3]);
});
it('should sort with duplicated values', () => {
expect(sort([1, 3, 2, 1])).toEqual([1, 1, 2, 3]);
});
it('should sort with almost already sorted array', () => {
expect(sort([1, 2, 3, 0])).toEqual([0, 1, 2, 3]);
});
});
});