Skip to content

Commit 763cb63

Browse files
committed
Example Day01Test implementation
1 parent c9ba229 commit 763cb63

File tree

3 files changed

+36
-9
lines changed

3 files changed

+36
-9
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import com.github.hsz.aoc.Day
55
class Day01 : Day(2021, 1) {
66

77
override fun part1(input: String): Number {
8-
TODO("Not yet implemented")
8+
return 0
99
}
1010

1111
override fun part2(input: String): Number {
12-
TODO("Not yet implemented")
12+
return 0
1313
}
1414
}

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@ package com.github.hsz.aoc
33
import org.junit.jupiter.api.Assertions
44
import org.junit.jupiter.api.DynamicTest
55

6-
open class DayTest(val day: Day) {
6+
abstract class DayTest(val day: Day) {
7+
78
fun test(
8-
function: Function1<String, Number>,
9+
function: (String) -> Number,
910
answer: Number,
10-
data: Collection<Pair<String, Number>> = emptyList(),
11-
custom: Collection<Pair<Number, Number>> = emptyList(),
11+
testData: Collection<Pair<String, Number>> = emptyList(),
12+
asserts: Collection<Pair<Number, Number>> = emptyList(),
1213
) =
13-
data.mapIndexed { index, (testInput, expected) ->
14+
testData.mapIndexed { index, (testInput, expected) ->
1415
DynamicTest.dynamicTest("Test case #${index + 1}") {
1516
Assertions.assertEquals(expected, function(testInput.trimIndent()))
1617
}
1718
} +
18-
custom.mapIndexed { index, (testValue, expected) ->
19-
DynamicTest.dynamicTest("Test case #${index + 1 + data.size}") {
19+
asserts.mapIndexed { index, (testValue, expected) ->
20+
DynamicTest.dynamicTest("Test case #${index + 1 + testData.size}") {
2021
Assertions.assertEquals(expected, testValue)
2122
}
2223
} +
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.github.hsz.aoc.aoc2021
2+
3+
import com.github.hsz.aoc.DayTest
4+
import org.junit.jupiter.api.TestFactory
5+
6+
class Day01Test : DayTest(Day01()) {
7+
8+
@TestFactory
9+
fun `Part 1`() = test(
10+
function = day::part1,
11+
testData = listOf(
12+
"" to 0,
13+
),
14+
answer = 0
15+
)
16+
17+
@TestFactory
18+
fun `Part 2`() = test(
19+
function = day::part2,
20+
testData = listOf(
21+
"" to 0,
22+
),
23+
answer = 0
24+
)
25+
}
26+

0 commit comments

Comments
 (0)