forked from lodash/lodash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinRange.js
More file actions
54 lines (47 loc) · 1.66 KB
/
inRange.js
File metadata and controls
54 lines (47 loc) · 1.66 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
import assert from 'assert';
import lodashStable from 'lodash';
import { falsey, stubTrue } from './utils.js';
import inRange from '../inRange.js';
describe('inRange', function() {
it('should work with an `end`', function() {
assert.strictEqual(inRange(3, 5), true);
assert.strictEqual(inRange(5, 5), false);
assert.strictEqual(inRange(6, 5), false);
});
it('should work with a `start` and `end`', function() {
assert.strictEqual(inRange(1, 1, 5), true);
assert.strictEqual(inRange(3, 1, 5), true);
assert.strictEqual(inRange(0, 1, 5), false);
assert.strictEqual(inRange(5, 1, 5), false);
});
it('should treat falsey `start` as `0`', function() {
lodashStable.each(falsey, function(value, index) {
if (index) {
assert.strictEqual(inRange(0, value), false);
assert.strictEqual(inRange(0, value, 1), true);
} else {
assert.strictEqual(inRange(0), false);
}
});
});
it('should swap `start` and `end` when `start` > `end`', function() {
assert.strictEqual(inRange(2, 5, 1), true);
assert.strictEqual(inRange(-3, -2, -6), true);
});
it('should work with a floating point `n` value', function() {
assert.strictEqual(inRange(0.5, 5), true);
assert.strictEqual(inRange(1.2, 1, 5), true);
assert.strictEqual(inRange(5.2, 5), false);
assert.strictEqual(inRange(0.5, 1, 5), false);
});
it('should coerce arguments to finite numbers', function() {
var actual = [
inRange(0, '1'),
inRange(0, '0', 1),
inRange(0, 0, '1'),
inRange(0, NaN, 1),
inRange(-1, -1, NaN)
];
assert.deepStrictEqual(actual, lodashStable.map(actual, stubTrue));
});
});