-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathtest.js
72 lines (60 loc) · 1.66 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import test from 'ava';
import Cycled from './index.js';
const fixture = [1, 2, 3];
test('.current()', t => {
const cycled = new Cycled(fixture);
t.is(cycled.current(), 1);
cycled.next();
t.is(cycled.current(), 2);
});
test('.next()', t => {
const cycled = new Cycled(fixture);
t.deepEqual([cycled.next(), cycled.next(), cycled.next(), cycled.next()], [2, 3, 1, 2]);
});
test('.previous()', t => {
const cycled = new Cycled(fixture);
t.deepEqual([cycled.previous(), cycled.previous(), cycled.previous(), cycled.previous()], [3, 2, 1, 3]);
});
test('.step()', t => {
const cycled = new Cycled(fixture);
t.is(cycled.step(2), 3);
t.is(cycled.step(-2), 1);
});
test('.peek()', t => {
const cycled = new Cycled(fixture);
t.is(cycled.peek(1), 2);
t.is(cycled.peek(-2), 2);
});
test('.index', t => {
const cycled = new Cycled(fixture);
t.is(cycled.index, 0);
cycled.index = 2;
t.is(cycled.index, 2);
t.is(cycled.current(), 3);
cycled.index = -7;
t.is(cycled.index, 2);
t.is(cycled.current(), 3);
});
test('.indefinitely()', t => {
const cycled = new Cycled(fixture);
t.is(cycled.indefinitely().next().value, 2);
});
test('.indefinitelyReversed()', t => {
const cycled = new Cycled(fixture);
t.is(cycled.indefinitelyReversed().next().value, 3);
});
test('.indexOf()', t => {
const cycled = new Cycled(fixture);
t.is(cycled.indexOf(3), 2);
});
test('iterable', t => {
const cycled = new Cycled(fixture);
t.is(cycled[Symbol.iterator]().next().value, 1);
});
test('iterations on destructuring', t => {
const cycled = new Cycled(fixture);
t.deepEqual([...cycled], fixture);
t.deepEqual([...cycled], fixture);
cycled.next();
t.deepEqual([...cycled], [2, 3, 1]);
});