File tree Expand file tree Collapse file tree 5 files changed +25
-20
lines changed
main/kotlin/com/github/hsz/aoc
test/kotlin/com/github/hsz/aoc Expand file tree Collapse file tree 5 files changed +25
-20
lines changed Original file line number Diff line number Diff line change @@ -2,11 +2,15 @@ package com.github.hsz.aoc
22
33import 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}
Original file line number Diff line number Diff line change 11package com.github.hsz.aoc
22
33class Day01 : Day (1 ) {
4+
45 override fun part1 (input : String ): Int {
56 return 0
67 }
Original file line number Diff line number Diff line change 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 )
Original file line number Diff line number Diff line change @@ -3,15 +3,19 @@ package com.github.hsz.aoc
33import kotlin.test.Test
44import 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}
Original file line number Diff line number Diff line change @@ -3,14 +3,7 @@ package com.github.hsz.aoc
33import org.junit.jupiter.api.AfterAll
44import 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}
You can’t perform that action at this time.
0 commit comments