Skip to content

Commit 7cfa4ff

Browse files
committed
transforms: fix logic for outside intervals
- add a missing test cases for semi-open intervals - replace verb 'filter' by 'keep' in operation description
1 parent 7fc7dfa commit 7cfa4ff

File tree

2 files changed

+107
-24
lines changed

2 files changed

+107
-24
lines changed

src/transforms/filter.js

+19-19
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,26 @@ exports.attributes = {
4343
description: [
4444
'Sets the filter operation.',
4545

46-
'*=* filters items equal to `value`',
46+
'*=* keeps items equal to `value`',
4747

48-
'*<* filters items less than `value`',
49-
'*<=* filters items less than or equal to `value`',
48+
'*<* keeps items less than `value`',
49+
'*<=* keeps items less than or equal to `value`',
5050

51-
'*>* filters items greater than `value`',
52-
'*>=* filters items greater than or equal to `value`',
51+
'*>* keeps items greater than `value`',
52+
'*>=* keeps items greater than or equal to `value`',
5353

54-
'*[]* filters items inside `value[0]` to value[1]` including both bounds`',
55-
'*()* filters items inside `value[0]` to value[1]` excluding both bounds`',
56-
'*[)* filters items inside `value[0]` to value[1]` including `value[0]` but excluding `value[1]',
57-
'*(]* filters items inside `value[0]` to value[1]` excluding `value[0]` but including `value[1]',
54+
'*[]* keeps items inside `value[0]` to value[1]` including both bounds`',
55+
'*()* keeps items inside `value[0]` to value[1]` excluding both bounds`',
56+
'*[)* keeps items inside `value[0]` to value[1]` including `value[0]` but excluding `value[1]',
57+
'*(]* keeps items inside `value[0]` to value[1]` excluding `value[0]` but including `value[1]',
5858

59-
'*][* filters items outside `value[0]` to value[1]` and not equal to both bounds`',
60-
'*)(* filters items outside `value[0]` to value[1]`',
61-
'*](* filters items outside `value[0]` to value[1]` and not equal to `value[0]`',
62-
'*)[* filters items outside `value[0]` to value[1]` and not equal to `value[1]`',
59+
'*][* keeps items outside `value[0]` to value[1]` and equal to both bounds`',
60+
'*)(* keeps items outside `value[0]` to value[1]`',
61+
'*](* keeps items outside `value[0]` to value[1]` and equal to `value[0]`',
62+
'*)[* keeps items outside `value[0]` to value[1]` and equal to `value[1]`',
6363

64-
'*{}* filters items present in a set of values',
65-
'*}{* filters items not present in a set of values'
64+
'*{}* keeps items present in a set of values',
65+
'*}{* keeps items not present in a set of values'
6666
].join(' ')
6767
},
6868
value: {
@@ -237,25 +237,25 @@ function getFilterFunc(opts, d2c) {
237237
case '][':
238238
return function(v) {
239239
var cv = d2c(v);
240-
return cv < coercedValue[0] || cv > coercedValue[1];
240+
return cv <= coercedValue[0] || cv >= coercedValue[1];
241241
};
242242

243243
case ')(':
244244
return function(v) {
245245
var cv = d2c(v);
246-
return cv <= coercedValue[0] || cv >= coercedValue[1];
246+
return cv < coercedValue[0] || cv > coercedValue[1];
247247
};
248248

249249
case '](':
250250
return function(v) {
251251
var cv = d2c(v);
252-
return cv < coercedValue[0] || cv >= coercedValue[1];
252+
return cv <= coercedValue[0] || cv > coercedValue[1];
253253
};
254254

255255
case ')[':
256256
return function(v) {
257257
var cv = d2c(v);
258-
return cv <= coercedValue[0] || cv > coercedValue[1];
258+
return cv < coercedValue[0] || cv >= coercedValue[1];
259259
};
260260

261261
case '{}':

test/jasmine/tests/transform_filter_test.js

+88-5
Original file line numberDiff line numberDiff line change
@@ -173,18 +173,53 @@ describe('filter transforms calc:', function() {
173173
}]
174174
})]);
175175

176-
_assert(
177-
out,
176+
_assert(out,
178177
[-1, 0, 1],
179178
[2, 1, 2],
180179
[0.2, 0.1, 0.2]
181180
);
182181
});
183182

183+
it('+ *within* + with RHS open', function() {
184+
var out = _transform([Lib.extendDeep({}, _base, {
185+
transforms: [{
186+
operation: '[)',
187+
value: [-1, 1],
188+
filtersrc: 'x'
189+
}]
190+
})]);
191+
192+
_assert(out, [-1, 0], [2, 1], [0.2, 0.1]);
193+
});
194+
195+
it('+ *within* + with LHS open', function() {
196+
var out = _transform([Lib.extendDeep({}, _base, {
197+
transforms: [{
198+
operation: '(]',
199+
value: [-1, 1],
200+
filtersrc: 'x'
201+
}]
202+
})]);
203+
204+
_assert(out, [0, 1], [1, 2], [0.1, 0.2]);
205+
});
206+
207+
it('+ *within* + with both sides open', function() {
208+
var out = _transform([Lib.extendDeep({}, _base, {
209+
transforms: [{
210+
operation: '()',
211+
value: [-1, 1],
212+
filtersrc: 'x'
213+
}]
214+
})]);
215+
216+
_assert(out, [0], [1], [0.1]);
217+
});
218+
184219
it('+ *notwithin*', function() {
185220
var out = _transform([Lib.extendDeep({}, _base, {
186221
transforms: [{
187-
operation: '][',
222+
operation: ')(',
188223
value: [-1, 1],
189224
filtersrc: 'x'
190225
}]
@@ -197,6 +232,54 @@ describe('filter transforms calc:', function() {
197232
);
198233
});
199234

235+
it('+ *notwithin* with RHS closed', function() {
236+
var out = _transform([Lib.extendDeep({}, _base, {
237+
transforms: [{
238+
operation: ')[',
239+
value: [-1, 1],
240+
filtersrc: 'x'
241+
}]
242+
})]);
243+
244+
_assert(out,
245+
[-2, -2, 1, 2, 3],
246+
[1, 3, 2, 3, 1],
247+
[0.1, 0.3, 0.2, 0.3, 0.4]
248+
);
249+
});
250+
251+
it('+ *notwithin* with LHS closed', function() {
252+
var out = _transform([Lib.extendDeep({}, _base, {
253+
transforms: [{
254+
operation: '](',
255+
value: [-1, 1],
256+
filtersrc: 'x'
257+
}]
258+
})]);
259+
260+
_assert(out,
261+
[-2, -1, -2, 2, 3],
262+
[1, 2, 3, 3, 1],
263+
[0.1, 0.2, 0.3, 0.3, 0.4]
264+
);
265+
});
266+
267+
it('+ *notwithin* with both sides closed', function() {
268+
var out = _transform([Lib.extendDeep({}, _base, {
269+
transforms: [{
270+
operation: '][',
271+
value: [-1, 1],
272+
filtersrc: 'x'
273+
}]
274+
})]);
275+
276+
_assert(out,
277+
[-2, -1, -2, 1, 2, 3],
278+
[1, 2, 3, 2, 3, 1],
279+
[0.1, 0.2, 0.3, 0.2, 0.3, 0.4]
280+
);
281+
});
282+
200283
it('+ *in*', function() {
201284
var out = _transform([Lib.extendDeep({}, _base, {
202285
transforms: [{
@@ -279,7 +362,7 @@ describe('filter transforms calc:', function() {
279362
it('+ *notwithin*', function() {
280363
var out = _transform([Lib.extendDeep({}, _base, {
281364
transforms: [{
282-
operation: '][',
365+
operation: ')(',
283366
value: ['a', 'c'],
284367
filtersrc: 'x'
285368
}]
@@ -389,7 +472,7 @@ describe('filter transforms calc:', function() {
389472
it('+ *notwithin*', function() {
390473
var out = _transform([Lib.extendDeep({}, _base, {
391474
transforms: [{
392-
operation: '][',
475+
operation: ')(',
393476
value: ['2016-08-01', '2016-10-01'],
394477
filtersrc: 'x'
395478
}]

0 commit comments

Comments
 (0)