-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathenum.spec.js
More file actions
126 lines (108 loc) · 3.62 KB
/
enum.spec.js
File metadata and controls
126 lines (108 loc) · 3.62 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
const expect = require('chai').expect;
const Elixir = require('../build/Elixir.App');
const Tuple = require('../../../src/javascript/lib/core').default.Tuple;
const Enum = Elixir.load(Elixir.ElixirScript.Enum);
describe('Enum', () => {
it('all?/2', () => {
expect(Enum.all__qmark__([2, 4, 6], x => x % 2 === 0)).to.eql(true);
expect(Enum.all__qmark__([2, 3, 4], x => x % 2 === 0)).to.eql(false);
});
it('any?/2', () => {
expect(Enum.any__qmark__([2, 4, 6], x => x % 2 === 1)).to.eql(false);
expect(Enum.any__qmark__([2, 3, 4], x => x % 2 === 1)).to.eql(true);
});
it('at/3', () => {
expect(Enum.at([2, 4, 6], 0)).to.eql(2);
expect(Enum.at([2, 4, 6], 2)).to.eql(6);
expect(Enum.at([2, 4, 6], 4)).to.eql(null);
expect(Enum.at([2, 4, 6], 4, Symbol.for('none'))).to.eql(
Symbol.for('none'),
);
expect(Enum.at([2, 4, 6], -2)).to.eql(4);
expect(Enum.at([2, 4, 6], -4)).to.eql(null);
});
it('concat/1', () => {
expect(Enum.concat([[1, [2], 3], [4], [5, 6]])).to.eql([
1,
[2],
3,
4,
5,
6,
]);
expect(Enum.concat([[], []])).to.eql([]);
expect(Enum.concat([[]])).to.eql([]);
expect(Enum.concat([])).to.eql([]);
});
it('concat/2', () => {
expect(Enum.concat([], [1])).to.eql([1]);
expect(Enum.concat([1, [2], 3], [4, 5])).to.eql([1, [2], 3, 4, 5]);
expect(Enum.concat([], [])).to.eql([]);
});
it('count/1', () => {
expect(Enum.count([1, 2, 3])).to.eql(3);
expect(Enum.count([])).to.eql(0);
expect(Enum.count([1, true, false, null])).to.eql(4);
});
it('count/2', () => {
expect(Enum.count([1, 2, 3], x => x % 2 === 0)).to.eql(1);
expect(Enum.count([], x => x % 2 === 0)).to.eql(0);
expect(Enum.count([1, true, false, null], x => x)).to.eql(2);
});
it('drop/2', () => {
expect(Enum.drop([1, 2, 3], 0)).to.eql([1, 2, 3]);
expect(Enum.drop([1, 2, 3], 1)).to.eql([2, 3]);
expect(Enum.drop([1, 2, 3], 2)).to.eql([3]);
expect(Enum.drop([1, 2, 3], 3)).to.eql([]);
expect(Enum.drop([1, 2, 3], 4)).to.eql([]);
expect(Enum.drop([1, 2, 3], -1)).to.eql([1, 2]);
expect(Enum.drop([1, 2, 3], -2)).to.eql([1]);
expect(Enum.drop([1, 2, 3], -4)).to.eql([]);
});
it('drop_every/2', () => {
expect(Enum.drop_every([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2)).to.eql([
2,
4,
6,
8,
10,
]);
expect(Enum.drop_every([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3)).to.eql([
2,
3,
5,
6,
8,
9,
]);
expect(Enum.drop_every([], 2)).to.eql([]);
expect(Enum.drop_every([1, 2], 2)).to.eql([2]);
expect(Enum.drop_every([1, 2, 3], 0)).to.eql([1, 2, 3]);
});
it('drop_while/2', () => {
expect(Enum.drop_while([1, 2, 3, 4, 3, 2, 1], x => x <= 3)).to.eql([
4,
3,
2,
1,
]);
expect(Enum.drop_while([1, 2, 3], _ => false)).to.eql([1, 2, 3]);
expect(Enum.drop_while([1, 2, 3], x => x <= 3)).to.eql([]);
expect(Enum.drop_while([], _ => false)).to.eql([]);
});
it('empty?/1', () => {
expect(Enum.empty__qmark__([])).to.eql(true);
expect(Enum.empty__qmark__([1, 2, 3])).to.eql(false);
});
it('fetch/2', () => {
expect(Enum.fetch([66], 0)).to.eql(new Tuple(Symbol.for('ok'), 66));
expect(Enum.fetch([66], -1)).to.eql(new Tuple(Symbol.for('ok'), 66));
expect(Enum.fetch([66], 1)).to.eql(Symbol.for('error'));
expect(Enum.fetch([66], -2)).to.eql(Symbol.for('error'));
});
it('fetch!/2', () => {
expect(Enum.fetch__emark__([2, 4, 6], 0)).to.eql(2);
expect(Enum.fetch__emark__([2, 4, 6], 2)).to.eql(6);
expect(Enum.fetch__emark__([2, 4, 6], -2)).to.eql(4);
});
});