-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
38 lines (35 loc) · 1.6 KB
/
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
const assert = require('assert')
const { part1, part2, evaluateExpression } = require('./script')
const homework =
`1 + 2 * 3 + 4 * 5 + 6
1 + (2 * 3) + (4 * (5 + 6))
2 * 3 + (4 * 5)
5 + (8 * 3 + 9 + 3 * 4 * 3)
5 * 9 * (7 * 3 * 3 + 9 * 3 + (8 + 6 * 4))
((2 + 4 * 9) * (6 + 9 * 8 + 6) + 6) + 2 + 4 * 2`
describe('Day 18: Operation Order', () => {
describe('evaluateExpressionLeftToRight', () => {
it('should evaluate an expression from left to right', () => {
assert.strictEqual(evaluateExpression('1 + 2 * 3 + 4 * 5 + 6'), 71)
assert.strictEqual(evaluateExpression('5 + (8 * 3 + 9 + 3 * 4 * 3)'), 437)
assert.strictEqual(evaluateExpression('((2 + 4 * 9) * (6 + 9 * 8 + 6) + 6) + 2 + 4 * 2'), 13632)
})
})
describe('Part One', () => {
it('should evaluate the expression on each line of homework and provide the sum of the resulting values', () => {
assert.strictEqual(part1(homework), 26457)
})
})
describe('evaluateAdditionsFirst', () => {
it('should perform additions first', () => {
assert.strictEqual(evaluateExpression('1 + 2 * 3 + 4 * 5 + 6', true), 231)
assert.strictEqual(evaluateExpression('1 + (2 * 3) + (4 * (5 + 6))', true), 51)
assert.strictEqual(evaluateExpression('2 * 3 + (4 * 5)', true), 46)
})
})
describe('Part Two', () => {
it('should evaluate the expression on each line of homework and provide the sum of the resulting values (addition taking precedence)', () => {
assert.strictEqual(part2(homework), 694173)
})
})
})