-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuniq-adjacent.spec.js
114 lines (109 loc) · 3.17 KB
/
uniq-adjacent.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
require('../prod/array-x');
describe('uniqAdjacent() should handle empty array', () => {
it('without selector', () => {
expect([].x.uniqAdjacent()).toEqual([]);
});
it('with selector', () => {
expect([].x.uniqAdjacent(e => e.id)).toEqual([]);
});
});
describe('uniqAdjacent() should handle one-item array', () => {
it('without selector', () => {
expect([10].x.uniqAdjacent()).toEqual([10]);
});
it('with selector', () => {
expect([{id: 10}].x.uniqAdjacent(e => e.id)).toEqual([{id: 10}]);
});
});
describe('uniqAdjacent() should handle two-items array', () => {
describe('of same value', () => {
it('without selector', () => {
expect([10, 10].x.uniqAdjacent()).toEqual([10]);
});
it('with selector', () => {
expect([{id: 10}, {id: 10}].x.uniqAdjacent(e => e.id)).toEqual([{id: 10}]);
});
});
describe('of different values', () => {
it('without selector', () => {
expect([10, 20].x.uniqAdjacent()).toEqual([10, 20]);
});
it('with selector', () => {
expect([{id: 10}, {id: 20}].x.uniqAdjacent(e => e.id)).toEqual([{id: 10}, {id: 20}]);
});
});
});
describe('uniqAdjacent() should handle 3+ items array', () => {
describe('of same value', () => {
it('without selector', () => {
expect([10, 10, 10, 10].x.uniqAdjacent()).toEqual([10]);
});
it('with selector', () => {
expect([
{id: 10}, {id: 10}, {id: 10}, {id: 10}
].x.uniqAdjacent(e => e.id)).toEqual([
{id: 10}
]);
});
});
describe('of different values', () => {
it('without selector', () => {
expect([10, 20, 30, 40].x.uniqAdjacent()).toEqual([10, 20, 30, 40]);
});
it('with selector', () => {
expect([
{id: 10}, {id: 20}, {id: 30}, {id: 40}
].x.uniqAdjacent(e => e.id)).toEqual([
{id: 10}, {id: 20}, {id: 30}, {id: 40}
]);
});
});
describe('of different pairs', () => {
it('without selector', () => {
expect([10, 20, 10, 20, 30, 30].x.uniqAdjacent()).toEqual([10, 20, 10, 20, 30]);
});
it('with selector', () => {
expect([
{id: 10}, {id: 20}, {id: 10}, {id: 20}, {id: 30}, {id: 30}
].x.uniqAdjacent(e => e.id)).toEqual([
{id: 10}, {id: 20}, {id: 10}, {id: 20}, {id: 30}
]);
});
});
describe('of symmetric values', () => {
it('without selector', () => {
expect([
1, 2, 3, 3, 2, 2, 1, 1
].x.uniqAdjacent()).toEqual([
1, 2, 3, 2, 1
]);
});
it('with selector', () => {
expect([
{ x: 1, id: 100 },
{ x: 2, id: 101 },
{ x: 3, id: 102 },
{ x: 3, id: 103 },
{ x: 2, id: 104 },
{ x: 2, id: 105 },
{ x: 1, id: 106 },
{ x: 1, id: 107 }
].x.uniqAdjacent(obj => obj.x)).toEqual([
{ x: 1, id: 100 },
{ x: 2, id: 101 },
{ x: 3, id: 102 },
{ x: 2, id: 104 },
{ x: 1, id: 106 }
]);
});
});
});
describe('uniqAdjacent() should keep', () => {
it('first occurence of item', () => {
expect([
{x:10,y:10}, {x:10,y:20}, {x:20,y:20}, {x:20,y:10}
].x.uniqAdjacent(coords => coords.x)).toEqual([
{x:10,y:10}, {x:20,y:20}
]);
});
});