|
1 | 1 | /* eslint-env mocha */ |
2 | 2 | const expect = require('chai').expect |
3 | | -const { calculateFuel } = require('./fuel-calculator') |
| 3 | +const { calculateFuel, calculateFuelRecursively } = require('./fuel-calculator') |
4 | 4 |
|
5 | 5 | describe('--- 2019 Day 1: The Tyranny of the Rocket Equation ---', () => { |
6 | 6 | 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] |
10 | 11 |
|
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 | + }) |
13 | 33 | }) |
14 | 34 | }) |
15 | 35 | }) |
|
0 commit comments