-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01-tyranny-of-the-rocket-equation.test.js
More file actions
43 lines (32 loc) · 1.07 KB
/
Copy path01-tyranny-of-the-rocket-equation.test.js
File metadata and controls
43 lines (32 loc) · 1.07 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
const {
calculateFuel,
calculateFuelRecursive,
calculateTotalFuel
} = require('./01-tyranny-of-the-rocket-equation');
describe('01 - the tyranny of the rocket equation', () => {
describe('part one', () => {
it('can calculate fuel from mass', () => {
const fuel = calculateFuel(1969);
expect(fuel).toBe(654);
});
it('can calculate total fuel requirements', () => {
const fuel = calculateTotalFuel([12, 14, 1969, 100756], calculateFuel);
expect(fuel).toBe(2 + 2 + 654 + 33583);
});
});
describe('part two', () => {
it('counts negative fuel requirement as zero', () => {
const fuel = calculateFuel(1);
expect(fuel).toBe(0);
});
it('can calculate fuel from mass recursively', () => {
const fuel = calculateFuelRecursive(14);
expect(fuel).toBe(2);
});
it('can calculate total fuel requirements recursively', () => {
const masses = [14, 1969, 100756];
const fuel = calculateTotalFuel(masses, calculateFuelRecursive);
expect(fuel).toBe(2 + 966 + 50346);
});
});
});