Browse Source

Day 3: More tests..

master
Jeremy Soumokil 2 years ago
parent
commit
5a814d807f
2 changed files with 21 additions and 2 deletions
  1. +2
    -2
      src/main/kotlin/day3/Day3.kt
  2. +19
    -0
      src/test/kotlin/day3/Day3Test.kt

+ 2
- 2
src/main/kotlin/day3/Day3.kt View File

@ -12,7 +12,7 @@ object Day3 {
} }
.sumOf { it.number } .sumOf { it.number }
private fun readLines(file: String): List<String> =
fun readLines(file: String): List<String> =
File(file) File(file)
.readLines() .readLines()
@ -28,7 +28,7 @@ object Day3 {
Part( Part(
number.toInt(), number.toInt(),
Coordinate(x, y), Coordinate(x, y),
Coordinate(x + number.length, y)
Coordinate(x + number.length - 1, y)
) )
) )
} }

+ 19
- 0
src/test/kotlin/day3/Day3Test.kt View File

@ -2,6 +2,7 @@ package day3
import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import kotlin.test.assertContentEquals
class Day3Test { class Day3Test {
@ -9,4 +10,22 @@ class Day3Test {
fun readParts() { fun readParts() {
assertEquals(4361, Day3.sumOfSelectedParts("src/test/resources/day3/input.txt")) 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)
}
)
}
} }

Loading…
Cancel
Save