Skip to content

Commit e510ff1

Browse files
committed
add tests
1 parent b36725b commit e510ff1

File tree

6 files changed

+84
-15
lines changed

6 files changed

+84
-15
lines changed

build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ repositories {
1414

1515
dependencies {
1616
testImplementation(kotlin("test"))
17+
testImplementation("org.junit.jupiter:junit-jupiter:5.8.1")
1718
}
1819

1920
tasks.test {

src/main/kotlin/days/day2.kt

+11-15
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,18 @@ fun String.parseResult() = when (this) {
4848
else -> throw IllegalArgumentException(this)
4949
}
5050

51-
fun neededFor(result: Result, option: Option) = when(result) {
52-
Lose -> option.strongAgainst()
51+
fun neededFor(result: Result, option: Option) = when (result) {
52+
Lose -> when (option) {
53+
Rock -> Scissors
54+
Paper -> Rock
55+
Scissors -> Paper
56+
}
5357
Draw -> option
54-
Win -> option.weakAgainst()
55-
}
56-
57-
fun Option.weakAgainst() = when(this) {
58-
Rock -> Paper
59-
Paper -> Scissors
60-
Scissors -> Rock
61-
}
62-
63-
fun Option.strongAgainst() = when(this) {
64-
Rock -> Scissors
65-
Paper -> Rock
66-
Scissors -> Paper
58+
Win -> when (option) {
59+
Rock -> Paper
60+
Paper -> Scissors
61+
Scissors -> Rock
62+
}
6763
}
6864

6965
fun day2part2() = Files.lines(Paths.get("input/2.txt")).asSequence()

src/test/kotlin/days/Day1Test.kt

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package days
2+
3+
import org.junit.jupiter.api.Test
4+
5+
import org.junit.jupiter.api.Assertions.*
6+
7+
internal class Day1Test {
8+
9+
@Test
10+
fun day1part1Test() {
11+
assertEquals(71300, day1part1())
12+
}
13+
14+
@Test
15+
fun day1part2Test() {
16+
assertEquals(209691, day1part2())
17+
}
18+
}

src/test/kotlin/days/Day2Test.kt

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package days
2+
3+
import org.junit.jupiter.api.Test
4+
5+
import org.junit.jupiter.api.Assertions.*
6+
7+
internal class Day2Test {
8+
9+
@Test
10+
fun day2Part1Test() {
11+
assertEquals(14827, day2Part1())
12+
}
13+
14+
@Test
15+
fun day2part2Test() {
16+
assertEquals(13889, day2part2())
17+
}
18+
}

src/test/kotlin/days/Day3Test.kt

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package days
2+
3+
import org.junit.jupiter.api.Test
4+
5+
import org.junit.jupiter.api.Assertions.*
6+
7+
internal class Day3Test {
8+
9+
@Test
10+
fun day3part1Test() {
11+
assertEquals(8233, day3part1())
12+
}
13+
14+
@Test
15+
fun day3part2Test() {
16+
assertEquals(2821, day3part2())
17+
}
18+
}

src/test/kotlin/days/Day4Test.kt

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package days
2+
3+
import org.junit.jupiter.api.Test
4+
5+
import org.junit.jupiter.api.Assertions.*
6+
7+
internal class Day4Test {
8+
9+
@Test
10+
fun day4part1Test() {
11+
assertEquals(487, day4part1())
12+
}
13+
14+
@Test
15+
fun day4part2Test() {
16+
assertEquals(849, day4part2())
17+
}
18+
}

0 commit comments

Comments
 (0)