Skip to content

Commit a57b9dd

Browse files
committed
Add tests.
1 parent d5200ac commit a57b9dd

File tree

5 files changed

+107
-5
lines changed

5 files changed

+107
-5
lines changed

aockt-test/src/main/kotlin/internal/AdventConfig.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ internal data class AdventProjectConfig(
2727
}
2828
}
2929

30-
companion object Key : CoroutineContext.Key<AdventProjectConfig>{
30+
companion object Key : CoroutineContext.Key<AdventProjectConfig> {
3131
/** Sane defaults. */
3232
val Default: AdventProjectConfig = AdventProjectConfig(
3333
efficiencyBenchmark = 15.seconds,
@@ -72,7 +72,7 @@ internal data class AdventDebugConfig(
7272

7373
internal fun AdventTestConfig.forExamples(defaults: AdventProjectConfig): AdventTestConfig.ForExamples =
7474
AdventTestConfig.ForExamples(
75-
enabled = (executionMode ?: defaults.executionMode) != ExecMode.SkipExamples,
75+
enabled = if (!enabled) false else (executionMode ?: defaults.executionMode) != ExecMode.SkipExamples,
7676
partFunction = partFunction,
7777
examples = examples,
7878
)
@@ -81,7 +81,7 @@ internal fun AdventTestConfig.forInput(defaults: AdventProjectConfig): AdventTes
8181
AdventTestConfig.ForInput(
8282
id = id,
8383
part = part,
84-
enabled = (executionMode ?: defaults.executionMode) != ExecMode.ExamplesOnly,
84+
enabled = if (!enabled) false else (executionMode ?: defaults.executionMode) != ExecMode.ExamplesOnly,
8585
partFunction = partFunction,
8686
expensive = expensive,
8787
efficiencyBenchmark = efficiencyBenchmark ?: defaults.efficiencyBenchmark

aockt-test/src/main/kotlin/internal/AdventDebugScopeImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ internal class AdventDebugScopeImpl(
99
) : AdventDebugScope {
1010

1111
override val input: String
12-
get() = puzzleInput?.toString()?: throw MissingInputException()
12+
get() = (puzzleInput ?: throw MissingInputException()).toString()
1313
}

aockt-test/src/test/kotlin/integration/DebugMode.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package io.github.jadarma.aockt.test.integration
22

33
import io.github.jadarma.aockt.test.AdventDay
44
import io.github.jadarma.aockt.test.AdventSpec
5+
import io.github.jadarma.aockt.test.internal.MissingInputException
6+
import io.kotest.assertions.throwables.shouldThrowExactly
57
import io.kotest.core.test.TestCase
68
import io.kotest.engine.test.TestResult
79
import io.kotest.matchers.booleans.shouldBeFalse
@@ -10,7 +12,7 @@ import io.kotest.matchers.shouldBe
1012

1113
private var didExecute = false
1214

13-
@AdventDay(3000, 6, "DebugMode")
15+
@AdventDay(9999, 2, "DebugMode")
1416
class DebugMode : AdventSpec<ObjectSolution>({
1517

1618
partOne {
@@ -19,6 +21,7 @@ class DebugMode : AdventSpec<ObjectSolution>({
1921

2022
debug {
2123
didExecute = true
24+
input shouldBe "ABC"
2225
}
2326
}) {
2427

@@ -38,3 +41,11 @@ class DebugMode : AdventSpec<ObjectSolution>({
3841
}
3942
}
4043
}
44+
45+
@AdventDay(3000, 6, "DebugMode", variant = "With missing input")
46+
class DebugMode2 : AdventSpec<ObjectSolution>({
47+
48+
debug {
49+
shouldThrowExactly<MissingInputException>{ input }
50+
}
51+
})

aockt-test/src/test/kotlin/internal/DslTest.kt

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,61 @@ class DslTest : FunSpec({
102102
}
103103
}
104104
}
105+
106+
context("Configurations compute final test configs") {
107+
val configA = AdventTestConfig(
108+
id = AdventDayID(9999, 2),
109+
part = AdventDayPart.One,
110+
partFunction = ObjectSolution.partFunction(AdventDayPart.One),
111+
enabled = true,
112+
expensive = true,
113+
executionMode = ExecMode.SkipExamples,
114+
efficiencyBenchmark = 10.seconds,
115+
examples = listOf(PuzzleInput("B") to PuzzleAnswer("1:B"))
116+
)
117+
val configB = AdventTestConfig(
118+
id = AdventDayID(9999, 2),
119+
part = AdventDayPart.Two,
120+
partFunction = ObjectSolution.partFunction(AdventDayPart.Two),
121+
enabled = false,
122+
expensive = false,
123+
executionMode = null,
124+
efficiencyBenchmark = null,
125+
examples = emptyList(),
126+
)
127+
128+
test("for examples") {
129+
configA.forExamples(AdventProjectConfig.Default).should { finalConfig ->
130+
finalConfig.enabled shouldBe false
131+
finalConfig.examples shouldBe configA.examples
132+
finalConfig.partFunction.invoke(PuzzleInput("B")) shouldBe PuzzleAnswer("1:B")
133+
}
134+
configB.forExamples(AdventProjectConfig.Default).should { finalConfig ->
135+
finalConfig.enabled shouldBe false
136+
finalConfig.examples shouldBe emptyList()
137+
finalConfig.partFunction.invoke(PuzzleInput("B")) shouldBe PuzzleAnswer("2:1")
138+
}
139+
}
140+
141+
test("for input") {
142+
configA.forInput(AdventProjectConfig.Default).should { finalConfig ->
143+
finalConfig.id shouldBe configA.id
144+
finalConfig.part shouldBe configA.part
145+
finalConfig.enabled shouldBe true
146+
finalConfig.partFunction.invoke(PuzzleInput("B")) shouldBe PuzzleAnswer("1:B")
147+
finalConfig.expensive shouldBe true
148+
finalConfig.efficiencyBenchmark shouldBe configA.efficiencyBenchmark
149+
}
150+
configB.forInput(AdventProjectConfig.Default).should { finalConfig ->
151+
finalConfig.id shouldBe configB.id
152+
finalConfig.part shouldBe configB.part
153+
finalConfig.enabled shouldBe false
154+
finalConfig.partFunction.invoke(PuzzleInput("B")) shouldBe PuzzleAnswer("2:1")
155+
finalConfig.expensive shouldBe false
156+
finalConfig.efficiencyBenchmark shouldBe AdventProjectConfig.Default.efficiencyBenchmark
157+
}
158+
}
159+
}
105160
})
106161

107162
@AdventDay(3000, 3)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package io.github.jadarma.aockt.test.internal
2+
3+
import io.kotest.assertions.throwables.shouldThrow
4+
import io.kotest.core.spec.style.FunSpec
5+
import io.kotest.matchers.shouldBe
6+
7+
class PuzzleTestDataTest : FunSpec({
8+
9+
context("Puzzle inputs") {
10+
11+
test("cannot be empty") {
12+
shouldThrow<IllegalArgumentException> { PuzzleInput("") }
13+
}
14+
15+
test("are inlined") {
16+
PuzzleInput("aaa").toString() shouldBe "aaa"
17+
}
18+
19+
@Suppress("StringShouldBeRawString")
20+
test("can be previewed") {
21+
val singleLine = PuzzleInput("A")
22+
val multiLine = PuzzleInput("B\n1\n2\nB")
23+
val manyLines = PuzzleInput("C\n1\n2\n3\n4\n5\n6\nC")
24+
25+
singleLine.preview() shouldBe "A"
26+
multiLine.preview() shouldBe "\nB\n1\n2\nB\n"
27+
manyLines.preview() shouldBe "\nC\n1\n2\n...\nC\n"
28+
}
29+
}
30+
31+
context("Puzzle answers") {
32+
test("are inlined") {
33+
PuzzleAnswer("answer").toString() shouldBe "answer"
34+
}
35+
}
36+
})

0 commit comments

Comments
 (0)