Skip to content

Commit fd6fb51

Browse files
test(2019-day-01): specs for recursive fuel calculations
1 parent 2bc9680 commit fd6fb51

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

2019/day-01/part-1/fuel-calculator.test.js

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,35 @@
11
/* eslint-env mocha */
22
const expect = require('chai').expect
3-
const { calculateFuel } = require('./fuel-calculator')
3+
const { calculateFuel, calculateFuelRecursively } = require('./fuel-calculator')
44

55
describe('--- 2019 Day 1: The Tyranny of the Rocket Equation ---', () => {
66
describe('Part 1', () => {
7-
it('calculates the fuel amount for a specified mass', () => {
8-
const inputs = [12, 14, 1969, 100756]
9-
const outputs = [2, 2, 654, 33583]
7+
describe('calculateFuel()', () => {
8+
it('calculates the fuel amount for a specified mass', () => {
9+
const inputs = [12, 14, 1969, 100756]
10+
const outputs = [2, 2, 654, 33583]
1011

11-
inputs.forEach((input, idx) => {
12-
expect(calculateFuel(input)).equals(outputs[idx])
12+
inputs.forEach((input, idx) => {
13+
expect(calculateFuel(input)).equals(outputs[idx])
14+
})
15+
})
16+
it('will not output negative quantities for fuel', () => {
17+
const inputs = [0, 1, -2345]
18+
const outputs = [0, 0, 0]
19+
20+
inputs.forEach((input, idx) => {
21+
expect(calculateFuel(input)).equals(outputs[idx])
22+
})
23+
})
24+
})
25+
describe('calculateFuelRecursively()', () => {
26+
it('calculates fuel amount for a specified mass, along with the fuel for the fuel', () => {
27+
const inputs = [14, 1969, 100756]
28+
const outputs = [2, 966, 50346]
29+
30+
inputs.forEach((input, idx) => {
31+
expect(calculateFuelRecursively(input)).equals(outputs[idx])
32+
})
1333
})
1434
})
1535
})

0 commit comments

Comments
 (0)