@@ -12,52 +12,69 @@ AocKt _(short for Advent of Code - Kotlin)_ is a simple library that makes runni
12
12
It is an opinionated testing framework built on [ Kotest] ( https://kotest.io/ ) that defines a new ` AdventSpec ` specialized
13
13
for testing AoC puzzle solutions with minimal boilerplate.
14
14
15
+ ## 📑 Documentation
16
+
17
+ Visit the [ project website] ( https://jadarma.github.io/advent-of-code-kotlin ) for installation instructions,
18
+ DSL documentation, workflow guides, advanced configuration options, and more!
19
+
15
20
## ✨ Features
16
21
17
- - * Completely Offline* - Puzzle inputs and solutions are read from local files, no need for tokens.
18
- - * Test Driven* - Run your code from unit tests for faster feedback loops and fearless refactorings.
19
- - * DSL Driven* - Define your test cases with minimal code.
20
- - * Configurable* - You decide what runs and when using optional parameters.
21
- - * Minimal* - The test framework is the only non-Kotlin dependency.
22
+ - ** Completely Offline* * - Puzzle inputs and solutions are read from local files, no need for tokens.
23
+ - ** Test- Driven* * - Run your code from unit tests for faster feedback loops and fearless refactorings.
24
+ - ** DSL- Driven* * - Define your test cases with minimal code.
25
+ - ** Configurable* * - You decide what runs and when using optional parameters.
26
+ - ** Minimal* * - The test framework is the only non-Kotlin dependency.
22
27
23
28
## ⚡ Quick Start
24
29
25
- ### Gradle
30
+ <details open >
31
+ <summary>Project Template</summary>
26
32
27
- To use AocKt, simply add the dependencies and configure your project to run unit tests with Kotest:
33
+ For your convenience, there is an
34
+ [ advent-of-code-kotlin-template] ( https://github.com/Jadarma/advent-of-code-kotlin-template ) repository which you can
35
+ use to generate your own solutions repo.
36
+ It comes with a pre-configured Gradle project with all bells and whistles you might need, as well as a
37
+ modified source structure for easier navigation.
38
+
39
+ _ (If you need a working example, check out [ my solutions repo] ( https://github.com/Jadarma/advent-of-code-kotlin-solutions ) .)_
40
+
41
+ </details >
42
+
43
+ <details >
44
+ <summary>Standalone Gradle Project</summary>
45
+
46
+ To add AocKt to your existing project, simply add the dependencies and configure your unit tests to run with Kotest:
28
47
29
48
``` kotlin
49
+ plugins {
50
+ kotlin(" jvm" ) version " $kotlinVersion "
51
+ }
52
+
30
53
repositories {
31
54
mavenCentral()
32
55
}
33
56
34
57
dependencies {
35
58
implementation(" io.github.jadarma.aockt:aockt-core:$aocktVersion " )
36
59
testImplementation(" io.github.jadarma.aockt:aockt-test:$aocktVersion " )
37
- testImplementation(" io.kotest:kotest-runner-junit5:5.9.1 " )
60
+ testImplementation(" io.kotest:kotest-runner-junit5:$kotestVersion " )
38
61
}
39
62
40
63
tasks.test {
41
64
useJUnitPlatform()
42
65
}
43
66
```
67
+ </details >
44
68
45
- ### Project Template
46
-
47
- For your convenience, there is an
48
- [ advent-of-code-kotlin-template] ( https://github.com/Jadarma/advent-of-code-kotlin-template ) repository which you can
49
- use to generate your own solutions repo, featuring a pre-configured Gradle project, modified source directory locations
50
- for easier navigation, and a detailed README with workflow examples.
51
- If you need a working example, you can check out
52
- [ my solutions repo] ( https://github.com/Jadarma/advent-of-code-kotlin-solutions ) as well.
53
-
54
- ## 📄 Usage Guide
69
+ ## 🧪 Test DSL Overview
55
70
56
- <details open >
57
- <summary >Basic Test Definition</summary >
71
+ AocKt provides the following DSL for testing puzzle solutions:
58
72
59
73
``` kotlin
60
- object Y9999D01 : Solution { /* ... */ } // 1.
74
+ object Y9999D01 : Solution { // 1.
75
+ override fun partOne (input : String ) = spoilers()
76
+ override fun partTwo (input : String ) = spoilers()
77
+ }
61
78
62
79
@AdventDay(9999 , 1 , " Magic Numbers" ) // 2.
63
80
class Y9999D01Test : AdventSpec <Y9999D01 >({ // 3.
@@ -73,7 +90,7 @@ In the above example:
73
90
74
91
1 . Your solution should implement the ` Solution ` interface.
75
92
2 . Each test class should be annotated with the ` @AdventDay ` annotation. Title is optional, but the year and day are
76
- required, so the spec knows what user input to test with .
93
+ required.
77
94
3 . Rather than passing it as an instance, the ` AdventSpec ` takes in your solution as a type parameter.
78
95
4 . Use the ` partOne ` and ` partTwo ` functions as needed.
79
96
Inside the lambda you can define test cases.
@@ -88,139 +105,6 @@ In the above example:
88
105
6 . As a shorthand for defining multiple examples that should output the same thing, use the ` shouldAllOutput ` function.
89
106
7 . If you don't have any examples, but do want to run the part against your input the lambda can be omitted.
90
107
91
- </details >
92
-
93
- <details >
94
- <summary>Project Configuration</summary>
95
-
96
- AocKt provides an extension you may register in your Kotest project to tweak the behaviour of the ` AdventSpec ` .
97
- Registering it is optional but recommended, and can be done like any other extension:
98
-
99
- ``` kotlin
100
- object TestConfig : AbstractProjectConfig() {
101
-
102
- override fun extensions () = listOf<Extension >(
103
- AocKtExtension (),
104
- )
105
- }
106
- ```
107
-
108
- The following optional parameters exist:
109
-
110
- - * formatAdventSpecNames* - When the extension is registered, ` AdventSpec ` classes have a pretty formatted name in the
111
- test runner. Set this to ` false ` to opt out of this behavior.
112
- - * efficiencyBenchmark* - If a solution completes under this time value, it will pass its efficiency test.
113
- Lower this value to increase the challenge or increase it to adjust for your hardware * (the latter shouldn't be
114
- necessary)* .
115
- Can be overridden for individual parts, see * Execution Configuration for Parts* for more details.
116
- Default is fifteen seconds.
117
- - * executionMode* - Choose the default execution mode for the entire project (run only examples, only user input, or
118
- all of them).
119
- If set to ` ExamplesOnly ` , does not run against the true puzzle input even if present.
120
- Useful when running the project with encrypted inputs (e.g. running a clone of someone else's solution repo).
121
- If set to ` SkipExamples ` , will only test against user input.
122
- Can be overridden for individual parts, see * Execution Configuration for Parts* for more details.
123
- Default is all.
124
-
125
- </details >
126
-
127
- <details >
128
- <summary>Testing Against User Input</summary>
129
-
130
- By default, only the example defined in the DSL will run.
131
- However, the solution can be tested against real user input if it is detected.
132
- AocKt looks inside the test resources directory for them.
133
- The structure is fixed and must match the following:
134
-
135
- ``` text
136
- testResourcesDir
137
- └── aockt
138
- └── y{year}
139
- └── d{two-digit-day}
140
- └── input.txt
141
- └── solution_part1.txt
142
- └── solution_part2.txt
143
- ```
144
-
145
- If the ` input.txt ` file exists, the ` Solution ` will be ran against it after the example tests.
146
- It is normal that at first the solutions are unknown, and therefore missing.
147
- The unverified solution will be added in parens at the end of the test name, which you can then submit to the website.
148
-
149
- If the ` solution_part1 ` or ` solution_part2.txt ` exist, then the value contained within them is assumed to be the correct
150
- output when running against ` input.txt ` , and will be validated.
151
-
152
- ** IMPORTANT!:** The reason for keeping the user inputs separate from the tests (apart from readability) is that
153
- [ puzzle inputs should not be redistributed] ( https://old.reddit.com/r/adventofcode/wiki/faqs/copyright/inputs ) .
154
- If you plan on sharing your solutions repository publicly, either ` .gitignore ` the ` src/test/resources/aockt ` directory
155
- or commit them as encrypted blobs only you can read!
156
-
157
- </details >
158
-
159
- <details >
160
- <summary>Execution configuration for Parts</summary>
161
-
162
- The ` partOne ` and ` partTwo ` scopes can be configured with optional parameters.
163
- These allow you to modify the way the generated tests behave.
164
- They are mostly meant to help during development, and reverted once your solutions are complete.
165
-
166
- The following optional parameters exist:
167
-
168
- - * enabled* - True by default. When set to false, all tests for this part are ignored.
169
- Useful for when working on the second part of a puzzle and want to skip re-checking the first when
170
- running the spec.
171
-
172
- - * expensive* - False by default. Lowers the time restrictions for execution.
173
- While most puzzles should be solvable in under 15 seconds, sometimes it's hard to come up with an optimised solution
174
- on the first try.
175
- This option tags the tests as slow if you want to exclude them from bulk execution.
176
-
177
- - * executionMode* - Defaults to project configuration.
178
- If set to ` ExamplesOnly ` , does not run against the true puzzle input even if present.
179
- Useful when refactoring an expensive day and no not wish to waste time on the big test while the small ones do fail.
180
- If set to ` SkipExamples ` , does not run against the example test cases even if present.
181
- Useful for isolating a single execution of the solution, useful when debugging.
182
-
183
- - * efficiencyBenchmark* - Defaults to project configuration.
184
- The maximum runtime a solution can have while being considered efficient by the time tests.
185
- Only the user input tests are measured.
186
-
187
- </details >
188
-
189
- <details >
190
- <summary>Multiple Solutions for the Same Puzzle</summary>
191
-
192
- The ` AdventSpec ` is designed to test a single ` Solution ` at a time.
193
- However, that doesn't mean you need to duplicate the code if you want to show off multiple approaches to the solution!
194
- You can instead define an abstract specification for your test cases, and use it to derive an arbitrary number of
195
- specific implementation test classes, and supply the ` variant ` parameter to the ` AdventDay ` annotation to disambiguate
196
- between the two.
197
-
198
- ``` kotlin
199
- object SolutionA : Solution { /* ... */ }
200
- object SolutionB : Solution { /* ... */ }
201
-
202
- @AdventDay(9999 , 1 , " Magic Numbers" , " Variant A" )
203
- class SolutionATest : Y9999D01Spec <SolutionA >()
204
-
205
- @AdventDay(9999 , 1 , " Magic Numbers" , " Variant B" )
206
- class SolutionBTest : Y9999D01Spec <SolutionB >()
207
-
208
- abstract class Y9999D01Spec <T : Solution > : AdventSpec <T >({
209
- val exampleInput = " 1,2,3,4"
210
- partOne { exampleInput shouldOutput 4 }
211
- partTwo { exampleInput shouldOutput 24 }
212
- })
213
- ```
214
-
215
- </details >
216
-
217
- <details >
218
- <summary>Workflow Example</summary>
219
-
220
- For a complete workflow example, check out the
221
- [ project template] ( https://github.com/Jadarma/advent-of-code-kotlin-template#-workflow-example ) .
222
- </details >
223
-
224
108
## 👥 Contributing
225
109
226
110
If you'd like to help out:
@@ -231,4 +115,4 @@ If you'd like to help out:
231
115
## ⚖ License
232
116
233
117
This project is licensed under the MIT License - see the [ LICENSE] ( LICENSE.md ) for details.\
234
- _ Advent of Code_ is a registered trademark of Eric K Wastl in the United States.
118
+ _ Advent of Code_ is a registered trademark of Eric K. Wastl in the United States.
0 commit comments