Skip to content

Commit 4c108e7

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

File tree

10 files changed

+57
-70
lines changed

10 files changed

+57
-70
lines changed

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1-
# advent-of-code-kotlin-template
2-
Advent of Code template project for Kotlin
1+
# Advent of Code Kotlin Template
2+
3+
[Advent of Code][aoc] – an annual event that happens in December since 2015.
4+
Every year since then, with the first of December, a programming puzzles contest are published every day for twenty-four days.
5+
A set of Christmas-oriented challenges provide an input you have to use to provide an answer using the language of your choice.
6+
Within this repository, we offer you a template prepared to use with [Kotlin][kotlin] language.
7+
8+
## Workflow
9+
**Advent of Code Kotlin Template** is a special type of GitHub repository which lets you speed up the preparation phase and start writing your solutions immediately.
310

411
![file:kotlin]
512

13+
[aoc]: https://adventofcode.com
14+
[kotlin]: https://kotlinlang.org
615
[file:kotlin]: .github/readme/kotlin.svg

build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ version = project.property("version").toString()
77

88
dependencies {
99
testImplementation(kotlin("test"))
10-
testImplementation(kotlin("test-junit5"))
1110
}
1211

1312
repositories {
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package com.github.hsz.aoc
22

3-
abstract class Day(year: Number, day: Number) {
3+
import com.github.hsz.aoc.utils.Resources
44

5-
val input = Resources.asString("aoc${year}/day${day.toString().padStart(2, '0')}.txt")
5+
abstract class Day(val number: Number) {
66

7-
abstract fun part1(input: String): Number
7+
val input = Resources.asString("day${number.toString().padStart(2, '0')}.txt")
88

9-
abstract fun part2(input: String): Number
9+
abstract fun part1(input: String): Any
10+
11+
abstract fun part2(input: String): Any
1012
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.github.hsz.aoc
2+
3+
class Day01 : Day(1) {
4+
override fun part1(input: String): Int {
5+
return 0
6+
}
7+
8+
override fun part2(input: String): Int {
9+
return 0
10+
}
11+
}

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

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/main/kotlin/com/github/hsz/aoc/Resources.kt renamed to src/main/kotlin/com/github/hsz/aoc/utils/Resources.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.github.hsz.aoc
1+
package com.github.hsz.aoc.utils
22

33
internal object Resources {
44

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.github.hsz.aoc
2+
3+
import kotlin.test.Test
4+
import kotlin.test.assertEquals
5+
6+
class Day01Test : DayTest(Day01()) {
7+
@Test
8+
fun part1() {
9+
assertEquals(0, day.part1(""))
10+
}
11+
12+
@Test
13+
fun part2() {
14+
assertEquals(0, day.part2(""))
15+
assertEquals(0, day.part2(day.input))
16+
}
17+
}
Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,16 @@
11
package com.github.hsz.aoc
22

3-
import org.junit.jupiter.api.Assertions
4-
import org.junit.jupiter.api.DynamicTest
3+
import org.junit.jupiter.api.AfterAll
4+
import org.junit.jupiter.api.TestInstance
55

6+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
67
abstract class DayTest(val day: Day) {
7-
8-
fun test(
9-
function: (String) -> Number,
10-
answer: Number,
11-
testData: Collection<Pair<String, Number>> = emptyList(),
12-
asserts: Collection<Pair<Number, Number>> = emptyList(),
13-
) =
14-
testData.mapIndexed { index, (testInput, expected) ->
15-
DynamicTest.dynamicTest("Test case #${index + 1}") {
16-
Assertions.assertEquals(expected, function(testInput.trimIndent()))
17-
}
18-
} +
19-
asserts.mapIndexed { index, (testValue, expected) ->
20-
DynamicTest.dynamicTest("Test case #${index + 1 + testData.size}") {
21-
Assertions.assertEquals(expected, testValue)
22-
}
23-
} +
24-
DynamicTest.dynamicTest("Solution") {
25-
Assertions.assertEquals(answer, function(day.input))
26-
}
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+
}
2716
}

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

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)