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
2
2
3
3
import com.github.hsz.aoc.utils.Resources
4
4
5
- abstract class Day (val number : Number ) {
5
+ abstract class Day (number : Number ) {
6
6
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" )
8
8
9
9
abstract fun part1 (input : String ): Any
10
10
11
+ fun part1 () = part1(input)
12
+
11
13
abstract fun part2 (input : String ): Any
14
+
15
+ fun part2 () = part2(input)
12
16
}
Original file line number Diff line number Diff line change 1
1
package com.github.hsz.aoc
2
2
3
3
class Day01 : Day (1 ) {
4
+
4
5
override fun part1 (input : String ): Int {
5
6
return 0
6
7
}
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
2
5
3
6
/* *
4
7
* Maps a string containing integers in new lines to a list of integers.
5
8
*/
6
- fun String.ints (): List < Int > = lines().map(String ::toInt)
9
+ fun String.ints () = lines().map(String ::toInt)
7
10
8
11
/* *
9
- * Shorthand for [String.toInt] .
12
+ * Converts string to md5 hash .
10
13
*/
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
3
3
import kotlin.test.Test
4
4
import kotlin.test.assertEquals
5
5
6
- class Day01Test : DayTest (Day01 ()) {
6
+ class Day01Test : DayTest () {
7
+
8
+ override val day = Day01 ()
9
+
7
10
@Test
8
11
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
10
14
}
11
15
12
16
@Test
13
17
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())
16
20
}
17
21
}
Original file line number Diff line number Diff line change @@ -3,14 +3,7 @@ package com.github.hsz.aoc
3
3
import org.junit.jupiter.api.AfterAll
4
4
import org.junit.jupiter.api.TestInstance
5
5
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
16
9
}
You can’t perform that action at this time.
0 commit comments