-
Notifications
You must be signed in to change notification settings - Fork 392
/
range-set.test.js
76 lines (68 loc) · 1.83 KB
/
range-set.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
66
67
68
69
70
71
72
73
74
75
76
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// @flow
import { canonicalizeRangeSet } from '../../utils/range-set';
describe('canonicalizeRangeSet', function () {
it('sorts unsorted ranges', function () {
expect(
canonicalizeRangeSet([
{ start: 5, end: 6 },
{ start: 1, end: 2 },
])
).toEqual([
{ start: 1, end: 2 },
{ start: 5, end: 6 },
]);
});
it('absorbs nested ranges', function () {
expect(
canonicalizeRangeSet([
{ start: 1, end: 6 },
{ start: 3, end: 6 },
])
).toEqual([{ start: 1, end: 6 }]);
});
it('unifies overlapping ranges', function () {
expect(
canonicalizeRangeSet([
{ start: 1, end: 4 },
{ start: 3, end: 6 },
])
).toEqual([{ start: 1, end: 6 }]);
});
it('unifies adjacent ranges', function () {
expect(
canonicalizeRangeSet([
{ start: 1, end: 3 },
{ start: 3, end: 6 },
])
).toEqual([{ start: 1, end: 6 }]);
});
it('removes empty ranges', function () {
expect(
canonicalizeRangeSet([
{ start: 1, end: 3 },
{ start: 6, end: 6 },
])
).toEqual([{ start: 1, end: 3 }]);
});
it('handles this complicated example', function () {
expect(
canonicalizeRangeSet([
{ start: 1, end: 2.5 },
{ start: 1.5, end: 2 },
{ start: 1, end: 2 },
{ start: 1.7, end: 2.6 },
{ start: -4, end: -4 },
{ start: -4, end: -3.8 },
{ start: -3.5, end: 2.5 },
{ start: -3.5, end: -3 },
{ start: -6, end: -4 },
])
).toEqual([
{ start: -6, end: -3.8 },
{ start: -3.5, end: 2.6 },
]);
});
});