-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathshellSort.test.js
42 lines (35 loc) · 1.65 KB
/
shellSort.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
const shellSort = require('../../src/algorithms/sorting/shellSort');
const cmprArray = require('../helpers/compareArrays');
test('Keeping empty as unchanged', () => {
const inputArray = [];
const outputArray = shellSort(inputArray);
expect(cmprArray(inputArray, outputArray)).toBe(true);
});
test('Keeping sigle item unchanged', () => {
const inputArray = [7];
const outputArray = shellSort(inputArray);
expect(cmprArray(inputArray, outputArray)).toBe(true);
});
test('Keeping sorted as sorted', () => {
const inputArray = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const outputArray = shellSort(inputArray);
expect(cmprArray(inputArray, outputArray)).toBe(true);
});
test('Sorting the unsorted of positives', () => {
const inputArray = [7, 25, 16, 9, 1, 3, 4, 8, 99, 100, 2, 10000, 2000];
const sortedArray = [1, 2, 3, 4, 7, 8, 9, 16, 25, 99, 100, 2000, 10000]
const outputArray = shellSort(inputArray);
expect(cmprArray(inputArray, outputArray)).toBe(true);
});
test('Sorting the unsorted array of negatives', () => {
const inputArray = [-7, -25, -16, -9, -1, -3, -4, -8, -99, -100, -2, -10000, -2000];
const sortedArray = [-10000, -2000, -100, -99, -25, -16, -9, -8, -7, -4, -3, -2, -1]
const outputArray = shellSort(inputArray);
expect(cmprArray(inputArray, outputArray)).toBe(true);
});
test('Sorting the unsorted array of mixed values', () => {
const inputArray = [10000, -2000, 99, -100, 25, -16, 9, -8, 3, -7, 2, -4, -1];
const sortedArray = [-2000, -100, -16, -8, -7, -4, -1, 2, 3, 9, 25, 99, 10000]
const outputArray = shellSort(inputArray);
expect(cmprArray(sortedArray, outputArray)).toBe(true);
});