-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
test.js
53 lines (45 loc) · 1.99 KB
/
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
import test from 'ava';
import getRange from './index.js';
/** @param {import('.').Range} range */
const get = range => [...getRange(range)];
test('main', t => {
t.deepEqual(get({end: 0}), []);
t.deepEqual(get({end: 1}), [0]);
t.deepEqual(get({end: 2}), [0, 1]);
t.deepEqual(get({end: 5}), [0, 1, 2, 3, 4]);
t.deepEqual(get({end: -2}), []);
t.deepEqual(get({start: 0, end: 1}), [0]);
t.deepEqual(get({start: 0, end: 2}), [0, 1]);
t.deepEqual(get({start: 1, end: 2}), [1]);
t.deepEqual(get({start: 1, end: 5}), [1, 2, 3, 4]);
t.deepEqual(get({start: -2, end: 2}), [-2, -1, 0, 1]);
});
test('`step` option', t => {
t.deepEqual(get({start: 0, end: 2, step: 2}), [0]);
t.deepEqual(get({start: 0, end: 3, step: 2}), [0, 2]);
t.deepEqual(get({start: 0, end: 4, step: 2}), [0, 2]);
t.deepEqual(get({start: 0, end: 6, step: 2}), [0, 2, 4]);
t.deepEqual(get({start: 0, end: -1, step: -1}), [0]);
t.deepEqual(get({start: 0, end: -2, step: -1}), [0, -1]);
t.deepEqual(get({start: -1, end: -2, step: -1}), [-1]);
t.deepEqual(get({start: -1, end: -5, step: -1}), [-1, -2, -3, -4]);
t.deepEqual(get({start: 2, end: -2, step: -1}), [2, 1, 0, -1]);
t.deepEqual(get({start: 0, end: -2, step: -2}), [0]);
t.deepEqual(get({start: 0, end: -3, step: -2}), [0, -2]);
t.deepEqual(get({start: 0, end: -4, step: -2}), [0, -2]);
t.deepEqual(get({start: 0, end: -6, step: -2}), [0, -2, -4]);
});
test('`inclusive` option', t => {
t.deepEqual(get({end: 0, inclusive: true}), [0]);
t.deepEqual(get({end: 1, inclusive: true}), [0, 1]);
t.deepEqual(get({end: -2, inclusive: true}), []);
t.deepEqual(get({start: 1, end: 5, inclusive: true}), [1, 2, 3, 4, 5]);
t.deepEqual(get({start: 0, end: 2, step: 2, inclusive: true}), [0, 2]);
t.deepEqual(get({start: 0, end: 3, step: 2, inclusive: true}), [0, 2]);
t.deepEqual(get({start: 0, end: -6, step: -2, inclusive: true}), [0, -2, -4, -6]);
});
test('generator', t => {
const range = getRange({start: 0, end: 4, step: 2});
t.is(range.next().value, 0);
t.is(range.next().value, 2);
});