forked from ramda/ramda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd.js
40 lines (33 loc) · 1.02 KB
/
add.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
var R = require('../source/index.js');
var eq = require('./shared/eq.js');
var fc = require('fast-check');
describe('add', function() {
it('adds together two numbers', function() {
eq(R.add(3, 7), 10);
});
it('coerces its arguments to numbers', function() {
eq(R.add('1', '2'), 3);
eq(R.add(1, '2'), 3);
eq(R.add(true, false), 1);
eq(R.add(null, null), 0);
eq(R.add(undefined, undefined), NaN);
eq(R.add(new Date(1), new Date(2)), 3);
});
});
describe('add properties', function() {
it('commutative', function() {
fc.assert(fc.property(fc.integer(), fc.integer(), function(a, b) {
return R.add(a, b) === R.add(b, a);
}));
});
it('associative', function() {
fc.assert(fc.property(fc.integer(), fc.integer(), fc.integer(), function(a, b, c) {
return R.add(a, R.add(b, c)) === R.add(R.add(a, b), c);
}));
});
it('identity', function() {
fc.assert(fc.property(fc.integer(), function(a) {
return R.add(a, 0) === a && R.add(0, a) === a;
}));
});
});