Skip to content

Commit 56b02d2

Browse files
committed
Reorganize tests
1 parent 03eda6a commit 56b02d2

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

test/multi-integer-range.js

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ describe('MultiRange', function() {
6868
});
6969

7070
describe('#append', function() {
71-
it('must append by number', function() {
71+
it('must append values correctly', function() {
7272
t(mr('5-10').append(5), '5-10');
7373
t(mr('5-10').append(8), '5-10');
7474
t(mr('5-10').append(10), '5-10');
@@ -79,17 +79,16 @@ describe('MultiRange', function() {
7979
t(mr('5-10,15-20').append(12), '5-10,12,15-20');
8080
t(mr('5-10,15-20').append(3), '3,5-10,15-20');
8181
t(mr('5-10,15-20').append(25), '5-10,15-20,25');
82-
});
83-
it('must append range resulting in concatenation', function() {
8482
t(mr('1-10,12-15,17-20').append(11), '1-15,17-20');
85-
t(mr('1-10,12-15,17-20').appendRange(1,100), '1-100');
86-
t(mr('1-10,12-15,17-20,100').appendRange(5,14), '1-15,17-20,100');
87-
t(mr('1-10,12-15,17-20').appendRange(14,19), '1-10,12-20');
83+
t(mr('1-10,12-15,17-20').append([[1,100]]), '1-100');
84+
t(mr('1-10,12-15,17-20,100').append([[5,14]]), '1-15,17-20,100');
85+
t(mr('1-10,12-15,17-20').append([[14,19]]), '1-10,12-20');
8886
});
89-
it('must append using string', function() {
87+
it('must accept various input types', function() {
88+
t(mr('5-10,15-20').append(12), '5-10,12,15-20');
9089
t(mr('5-10,15-20').append('11-14,21-25'), '5-25');
91-
});
92-
it('must append using another MultiRange', function() {
90+
t(mr('5-10,15-20').append([12]), '5-10,12,15-20');
91+
t(mr('5-10,15-20').append([[12, 13]]), '5-10,12-13,15-20');
9392
t(mr('5-10,15-20').append(mr('11-14,21-25')), '5-25');
9493
});
9594
it('must be chainable', function() {
@@ -99,23 +98,22 @@ describe('MultiRange', function() {
9998
});
10099

101100
describe('#substract', function() {
102-
it('must subtract a value', function() {
101+
it('must subtract values correctly', function() {
103102
t(mr('1-10').subtract(100), '1-10');
104103
t(mr('1-10').subtract(0), '1-10');
105104
t(mr('1-10').subtract(11), '1-10');
106105
t(mr('1-10').subtract(1), '2-10');
107106
t(mr('1-10').subtract(10), '1-9');
108-
});
109-
it('must subtract range resulting in devision', function() {
110107
t(mr('1-10').subtractRange(1, 10), '');
111108
t(mr('1-10').subtractRange(5, 8), '1-4,9-10');
112109
t(mr('1-10,20-30').subtractRange(11, 19), '1-10,20-30');
113110
t(mr('1-10,20-30').subtractRange(5, 25), '1-4,26-30');
114111
});
115-
it('must subtract using string', function() {
112+
it('must accept various input types', function() {
113+
t(mr('1-20').subtract(5), '1-4,6-20');
116114
t(mr('1-20').subtract('5,10-15'), '1-4,6-9,16-20');
117-
});
118-
it('must subtract using another MultiRange', function() {
115+
t(mr('1-20').subtract([5,10,15]), '1-4,6-9,11-14,16-20');
116+
t(mr('1-20').subtract([[5,10]]), '1-4,11-20');
119117
t(mr('1-20').subtract(new mr('5,10-15')), '1-4,6-9,16-20');
120118
});
121119
it('must be chainable', function() {
@@ -125,13 +123,6 @@ describe('MultiRange', function() {
125123
});
126124

127125
describe('#intersect', function() {
128-
it('must accept various input types', function() {
129-
t(mr('10-15').intersect(12), '12');
130-
t(mr('10-15').intersect('12-17'), '12-15');
131-
t(mr('10-15').intersect(mr('12-17')), '12-15');
132-
t(mr('10-15').intersect(mr([[12,17]])), '12-15');
133-
t(mr('10-15').intersect(mr([12,15,17])), '12,15');
134-
});
135126
it('must calculate intersections correctly', function() {
136127
// the result must remain consistent when operands are swapped
137128
function t2(r1, r2, expected) {
@@ -146,6 +137,13 @@ describe('MultiRange', function() {
146137
t2('10-12,14-16,18-20', '10-12,14-16,18-20', '10-12,14-16,18-20');
147138
t2('10-12,14-16,18-20', '20-22,24-26,28-30', '20');
148139
});
140+
it('must accept various input types', function() {
141+
t(mr('10-15').intersect(12), '12');
142+
t(mr('10-15').intersect('12-17'), '12-15');
143+
t(mr('10-15').intersect([12,15,17]), '12,15');
144+
t(mr('10-15').intersect([[12,17]]), '12-15');
145+
t(mr('10-15').intersect(mr('12-17')), '12-15');
146+
});
149147
it('must be chainable', function() {
150148
t(mr('1-100').intersect('20-150').intersect('10-40'), '20-40');
151149
});
@@ -171,9 +169,11 @@ describe('MultiRange', function() {
171169
assert.isFalse(mr('5-20,25-100,150-300').has('5-20,25-103,150-300'));
172170
assert.isFalse(mr('5-20,25-100,150-300').has('5,80,18-7,280,100,15-20,25,200-250,301'));
173171
});
174-
it('must accept various parameters', function() {
172+
it('must accept various input types', function() {
175173
assert.isTrue(mr('5-20,25-100,150-300').has(30));
176174
assert.isFalse(mr('5-20,25-100,150-300').has(23));
175+
assert.isTrue(mr('5-20,25-100,150-300').has('30'));
176+
assert.isFalse(mr('5-20,25-100,150-300').has('23'));
177177
assert.isTrue(mr('5-20,25-100,150-300').has([10,20,30,40]));
178178
assert.isFalse(mr('5-20,25-100,150-300').has([10,20,30,40,120]));
179179
assert.isTrue(mr('5-20,25-100,150-300').has([[10,20],[30,50]]));
@@ -263,7 +263,6 @@ describe('MultiRange', function() {
263263

264264
});
265265

266-
267266
it('must not change the internal data after getRanges()', function() {
268267
var a = mr('5,12-15,100');
269268
var ranges = a.getRanges();

0 commit comments

Comments
 (0)