Skip to content

Commit e164622

Browse files
committed
Simplify structure and tests
1 parent 4c108e7 commit e164622

File tree

5 files changed

+25
-20
lines changed

5 files changed

+25
-20
lines changed

src/main/kotlin/com/github/hsz/aoc/Day.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ package com.github.hsz.aoc
22

33
import com.github.hsz.aoc.utils.Resources
44

5-
abstract class Day(val number: Number) {
5+
abstract class Day(number: Number) {
66

7-
val input = Resources.asString("day${number.toString().padStart(2, '0')}.txt")
7+
private val input = Resources.asString("day${number.toString().padStart(2, '0')}.txt")
88

99
abstract fun part1(input: String): Any
1010

11+
fun part1() = part1(input)
12+
1113
abstract fun part2(input: String): Any
14+
15+
fun part2() = part2(input)
1216
}

src/main/kotlin/com/github/hsz/aoc/Day01.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.github.hsz.aoc
22

33
class Day01 : Day(1) {
4+
45
override fun part1(input: String): Int {
56
return 0
67
}
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
package com.github.hsz.aoc
1+
package com.github.hsz.aoc.utils
2+
3+
import java.math.BigInteger
4+
import java.security.MessageDigest
25

36
/**
47
* Maps a string containing integers in new lines to a list of integers.
58
*/
6-
fun String.ints(): List<Int> = lines().map(String::toInt)
9+
fun String.ints() = lines().map(String::toInt)
710

811
/**
9-
* Shorthand for [String.toInt].
12+
* Converts string to md5 hash.
1013
*/
11-
operator fun String.unaryPlus() = toInt()
14+
fun String.md5(): String = BigInteger(1, MessageDigest.getInstance("MD5").digest(toByteArray())).toString(16)

src/test/kotlin/com/github/hsz/aoc/Day01Test.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@ package com.github.hsz.aoc
33
import kotlin.test.Test
44
import kotlin.test.assertEquals
55

6-
class Day01Test : DayTest(Day01()) {
6+
class Day01Test : DayTest() {
7+
8+
override val day = Day01()
9+
710
@Test
811
fun part1() {
9-
assertEquals(0, day.part1(""))
12+
assertEquals(0, day.part1("foo")) // check against test input
13+
assertEquals(0, day.part1()) // check against input data
1014
}
1115

1216
@Test
1317
fun part2() {
14-
assertEquals(0, day.part2(""))
15-
assertEquals(0, day.part2(day.input))
18+
assertEquals(0, day.part2("bar"))
19+
assertEquals(0, day.part2())
1620
}
1721
}

src/test/kotlin/com/github/hsz/aoc/DayTest.kt

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,7 @@ package com.github.hsz.aoc
33
import org.junit.jupiter.api.AfterAll
44
import org.junit.jupiter.api.TestInstance
55

6-
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
7-
abstract class DayTest(val day: Day) {
8-
@AfterAll
9-
fun solve() {
10-
with(day) {
11-
println("Solutions for Day $number:")
12-
println("Part 1: ${part1(input)}")
13-
println("Part 2: ${part2(input)}")
14-
}
15-
}
6+
abstract class DayTest {
7+
8+
abstract val day: Day
169
}

0 commit comments

Comments
 (0)