generated from HackYourFutureBelgium/practice-code-review
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort-numbers.spec.js
68 lines (67 loc) · 2.38 KB
/
sort-numbers.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { sortNumbers } from './sort-numbers.js';
describe('sortNumbers sorts an array of numbers', () => {
describe('sorts positive numbers', () => {
it('whole numbers', () => {
const expected = [0, 1, 2, 3, 5];
const received = sortNumbers([5, 2, 0, 3, 1]);
expect(received).toEqual(expected);
});
it('decimal numbers', () => {
const expected = [0, 1.11, 2.01, 3.8, 5.4];
const received = sortNumbers([5.4, 2.01, 3.8, 0, 1.11]);
expect(received).toEqual(expected);
});
it('mixed whole and decimal numbers', () => {
const expected = [1, 2, 3.8, 5.4];
const received = sortNumbers([5.4, 2, 3.8, 1]);
expect(received).toEqual(expected);
});
});
describe('sorts negative numbers', () => {
it('whole numbers', () => {
const expected = [-5, -3, -2, -1, 0];
const received = sortNumbers([-1, 0, -3, -2, -5]);
expect(received).toEqual(expected);
});
it('decimal numbers', () => {
const expected = [-5.09, -3.01, -2.56, -1.4, 0];
const received = sortNumbers([-1.4, -3.01, -2.56, 0, -5.09]);
expect(received).toEqual(expected);
});
it('mixed whole and decimal numbers', () => {
const expected = [-5.09, -3.01, -2, -1, 0];
const received = sortNumbers([0, -1, -3.01, -2, -5.09]);
expect(received).toEqual(expected);
});
});
describe('sorts mixed positive and negative numbers', () => {
it('whole numbers', () => {
const expected = [-2, -1, 0, 1, 2];
const received = sortNumbers([0, 1, -1, 2, -2]);
expect(received).toEqual(expected);
});
it('decimal numbers', () => {
const expected = [-2.34, -1.01, 0, 1.4, 2.99];
const received = sortNumbers([0, 1.4, -1.01, 2.99, -2.34]);
expect(received).toEqual(expected);
});
it('mixed whole and decimal numbers', () => {
const expected = [-5.09, -1, 0, 2, 3.01];
const received = sortNumbers([-1, 3.01, 0, 2, -5.09]);
expect(received).toEqual(expected);
});
});
describe('has no side-effects', () => {
it('returns a new array', () => {
const arg = [];
const returned = sortNumbers(arg);
const areDifferent = arg !== returned;
expect(areDifferent).toEqual(true);
});
it('does not modify the argument', () => {
const arg = [3, 2, 1];
sortNumbers(arg);
expect(arg).toEqual([3, 2, 1]);
});
});
});