My solutions for the Advent of Code - 2022
Create each Day's solutions in a structure like this under src/test/kotlin:
./day01 +
|
+- CalorieCounterTest.kt
+- input.txt
+- test-input.txt
+- README.md
./day02 +
|
+- Day02Test.kt
+- input.txt
+- test-input.txt
+- README.md
./dayNN +
|
+- TodayTest.kt
+- input.txt
+- test-input.txt
+- README.md
Assuming each day's solutions follow the above directory structure and naming conventions, you will be able to run each solution with a command like:
./gradlew run test --tests="day01**"
If the tests are named appropriately, you can also use a command like this to just run a specific test:
./gradlew run test --tests="day01**Part 1**Sample**"
This would run just the Part One solution for the Sample input (test-input.txt).
For each new Day, you can simply copy the "template" dayNN package, and rename/implement as appropriate, or follow these destructions...
- Create a dayNN directory
- In the dayNN directory, create a SomethingTest.kt for the tests for the challenges. Naming the tests appropriately will allow the above gradle commands to work as described.
package dayNN
import Helpers
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
@DisplayName("Day N - Description")
class TodayTest : Helpers() {
@Test
fun `Day 1 Part 1 Sample Input should return 42`() {
assertEquals(42, Solver(loadSampleInput()).solvePartOne())
}
@Test
fun `Day 1 Part 2 Sample Input should return 90210`() {
assertEquals(90210, Solver(loadSampleInput()).solvePartTwo())
}
@Test
fun `Day 1 Part 1 Real Input should return 42`() {
assertEquals(42, Solver(loadInput()).solvePartOne())
}
@Test
fun `Day 1 Part 2 Real Input should return 90210`() {
assertEquals(90210, Solver(loadInput()).solvePartTwo())
}
}
class Solver(data: List<String>) {
fun solvePartOne(): Int {
return 42
}
fun solvePartTwo(): Int {
return 90210
}
}
- In the dayNN directory, create an input.txt file with the input for the challenge; optionally create a test-input.txt with the sample input, for easier testing
- Copy the source of the final HTML page after solving both challenges, and paste into CodeBeautify to get a markdown version of the page
- Add a README each day, with the markdown from CodeBeautify
- Commit the day's solution, only after the day is over.
- The .gitignore should keep the input.txt from being committed, but please be sure to not commit this, per the author's request