Skip to content

Commit a9dcde1

Browse files
committed
Solution 2018-11: Unit test for part 2
Make the range of square sizes configurable to have the unit test run faster.
1 parent a64f453 commit a9dcde1

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

src/main/kotlin/de/ronny_h/aoc/year2018/day11/ChronalCharge.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class ChronalCharge : AdventOfCode<String>(2018, 11) {
1212
PowerCellGrid(input.single().toInt()).find3x3SquareWithLargestTotal()
1313

1414
override fun part2(input: List<String>): String =
15-
PowerCellGrid(input.single().toInt()).findSquareWithLargestTotal()
15+
PowerCellGrid(input.single().toInt()).findSquareWithLargestTotal(1..300)
1616
}
1717

1818
class PowerCellGrid(serialNumber: Int) : Grid<Int>(300, 300, -1000) {
@@ -28,8 +28,8 @@ class PowerCellGrid(serialNumber: Int) : Grid<Int>(300, 300, -1000) {
2828
}.last()
2929
}
3030

31-
fun findSquareWithLargestTotal(): String {
32-
val max = (1..300)
31+
fun findSquareWithLargestTotal(squareSizeRange: IntRange): String {
32+
val max = squareSizeRange
3333
.map {
3434
if (it % 10 == 0) println("calc for square size $it")
3535
findSquareWithLargestTotalForSize(it)

src/test/kotlin/de/ronny_h/aoc/year2018/day11/ChronalChargeTest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ class ChronalChargeTest : StringSpec({
2727
}
2828

2929
"part 2: For grid serial number 18, the largest total square is 16x16 with a top-left corner of 90,269" {
30-
// takes too long for a unit test (about 22 seconds)
31-
// ChronalCharge().part2(listOf("18")) shouldBe "90,269,16"
30+
PowerCellGrid(18).findSquareWithLargestTotal(15..17) shouldBe "90,269,16"
3231
}
3332
})

0 commit comments

Comments
 (0)