forked from kevin-bennett-ags/tdd-homework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator.test.js
48 lines (42 loc) · 1.34 KB
/
calculator.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
'use strict';
const assert = require('assert');
const calculator = require('./calculator');
describe('Calculator', function() {
describe('#add()', function() {
it('should add two numbers', function() {
assert.equal(calculator.add('1,2,3,4,5'), 15);
});
it('should throw error for negative number', function() {
assert.throws(() => {
return calculator.add('1,2,3,4,-5');
}, Error, 'negatives not allowed');
});
})
describe('#multiply()', function() {
it('should multiply two numbers', function() {
assert.equal(calculator.multiply(3, 4), 12);
});
});
// test for divide
describe('#divide()', function() {
it('should divide two numbers', function() {
assert.equal(calculator.divide(12, 4), 3);
});
it('should throw error for zero divider', function() {
assert.throws(() => {
return calculator.divide(12, 0);
}, Error, 'zero is not allowed as divider');
});
});
// test of remainder
describe('#remainder()', function() {
it('should get remainder for division of two numbers', function() {
assert.equal(calculator.remainder(12, 5), 2);
});
it('should throw error for zero divider', function() {
assert.throws(() => {
return calculator.remainder(12, 0);
}, Error, 'zero is not allowed as divider');
});
});
});