forked from helpers/handlebars-helpers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
math.js
88 lines (77 loc) · 2.68 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
'use strict';
require('should');
var hbs = require('handlebars');
var helpers = require('..');
helpers.math({handlebars: hbs});
describe('math', function () {
describe('add', function () {
it('should return the sum of two numbers.', function () {
var fn = hbs.compile('{{add value 5}}');
fn({value: 5}).should.equal('10');
});
});
describe('average', function () {
it('should return the average of a list of numbers:', function () {
var fn = hbs.compile('{{avg 1 2 3 4}}');
fn().should.equal('2.5');
});
it('should return the average of an array of numbers:', function () {
var fn = hbs.compile('{{avg array}}');
fn({array: [1, 3, 6, 9]}).should.equal('4.75');
});
});
describe('ceil', function () {
it('should return the value rounded up to the nearest integer.', function () {
var fn = hbs.compile('{{ceil value}}');
fn({value: 5.6}).should.equal('6');
});
});
describe('divide', function () {
it('should return the division of two numbers.', function () {
var fn = hbs.compile('{{divide value 5}}');
fn({value: 5}).should.equal('1');
});
});
describe('floor', function () {
it('should return the value rounded down to the nearest integer.', function () {
var fn = hbs.compile('{{floor value}}');
fn({value: 5.6}).should.equal('5');
});
});
describe('multiply', function () {
it('should return the multiplication of two numbers.', function () {
var fn = hbs.compile('{{multiply value 5}}');
fn({value: 5}).should.equal('25');
});
});
describe('round', function () {
it('should return the value rounded to the nearest integer.', function () {
var fn = hbs.compile('{{round value}}');
fn({value: 5.69}).should.equal('6');
});
});
describe('subtract', function () {
it('should return the difference of two numbers.', function () {
var fn = hbs.compile('{{subtract value 5}}');
fn({value: 5}).should.equal('0');
});
});
describe('sum', function () {
it('should return the sum of multiple numbers.', function () {
var fn = hbs.compile('{{sum value 67 80}}');
fn({value: 20}).should.equal('167');
});
it('should return the sum of multiple numbers.', function () {
var fn = hbs.compile('{{sum 1 2 3}}');
fn().should.equal('6');
});
it('should return the total sum of array.', function () {
var fn = hbs.compile('{{sum value}}');
fn({value: [1, 2, 3]}).should.equal('6');
});
it('should return the total sum of array and numbers.', function () {
var fn = hbs.compile('{{sum value 5}}');
fn({value: [1, 2, 3]}).should.equal('11');
});
});
});