|
| 1 | +package de.ronny_h.aoc.year2018.day04 |
| 2 | + |
| 3 | +import de.ronny_h.aoc.extensions.asList |
| 4 | +import de.ronny_h.aoc.year2018.day04.GuardEvent.* |
| 5 | +import io.kotest.core.spec.style.StringSpec |
| 6 | +import io.kotest.matchers.shouldBe |
| 7 | + |
| 8 | +class ReposeRecordTest : StringSpec({ |
| 9 | + |
| 10 | + val input = """ |
| 11 | + [1518-11-01 00:00] Guard #10 begins shift |
| 12 | + [1518-11-01 00:05] falls asleep |
| 13 | + [1518-11-01 00:25] wakes up |
| 14 | + [1518-11-01 00:30] falls asleep |
| 15 | + [1518-11-01 00:55] wakes up |
| 16 | + [1518-11-01 23:58] Guard #99 begins shift |
| 17 | + [1518-11-02 00:40] falls asleep |
| 18 | + [1518-11-02 00:50] wakes up |
| 19 | + [1518-11-03 00:05] Guard #10 begins shift |
| 20 | + [1518-11-03 00:24] falls asleep |
| 21 | + [1518-11-03 00:29] wakes up |
| 22 | + [1518-11-04 00:02] Guard #99 begins shift |
| 23 | + [1518-11-04 00:36] falls asleep |
| 24 | + [1518-11-04 00:46] wakes up |
| 25 | + [1518-11-05 00:03] Guard #99 begins shift |
| 26 | + [1518-11-05 00:45] falls asleep |
| 27 | + [1518-11-05 00:55] wakes up |
| 28 | + """.asList() |
| 29 | + |
| 30 | + "input can be parsed" { |
| 31 | + input.parseRecords() shouldBe listOf( |
| 32 | + GuardDutyRecord("1518-11-01 00:00", 10, BEGIN_SHIFT), |
| 33 | + GuardDutyRecord("1518-11-01 00:05", 10, FALL_ASLEEP), |
| 34 | + GuardDutyRecord("1518-11-01 00:25", 10, WAKE_UP), |
| 35 | + GuardDutyRecord("1518-11-01 00:30", 10, FALL_ASLEEP), |
| 36 | + GuardDutyRecord("1518-11-01 00:55", 10, WAKE_UP), |
| 37 | + GuardDutyRecord("1518-11-01 23:58", 99, BEGIN_SHIFT), |
| 38 | + GuardDutyRecord("1518-11-02 00:40", 99, FALL_ASLEEP), |
| 39 | + GuardDutyRecord("1518-11-02 00:50", 99, WAKE_UP), |
| 40 | + GuardDutyRecord("1518-11-03 00:05", 10, BEGIN_SHIFT), |
| 41 | + GuardDutyRecord("1518-11-03 00:24", 10, FALL_ASLEEP), |
| 42 | + GuardDutyRecord("1518-11-03 00:29", 10, WAKE_UP), |
| 43 | + GuardDutyRecord("1518-11-04 00:02", 99, BEGIN_SHIFT), |
| 44 | + GuardDutyRecord("1518-11-04 00:36", 99, FALL_ASLEEP), |
| 45 | + GuardDutyRecord("1518-11-04 00:46", 99, WAKE_UP), |
| 46 | + GuardDutyRecord("1518-11-05 00:03", 99, BEGIN_SHIFT), |
| 47 | + GuardDutyRecord("1518-11-05 00:45", 99, FALL_ASLEEP), |
| 48 | + GuardDutyRecord("1518-11-05 00:55", 99, WAKE_UP), |
| 49 | + ) |
| 50 | + } |
| 51 | + |
| 52 | + "input gets sorted by timestamp" { |
| 53 | + """ |
| 54 | + [1518-11-01 00:25] wakes up |
| 55 | + [1518-11-01 00:05] falls asleep |
| 56 | + [1518-11-01 00:00] Guard #10 begins shift |
| 57 | + [1518-11-01 00:30] falls asleep |
| 58 | + """.asList() |
| 59 | + .parseRecords() shouldBe listOf( |
| 60 | + GuardDutyRecord("1518-11-01 00:00", 10, BEGIN_SHIFT), |
| 61 | + GuardDutyRecord("1518-11-01 00:05", 10, FALL_ASLEEP), |
| 62 | + GuardDutyRecord("1518-11-01 00:25", 10, WAKE_UP), |
| 63 | + GuardDutyRecord("1518-11-01 00:30", 10, FALL_ASLEEP), |
| 64 | + ) |
| 65 | + } |
| 66 | + |
| 67 | + "part 1: the guard's id who slept most, multiplied by the minute he slept most" { |
| 68 | + ReposeRecord().part1(input) shouldBe 240 |
| 69 | + } |
| 70 | + |
| 71 | + "part 2: the guard's id who sleeps most frequently in the same minute, multiplied by that minute" { |
| 72 | + ReposeRecord().part2(input) shouldBe 4455 |
| 73 | + } |
| 74 | +}) |
0 commit comments