-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
math.js
68 lines (57 loc) · 1.87 KB
/
math.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
/*!
* template-helpers <https://github.com/jonschlinkert/template-helpers>
*
* Copyright (c) 2015, Jon Schlinkert.
* Licensed under the MIT License.
*/
'use strict';
var assert = require('assert');
var helpers = require('..')('math');
var template = require('lodash.template');
var imports = {imports: helpers};
describe('math helpers', function() {
describe('add', function() {
it('should return a plus b', function() {
assert.equal(template('<%= add(5, 5) %>', imports)(), '10');
});
});
describe('subtract', function() {
it('should return a minus b.', function() {
assert.equal(template('<%= subtract(10, 2) %>', imports)(), '8');
});
});
describe('divide', function() {
it('should divide a by b.', function() {
assert.equal(template('<%= divide(30, 10) %>', imports)(), '3');
});
});
describe('multiply', function() {
it('should multiply a by b.', function() {
assert.equal(template('<%= multiply(30, 10) %>', imports)(), '300');
});
});
describe('floor', function() {
it('should floor `num`.', function() {
assert.equal(template('<%= floor(55.5) %>', imports)(), '55');
});
});
describe('ceil', function() {
it('should ceil `num`.', function() {
assert.equal(template('<%= ceil(55.5) %>', imports)(), '56');
});
});
describe('round', function() {
it('should round a number.', function() {
assert.equal(template('<%= round(21.1) %>', imports)(), '21');
assert.equal(template('<%= round(21.5) %>', imports)(), '22');
});
});
describe('sum.', function() {
it('should reduce-sum the numbers in the array.', function() {
assert.equal(template('<%= sum([1, 2, 3, 4, 5]) %>', imports)(), '15');
});
it('should ignore non-numbers.', function() {
assert.equal(template('<%= sum([1, 2, "foo", 3, 4, 5]) %>', imports)(), '15');
});
});
});