-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04.spec.js
More file actions
59 lines (48 loc) · 1.76 KB
/
Copy path04.spec.js
File metadata and controls
59 lines (48 loc) · 1.76 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
import {createCalculator} from './04.js'
import {expect} from 'chai'
describe ("calculator", () => {
it ("should return an object with properties add, subtract, and get functions", () => {
const calculator = createCalculator();
expect(calculator).to.be.an('object');
expect(calculator).to.have.property('add').to.be.a('function');
expect(calculator).to.have.property('subtract').to.be.a('function');
expect(calculator).to.have.property('get').to.be.a('function');
})
it ("should return 0 if input is empty", () => {
const calc = createCalculator()
const result = calc.get()
expect(result).to.equals(0)
})
it ("should return negative if positive numbers are substracted", () => {
const calc = createCalculator()
calc.subtract (4)
calc.subtract (45)
const result = calc.get()
expect(result).to.equals(-49)
})
it ("should return positive sum if positive numbers are added", () => {
const calc = createCalculator()
calc.add(5)
calc.add(5)
const result = calc.get()
expect(result).to.equals(10)
})
it ("should parse nums if they are given as string", () => {
const calc = createCalculator()
calc.add ('5')
calc.add ('5')
calc.subtract ('5')
const result = calc.get()
expect(result).to.equals(5)
})
it ("should return correct if more than one operiation is executed", () => {
const calc = createCalculator()
calc.add (15)
calc.add (5)
calc.add (-1)
calc.subtract (-2)
calc.subtract (10)
const result = calc.get()
expect(result).to.equals(11)
})
})