-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.js
35 lines (29 loc) · 1.31 KB
/
tests.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
const { expect } = require('chai')
const { describe, it } = require('mocha')
const calculate = require('./hazyCalculator')
describe('HazyCalculator', () => {
it('multiplies two numbers when one is stringified', () => {
const calculationSteps = ['2', '*', 4]
expect(calculate(calculationSteps)).to.equal(8)
})
it('treats null values as zeroes and includes them in the calculation', () => {
const calculationSteps = [10, '+', null]
expect(calculate(calculationSteps)).to.equal(10)
})
it('ignores undefined and empty string values and continues operation', () => {
const calculationSteps = [, , '', 23, '-', , 12] // eslint-disable-line no-sparse-arrays
expect(calculate(calculationSteps)).to.equal(11)
})
it('can perform a complex operation with multiple steps', () => {
const calculationSteps = [6, '/', '3', '*', 5]
expect(calculate(calculationSteps)).to.equal(10)
})
it('throws an error when the sequence has two operators in a row', () => {
const calculationSteps = [6, '/', '+', 3]
expect(() => calculate(calculationSteps)).to.throw('Invalid input!')
})
it('throws an error when the sequence contains non-numeric and non-operator elements', () => {
const calculationSteps = [9, 'NINE', 9]
expect(() => calculate(calculationSteps)).to.throw('Invalid input!')
})
})