-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathunique.spec.ts
More file actions
77 lines (66 loc) · 2.39 KB
/
unique.spec.ts
File metadata and controls
77 lines (66 loc) · 2.39 KB
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
69
70
71
72
73
74
75
76
77
import {unique} from '@angular-ru/cdk/array';
describe('[TEST]: unique', () => {
const a: any = {};
const b: any = {};
const c: any = {};
it('should return empty array', () => {
expect([].filter((element, index, self) => unique(element, index, self))).toEqual(
[],
);
});
it('should return one object', () => {
expect(
[a].filter((element, index, self) => unique(element, index, self)),
).toEqual([a]);
});
it('should return the same array', () => {
expect(
[a, b, c].filter((element, index, self) => unique(element, index, self)),
).toEqual([a, b, c]);
});
it('should return array with no duplicates of objects', () => {
expect(
[a, b, c, c, a].filter((element, index, self) =>
unique(element, index, self),
),
).toEqual([a, b, c]);
});
it('should return array with no duplicates of strings', () => {
expect(
['a', 'b', 'b', 'b'].filter((element, index, self) =>
unique(element, index, self),
),
).toEqual(['a', 'b']);
});
it('should return array with no duplicates of numbers', () => {
expect(
[13, 13, 13].filter((element, index, self) => unique(element, index, self)),
).toEqual([13]);
});
it('should return array with no duplicates according to values and types', () => {
expect(
[a, a, 'a', 13, 13, '13'].filter((element, index, self) =>
unique(element, index, self),
),
).toEqual([a, 'a', 13, '13']);
});
it('should return array with no duplicates of booleans', () => {
expect(
[true, true, false].filter((element, index, self) =>
unique(element, index, self),
),
).toEqual([true, false]);
});
it('should return array with no duplicates of "no value" types', () => {
expect(
[null, null, undefined, undefined, '', '', Infinity, Infinity].filter(
(element, index, self) => unique(element, index, self),
),
).toEqual([null, undefined, '', Infinity]);
});
it('should return empty array for the array of "NaN"', () => {
expect(
[NaN, NaN].filter((element, index, self) => unique(element, index, self)),
).toEqual([]);
});
});