-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathsort.test.js
63 lines (49 loc) · 1.33 KB
/
sort.test.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
60
61
62
63
import bubbleSort from './bubbleSort';
import selectionSort from './selectionSort';
import insertSort from './insertSort';
import quickSort from './quickSort';
import mergeSort from './mergeSort';
describe('sort array', () => {
const result = [1, 2, 3, 4, 5];
let arr;
beforeEach(() => {
arr = [2, 5, 1, 3, 4];
});
it('bubbleSort', () => {
expect(bubbleSort(arr)).toEqual(result);
});
it('selectionSort', () => {
expect(selectionSort(arr)).toEqual(result);
});
it('insertSort', () => {
expect(insertSort(arr)).toEqual(result);
});
it('quickSort', () => {
expect(quickSort(arr)).toEqual(result);
});
it('mergeSort', () => {
expect(mergeSort(arr)).toEqual(result);
});
});
describe('sort array, throw error', () => {
const result = /1 is not an array./;
let arr;
beforeEach(() => {
arr = 1;
});
it('bubbleSort, throw error', () => {
expect(() => bubbleSort(arr)).toThrow(result);
});
it('selectionSort, throw error', () => {
expect(() => selectionSort(arr)).toThrow(result);
});
it('insertSort, throw error', () => {
expect(() => insertSort(arr)).toThrow(result);
});
it('quickSort, throw error', () => {
expect(() => quickSort(arr)).toThrow(result);
});
it('mergeSort, throw error', () => {
expect(() => mergeSort(arr)).toThrow(result);
});
});