Skip to content

Commit e983ec6

Browse files
committed
Simplify the project structure
1 parent 417d4c6 commit e983ec6

File tree

19 files changed

+66
-214
lines changed

19 files changed

+66
-214
lines changed

.github/template-cleanup/README.md

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
![Tests](https://github.com/%REPOSITORY%/workflows/Tests/badge.svg)
2-
31
# %NAME%
42

53
Welcome to the Advent of Code[^aoc] Kotlin project created by [%NAME%][github] using the [Advent of Code Kotlin Template][template] delivered by JetBrains.

.github/template-cleanup/gradle.properties

-3
This file was deleted.

.github/workflows/template-cleanup.yml

-9
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,8 @@ jobs:
3939
sed -i "s/%REPOSITORY%/${GITHUB_REPOSITORY/\//\\/}/g" .github/template-cleanup/*
4040
sed -i "s/%GROUP%/$GROUP/g" .github/template-cleanup/*
4141
42-
# Replace template package name in project files with $GROUP
43-
find src -type f -exec sed -i "s/com.github.kotlinhandson.aoc/$GROUP/g" {} +
44-
find src -type f -exec sed -i "s/Template/$NAME/g" {} +
45-
find src -type f -exec sed -i "s/JetBrains/$ACTOR/g" {} +
46-
4742
# Move content
48-
mkdir -p src/main/kotlin/${GROUP//.//}
49-
mkdir -p src/test/kotlin/${GROUP//.//}
5043
cp -R .github/template-cleanup/* .
51-
mv src/main/kotlin/com/github/kotlinhandson/aoc/* src/main/kotlin/${GROUP//.//}/
52-
mv src/test/kotlin/com/github/kotlinhandson/aoc/* src/test/kotlin/${GROUP//.//}/
5344
5445
# Cleanup
5546
rm -rf \

.github/workflows/tests.yml

-28
This file was deleted.

.run/Run All Days.run.xml

-23
This file was deleted.

README.md

+40-49
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Right after the [@actions-user][actions-user] actor pushes the second commit to
2020
From now, everything's in your hands!
2121
Join the [Advent of Code][aoc] contest, solve the Day O1 as soon as it is published.
2222

23-
For the following days, copy the `Day01.kt` solution file, its `Day01Test.kt` tests, and name it with an incremented day.
23+
For the following days, copy the `Day01.kt` solution file and increment the day number.
2424

2525
> Remember to join the Kotlin contest!
2626
>
@@ -34,75 +34,66 @@ After you create a new project based on the current template repository using th
3434

3535
```
3636
.
37-
├── README.md README file
38-
├── build.gradle.kts Gradle configuration created with Kotlin DSL
37+
├── README.md README file
38+
├── build.gradle.kts Gradle configuration created with Kotlin DSL
3939
├── gradle
40-
│ └── wrapper Gradle Wrapper
41-
├── gradle.properties Gradle configuration properties
42-
├── gradlew *nix Gradle Wrapper script
43-
├── gradlew.bat Windows Gradle Wrapper script
44-
├── settings.gradle.kts Gradle project settings
40+
│ └── wrapper Gradle Wrapper
41+
├── gradle.properties Gradle configuration properties
42+
├── gradlew *nix Gradle Wrapper script
43+
├── gradlew.bat Windows Gradle Wrapper script
44+
├── settings.gradle.kts Gradle project settings
4545
└── src
46-
├── main
47-
│ ├── kotlin
48-
│ │ └── com.github.you.project
49-
│ │ ├── Day.kt Base class for Day* implementations
50-
│ │ ├── Day01.kt An empty implementation for the first AoC day
51-
│ │ └── utils
52-
│ │ ├── Resources.kt Utility class for loading input txt files
53-
│ │ └── utils.kt A set of utility methods shared across your classes
54-
│ └── resources
55-
│ └── day01.txt An empty file for the Day 01 input data
56-
└── test
57-
└── kotlin
58-
└── com.github.you.project
59-
├── DayTest.kt Base test class
60-
└── Day01Test.kt Class to test your implementation against test data
46+
├── Day01.kt An empty implementation for the first AoC day
47+
├── Day01.txt An empty file for the Day 01 input data
48+
├── Day01_test.txt An optional Day 01 test input data used for assertion
49+
└── utils.kt A set of utility methods shared across your days
6150
```
6251

63-
After the first puzzle appears, go to the `Day01.kt` and for each `part1` and `part2` classes, provide an algorithm implementation using the provided `input` data loaded from the `day01.txt` file.
52+
When the first puzzle appears, go to the `Day01.kt` and for each `part1` and `part2` functions, provide an algorithm implementation using the `input` data loaded from the `src/Day01.txt` file.
6453
This input data is common for both parts, and you can find it on the bottom of each day on the [Advent of Code][aoc] page.
6554

66-
To read the input data as a list of strings, you can go with the `String.ints()` utility method provided in the [`utils.kt`][file:utils] file, like:
55+
To read the input data, you can go with the `readInput(name: String)` utility method provided in the [`utils.kt`][file:utils] file, like:
6756

6857
```kotlin
69-
class Day01 : Day(1) {
70-
71-
override fun part1(input: String): Int {
72-
return input.ints().sum()
73-
}
58+
fun part1(input: List<String>): Int {
59+
return input.size
60+
}
7461

75-
// ...
62+
fun main() {
63+
val input = readInput("Day01")
64+
part1(input).also(::println)
7665
}
7766
```
7867

79-
This file also contains the `String.md5()` method for generating MD5 has out of the given string and expects more helper functions for the sake of the [KISS principle][kiss].
80-
81-
To check if everything works as expected during the development, you can use the test data and answers within each day's story and provide them for your `DayTest` test implementation.
82-
You may want to run such a test case by clicking the _Test All Days_ Run/Debug Configuration provided in the top-right toolbar or check the test result for each day separately.
68+
The [`utils.kt`][file:utils] file also contains the `String.md5()` method for generating MD5 has out of the given string and expects more helper functions for the sake of the [KISS principle][kiss].
8369

84-
To go with the next day, place the `day02.txt` file into the `resources` with relevant input data, create `Day02.kt` file with the class implementation:
70+
Each puzzle describes some test conditions, a small portion of the information that helps check if the produced value for the given test input is valid.
71+
To handle that case, you can put such an input into a separated file and perform a standard assertion against the output, like:
8572

8673
```kotlin
87-
class Day02 : Day(2) {
88-
// ...
74+
fun main() {
75+
val testInput = readInput("Day01_test")
76+
assert(part1(testInput) == 13)
8977
}
9078
```
9179

92-
Then just provide tests for the second day in a similar manner:
80+
The final result of your algorithm will be printed on the screen so that you can pass it to the Advent of Code website.
81+
82+
To go with the next day, place the `Day02.txt` file into the `src` with relevant input data and create `Day02.kt` file with a similar code scaffold:
9383

9484
```kotlin
95-
class Day02Test : DayTest() {
96-
97-
override val day = Day02()
85+
fun part1(input: List<String>): Int {
86+
return 0
87+
}
9888

99-
@Test
100-
override fun `Part 1`() {
101-
assertEquals(0, day.part1("test_input")) // check against test input
102-
assertEquals(0, day.part1()) // check solution against input data
103-
}
89+
fun part2(input: List<String>): Int {
90+
return 0
91+
}
10492

105-
// ...
93+
fun main() {
94+
val input = readInput("Day02")
95+
part1(input).also(::println)
96+
part2(input).also(::println)
10697
}
10798
```
10899

@@ -123,4 +114,4 @@ If you stuck with Kotlin-specific questions or anything related to this template
123114
[kotlin]: https://kotlinlang.org
124115
[slack]: https://surveys.jetbrains.com/s3/kotlin-slack-sign-up
125116
[file:kotlin]: .github/readme/kotlin.svg
126-
[file:utils]: src/main/kotlin/com/github/kotlinhandson/aoc/utils/utils.kt
117+
[file:utils]: src/utils.kt

build.gradle.kts

+5-10
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,18 @@ plugins {
22
kotlin("jvm") version "1.6.0"
33
}
44

5-
group = project.property("group").toString()
6-
version = project.property("version").toString()
7-
8-
dependencies {
9-
testImplementation(kotlin("test"))
10-
}
11-
125
repositories {
136
mavenCentral()
147
}
158

169
tasks {
17-
withType<Test> {
18-
useJUnitPlatform()
10+
sourceSets {
11+
main {
12+
java.srcDirs("src")
13+
}
1914
}
2015

2116
wrapper {
22-
gradleVersion = project.findProperty("gradleVersion").toString()
17+
gradleVersion = "7.3"
2318
}
2419
}

gradle.properties

-3
This file was deleted.

gradle/wrapper/gradle-wrapper.jar

-58.1 KB
Binary file not shown.

gradle/wrapper/gradle-wrapper.properties

-5
This file was deleted.

src/Day01.kt

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
fun part1(input: List<String>): Int {
2+
return input.size
3+
}
4+
5+
fun part2(input: List<String>): Int {
6+
return input.size
7+
}
8+
9+
fun main() {
10+
// test if implementation meets criteria from the description, like:
11+
val testInput = readInput("Day01_test")
12+
assert(part1(testInput) == 1)
13+
14+
val input = readInput("Day01")
15+
part1(input).also(::println)
16+
part2(input).also(::println)
17+
}
File renamed without changes.

src/Day01_test.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0

src/main/kotlin/com/github/kotlinhandson/aoc/Day.kt

-16
This file was deleted.

src/main/kotlin/com/github/kotlinhandson/aoc/Day01.kt

-12
This file was deleted.

src/main/kotlin/com/github/kotlinhandson/aoc/utils/Resources.kt

-6
This file was deleted.

src/test/kotlin/com/github/kotlinhandson/aoc/Day01Test.kt

-21
This file was deleted.

src/test/kotlin/com/github/kotlinhandson/aoc/DayTest.kt

-23
This file was deleted.
+3-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
package com.github.kotlinhandson.aoc.utils
2-
1+
import java.io.File
32
import java.math.BigInteger
43
import java.security.MessageDigest
54

65
/**
7-
* Maps a string containing integers in new lines to a list of integers.
6+
* Reads lines from the given input txt file.
87
*/
9-
fun String.ints() = lines().map(String::toInt)
8+
fun readInput(name: String) = File("src", "$name.txt").readLines()
109

1110
/**
1211
* Converts string to md5 hash.

0 commit comments

Comments
 (0)