Skip to content

Commit 971391d

Browse files
authored
Add better tests for Day1 (#3)
* Puzzle part 1 * Add further Day1 tests * Remove confusing comment
1 parent 192fb3a commit 971391d

File tree

4 files changed

+75
-4
lines changed

4 files changed

+75
-4
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
*.class
22
*.log
33
.metals
4+
.bloop
45
target
56
project/target

.scalafmt.conf

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
version = "2.3.2"
+35
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,46 @@
11
package advent.solutions
22

3+
/** Day 1: The Tyranny of the Rocket Equation
4+
*
5+
* @see https://adventofcode.com/2019/day/1
6+
*/
37
object Day1 {
48
// TODO: Write the code to solve day 1 here
59

10+
/** Calculates the fuel required to launch a module of a given mass
11+
*
12+
* @param mass The mass of the module
13+
* @return The fuel required to to launch the module
14+
*/
615
def fuel(mass: Int): Int = {
716
(mass / 3) - 2
817
}
918

19+
/** Calculates the sum of the fuel required to launch each module of a given mass
20+
*
21+
* @param masses The masses of each module
22+
* @return The sum of the fuel required to launch each module
23+
*/
24+
def sumOfFuel(masses: List[Int]): Int = {
25+
// This should use the Day1.fuel function above
26+
???
27+
}
28+
29+
/** Calculates the total required to launch a module, including the fuel required to launch the fuel itself
30+
*
31+
* @param mass The mass of the module
32+
* @return The fuel required to launch the module, plus the fuel required to launch that fuel
33+
*/
34+
def totalFuel(mass: Int): Int = ???
35+
36+
/** Calculates the sum of the total fuel required to launch each module of a given mass
37+
*
38+
* @param masses The masses of each module
39+
* @return The sum of the total fuel required to launch each module
40+
*/
41+
def sumOfTotalFuel(masses: List[Int]): Int = {
42+
// This should use the Day1.totalFuel function above
43+
???
44+
}
1045

1146
}

src/test/scala/advent/Day1Spec.scala

+38-4
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,53 @@ import advent.solutions._
55

66
final class Day1Spec extends FlatSpec with Matchers {
77

8-
it should "get 2 for a mass of 12" in {
8+
val input: List[Int] = List(
9+
141255, 93769, 122572, 149756, 72057, 82031, 60702, 124099, 135752, 115450,
10+
132370, 80491, 95738, 143495, 136550, 104549, 94588, 106213, 60223, 78219,
11+
60082, 118735, 127069, 101492, 110708, 141521, 117201, 61006, 117919, 90301,
12+
114235, 114314, 95737, 119737, 86881, 86544, 114809, 142720, 138854, 144712,
13+
133167, 87144, 106932, 111031, 112390, 109664, 66068, 50997, 141775, 73637,
14+
121700, 64790, 127751, 100007, 62234, 75611, 57855, 135729, 83746, 139042,
15+
112117, 76456, 129343, 50490, 146912, 77074, 147598, 149476, 101984, 85490,
16+
128768, 70178, 98111, 118362, 129962, 66553, 76347, 140614, 127431, 110969,
17+
138104, 118212, 107207, 79938, 144751, 142226, 116332, 65844, 124779,
18+
104634, 83143, 94999, 72677, 76926, 83956, 59617, 145999, 62619, 87955,
19+
143030
20+
)
21+
22+
"fuel" should "have a mass of 2 for a module of mass 12" in {
923
Day1.fuel(12) should be(2)
1024
}
1125

12-
it should "get 2 for a mass of 14" in {
26+
it should "have a mass of 2 for a module of mass 14" in {
1327
Day1.fuel(14) should be(2)
1428
}
1529

16-
it should "get 654 for a mass of 1969" in {
30+
it should "have a mass of 654 for a module of mass 1969" in {
1731
Day1.fuel(1969) should be(654)
1832
}
1933

20-
it should "get 33583 for a mass of 100756" in {
34+
it should "have a mass of 33583 for a module of mass 100756" in {
2135
Day1.fuel(100756) should be(33583)
2236
}
37+
38+
it should "solve part 1 of the puzzle" in {
39+
Day1.sumOfFuel(input) should be(3497399)
40+
}
41+
42+
"total fuel" should "have a mass of 2 for a module of mass 14" in {
43+
Day1.totalFuel(14) should be(2)
44+
}
45+
46+
it should "have a mass of 966 for a module of mass 1969" in {
47+
Day1.totalFuel(1969) should be(654)
48+
}
49+
50+
it should "have a mass of 50346 for a module of mass 100756" in {
51+
Day1.totalFuel(100756) should be(50346)
52+
}
53+
54+
it should "solve part 2 of the puzzle" in {
55+
Day1.sumOfTotalFuel(input) should be(5243207)
56+
}
2357
}

0 commit comments

Comments
 (0)