AocKt (short for Advent of Code - Kotlin) is a simple library that makes running and testing your Kotlin solutions to Advent of Code puzzles a breeze.
It is an opinionated testing framework built on Kotest that defines a new AdventSpec
specialized for testing AoC puzzle solutions with minimal boilerplate.
Visit the project website for installation instructions, DSL documentation, workflow guides, advanced configuration options, and more!
For your convenience, there is an advent-of-code-kotlin-template repository which you can use to generate your own solutions repo. It comes with a pre-configured Gradle project with all bells and whistles you might need, as well as a modified source structure for easier navigation.
(If you need a working example, check out my solutions repo.)
Standalone Gradle ProjectTo add AocKt to your existing project, simply add the dependencies and configure your unit tests to run with Kotest:
plugins { kotlin("jvm") version "$kotlinVersion" } repositories { mavenCentral() } dependencies { implementation("io.github.jadarma.aockt:aockt-core:$aocktVersion") testImplementation("io.github.jadarma.aockt:aockt-test:$aocktVersion") testImplementation("io.kotest:kotest-runner-junit5:$kotestVersion") } tasks.test { useJUnitPlatform() }
AocKt provides the following DSL for testing puzzle solutions:
object Y9999D01 : Solution { // 1. override fun partOne(input: String) = spoilers() override fun partTwo(input: String) = spoilers() } @AdventDay(9999, 1, "Magic Numbers") // 2. class Y9999D01Test : AdventSpec<Y9999D01>({ // 3. partOne { // 4. "1,2,3,4" shouldOutput 4 // 5. listOf("2", "2,2", "2,4,6,8") shouldAllOutput 0 // 6. } partTwo() // 7. })
In the above example:
Solution
interface.@AdventDay
annotation. Title is optional, but the year and day are required.AdventSpec
takes in your solution as a type parameter.partOne
and partTwo
functions as needed. Inside the lambda you can define test cases. The Solution
functions will only be invoked if the relevant part DSL is used. If you have not yet implemented the second part, or it doesn't exist (e.g.: Every year, part two of the last day just requires collecting all other 49 stars), then you may simply omit it.shouldOutput
function. Each usage will define another test case. The value tested against is checked against its string value, so shouldOutput 4
and shouldOutput "4"
are equivalent.shouldAllOutput
function.If you'd like to help out:
This project is licensed under the MIT License - see the LICENSE for details.
Advent of Code is a registered trademark of Eric K. Wastl in the United States.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4