Skip to content

Commit 9f743f5

Browse files
committed
Add more tests to 2024 day 9
1 parent 4ab694c commit 9f743f5

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/main/scala/eu/sim642/adventofcode2024/Day9.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ object Day9 {
2222
})._1
2323
}
2424

25+
def filesystemToString(filesystem: Filesystem): String = {
26+
val sb = new StringBuilder
27+
filesystem.foreach({
28+
case File(id, size) => sb ++= ('0' + id).toChar.toString * size // TODO: toDigit?
29+
case Free(size) => sb ++= "." * size
30+
})
31+
sb.toString
32+
}
33+
2534
trait Part {
2635
def compact(filesystem: Filesystem): Filesystem
2736

src/test/scala/eu/sim642/adventofcode2024/Day9Test.scala

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,22 @@ class Day9Test extends AnyFunSuite {
99
val exampleInput2 = "2333133121414131402"
1010

1111
test("Part 1 examples") {
12-
//assert(Part1.compactChecksum(parseFilesystem(exampleInput)) == ???)
13-
//println(Part1.compact(parseFilesystem(exampleInput)))
14-
//println(Part1.compact(parseFilesystem(exampleInput2)))
12+
assert(filesystemToString(Part1.compact(parseFilesystem(exampleInput))) ==
13+
"022111222") // trailing Free trimmed
14+
assert(filesystemToString(Part1.compact(parseFilesystem(exampleInput2))) ==
15+
"0099811188827773336446555566") // trailing Free trimmed
1516
assert(Part1.compactChecksum(parseFilesystem(exampleInput2)) == 1928)
17+
18+
assert(Part1.compactChecksum(parseFilesystem(exampleInput)) == 69) // not in text
1619
}
1720

1821
test("Part 1 input answer") {
1922
assert(Part1.compactChecksum(parseFilesystem(input)) == 6310675819476L)
2023
}
2124

2225
test("Part 2 examples") {
23-
//println(Part2.compact(parseFilesystem(exampleInput2)))
26+
assert(filesystemToString(Part2.compact(parseFilesystem(exampleInput2))) ==
27+
"00992111777.44.333....5555.6666.....8888..")
2428
assert(Part2.compactChecksum(parseFilesystem(exampleInput2)) == 2858)
2529
}
2630

0 commit comments

Comments
 (0)