-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
65 lines (57 loc) · 1.99 KB
/
index.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
64
65
/* eslint-env jest */
const stalinSort = require('./index')
const { comparatorDescending } = require('./utils')
const positiveCasesDefault = [
[[5, 2, 18, 1], [5, 18]],
[[5, 2, 3, 18, 1], [5, 18]],
[['John', 'Bernie', 'Kevin', 'Arnold'], ['John', 'Kevin']],
[[], []]
]
const positiveCasesDescending = [
[[5, 2, 18, 1], [5, 2, 1]],
[[5, 2, 3, 18, 1], [5, 2, 1]],
[['John', 'Bernie', 'Kevin', 'Arnold'], ['John', 'Bernie', 'Arnold']],
[[], []]
]
const negativeCasesBadArgument = [
['number', 5, new TypeError('Argument must be an array')],
['string', '', new TypeError('Argument must be an array')],
['object', {}, new TypeError('Argument must be an array')]
]
const negativeCasesBadComparator = [
['number', 5, new TypeError('Comparator must be a function')],
['string', '', new TypeError('Comparator must be a function')],
['object', {}, new TypeError('Comparator must be a function')]
]
describe('Positive scenarios (default behaviour)', () => {
test.each(positiveCasesDefault)(
'represses %p into %p',
(argument, expectedResult) => {
expect(stalinSort(argument)).toEqual(expectedResult)
}
)
})
describe('Positive scenarios (descending order)', () => {
test.each(positiveCasesDescending)(
'represses %p into %p',
(argument, expectedResult) => {
expect(stalinSort(argument, comparatorDescending)).toEqual(expectedResult)
}
)
})
describe('Negative scenarios: error should be thrown on bad argument', () => {
test.each(negativeCasesBadArgument)(
'throws an error on argument of type %p',
(argumentType, argument, expectedResult) => {
expect(() => stalinSort(argument)).toThrowError(expectedResult)
}
)
})
describe('Negative scenarios: error should be thrown on bad comparator callback argument type', () => {
test.each(negativeCasesBadComparator)(
'throws an error on comparator of type %p',
(argumentType, argument, expectedResult) => {
expect(() => stalinSort([], argument)).toThrowError(expectedResult)
}
)
})