-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from jwnace/day02-add-tests
added tests for day 2
- Loading branch information
Showing
4 changed files
with
74 additions
and
23 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package day02 | ||
|
||
import java.io.File | ||
|
||
const val RED_CUBES = 12 | ||
const val GREEN_CUBES = 13 | ||
const val BLUE_CUBES = 14 | ||
|
||
val input = File("src/main/kotlin/day02/input.txt").readLines() | ||
|
||
fun solve1() = part1(input) | ||
|
||
fun solve2() = part2(input) | ||
|
||
fun part1(input: List<String>): Int = | ||
input.map { line -> Game.parse(line) } | ||
.filter { it.isPossible } | ||
.sumOf { it.id } | ||
|
||
fun part2(input: List<String>): Int = | ||
input.map { Game.parse(it) } | ||
.sumOf { it.power } |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package day02 | ||
|
||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Test | ||
|
||
class Day02Tests { | ||
@Test | ||
fun `part1 example`() { | ||
// arrange | ||
val input = listOf( | ||
"Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green", | ||
"Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue", | ||
"Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red", | ||
"Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red", | ||
"Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green", | ||
) | ||
|
||
// act | ||
val actual = part1(input) | ||
|
||
// assert | ||
assertEquals(8, actual) | ||
} | ||
|
||
@Test | ||
fun `part1 solution`() { | ||
assertEquals(2348, solve1()) | ||
} | ||
|
||
@Test | ||
fun `part2 example`() { | ||
// arrange | ||
val input = listOf( | ||
"Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green", | ||
"Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue", | ||
"Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red", | ||
"Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red", | ||
"Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green", | ||
) | ||
|
||
// act | ||
val actual = part2(input) | ||
|
||
// assert | ||
assertEquals(2286, actual) | ||
} | ||
|
||
@Test | ||
fun `part2 solution`() { | ||
assertEquals(76008, solve2()) | ||
} | ||
} |