|
@@ -1,103 +0,0 @@
|
1
|
|
-import { limitLastN, validateLastNLimits } from './functions';
|
2
|
|
-
|
3
|
|
-describe('limitLastN', () => {
|
4
|
|
- it('handles undefined mapping', () => {
|
5
|
|
- expect(limitLastN(0, undefined)).toBe(undefined);
|
6
|
|
- });
|
7
|
|
- describe('when a correct limit mapping is given', () => {
|
8
|
|
- const limits = new Map();
|
9
|
|
-
|
10
|
|
- limits.set(5, -1);
|
11
|
|
- limits.set(10, 8);
|
12
|
|
- limits.set(20, 5);
|
13
|
|
-
|
14
|
|
- it('returns undefined when less participants that the first limit', () => {
|
15
|
|
- expect(limitLastN(2, limits)).toBe(undefined);
|
16
|
|
- });
|
17
|
|
- it('picks the first limit correctly', () => {
|
18
|
|
- expect(limitLastN(5, limits)).toBe(-1);
|
19
|
|
- expect(limitLastN(9, limits)).toBe(-1);
|
20
|
|
- });
|
21
|
|
- it('picks the middle limit correctly', () => {
|
22
|
|
- expect(limitLastN(10, limits)).toBe(8);
|
23
|
|
- expect(limitLastN(13, limits)).toBe(8);
|
24
|
|
- expect(limitLastN(19, limits)).toBe(8);
|
25
|
|
- });
|
26
|
|
- it('picks the top limit correctly', () => {
|
27
|
|
- expect(limitLastN(20, limits)).toBe(5);
|
28
|
|
- expect(limitLastN(23, limits)).toBe(5);
|
29
|
|
- expect(limitLastN(100, limits)).toBe(5);
|
30
|
|
- });
|
31
|
|
- });
|
32
|
|
-});
|
33
|
|
-
|
34
|
|
-describe('validateLastNLimits', () => {
|
35
|
|
- describe('validates the input by returning undefined', () => {
|
36
|
|
- it('if lastNLimits param is not an Object', () => {
|
37
|
|
- expect(validateLastNLimits(5)).toBe(undefined);
|
38
|
|
- });
|
39
|
|
- it('if any key is not a number', () => {
|
40
|
|
- const limits = {
|
41
|
|
- 'abc': 8,
|
42
|
|
- 5: -1,
|
43
|
|
- 20: 5
|
44
|
|
- };
|
45
|
|
-
|
46
|
|
- expect(validateLastNLimits(limits)).toBe(undefined);
|
47
|
|
- });
|
48
|
|
- it('if any value is not a number', () => {
|
49
|
|
- const limits = {
|
50
|
|
- 8: 'something',
|
51
|
|
- 5: -1,
|
52
|
|
- 20: 5
|
53
|
|
- };
|
54
|
|
-
|
55
|
|
- expect(validateLastNLimits(limits)).toBe(undefined);
|
56
|
|
- });
|
57
|
|
- it('if any value is null', () => {
|
58
|
|
- const limits = {
|
59
|
|
- 1: 1,
|
60
|
|
- 5: null,
|
61
|
|
- 20: 5
|
62
|
|
- };
|
63
|
|
-
|
64
|
|
- expect(validateLastNLimits(limits)).toBe(undefined);
|
65
|
|
- });
|
66
|
|
- it('if any value is undefined', () => {
|
67
|
|
- const limits = {
|
68
|
|
- 1: 1,
|
69
|
|
- 5: undefined,
|
70
|
|
- 20: 5
|
71
|
|
- };
|
72
|
|
-
|
73
|
|
- expect(validateLastNLimits(limits)).toBe(undefined);
|
74
|
|
- });
|
75
|
|
- it('if the map is empty', () => {
|
76
|
|
- expect(validateLastNLimits({})).toBe(undefined);
|
77
|
|
- });
|
78
|
|
- });
|
79
|
|
- it('sorts by the keys', () => {
|
80
|
|
- const mappingKeys = validateLastNLimits({
|
81
|
|
- 10: 5,
|
82
|
|
- 3: 3,
|
83
|
|
- 5: 4
|
84
|
|
- }).keys();
|
85
|
|
-
|
86
|
|
- expect(mappingKeys.next().value).toBe(3);
|
87
|
|
- expect(mappingKeys.next().value).toBe(5);
|
88
|
|
- expect(mappingKeys.next().value).toBe(10);
|
89
|
|
- expect(mappingKeys.next().done).toBe(true);
|
90
|
|
- });
|
91
|
|
- it('converts keys and values to numbers', () => {
|
92
|
|
- const mapping = validateLastNLimits({
|
93
|
|
- 3: 3,
|
94
|
|
- 5: 4,
|
95
|
|
- 10: 5
|
96
|
|
- });
|
97
|
|
-
|
98
|
|
- for (const key of mapping.keys()) {
|
99
|
|
- expect(typeof key).toBe('number');
|
100
|
|
- expect(typeof mapping.get(key)).toBe('number');
|
101
|
|
- }
|
102
|
|
- });
|
103
|
|
-});
|