Day 3: More tests..
This commit is contained in:
1 parent
71f8edaa7a
commit
5a814d807f
2 files changed
+21
-2
No files matched your search
@@ -12,7 +12,7 @@ object Day3 {
|
||||
}
|
||||
.sumOf { it.number }
|
||||
|
||||
private fun readLines(file: String): List<String> =
|
||||
fun readLines(file: String): List<String> =
|
||||
File(file)
|
||||
.readLines()
|
||||
|
||||
@@ -28,7 +28,7 @@ object Day3 {
|
||||
Part(
|
||||
number.toInt(),
|
||||
Coordinate(x, y),
|
||||
Coordinate(x + number.length, y)
|
||||
Coordinate(x + number.length - 1, y)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package day3
|
||||
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
import kotlin.test.assertContentEquals
|
||||
|
||||
class Day3Test {
|
||||
|
||||
@@ -9,4 +10,22 @@ class Day3Test {
|
||||
fun readParts() {
|
||||
assertEquals(4361, Day3.sumOfSelectedParts("src/test/resources/day3/input.txt"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testReadParts() {
|
||||
assertContentEquals(
|
||||
listOf(467, 114, 35, 633, 617, 58, 592, 755, 664, 598),
|
||||
Day3.readParts(Day3.readLines("src/test/resources/day3/input.txt")).map(Part::number)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOnly114And58DropOut() {
|
||||
assertContentEquals(
|
||||
listOf(467, 35, 633, 617, 592, 755, 664, 598),
|
||||
Day3.readLines("src/test/resources/day3/input.txt").let { lines ->
|
||||
Day3.readParts(lines).filter { part -> part.isSelected(lines) }.map(Part::number)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user