|
| 1 | +package de.ronny_h.aoc.year2015.day08 |
| 2 | + |
| 3 | +import io.kotest.core.spec.style.StringSpec |
| 4 | +import io.kotest.data.forAll |
| 5 | +import io.kotest.data.row |
| 6 | +import io.kotest.matchers.shouldBe |
| 7 | + |
| 8 | +class MatchsticksTest : StringSpec({ |
| 9 | + |
| 10 | + "the number of characters of code" { |
| 11 | + val matchsticks = Matchsticks() |
| 12 | + forAll( |
| 13 | + row("""""""", 2), |
| 14 | + row(""""abc"""", 5), |
| 15 | + row(""""aaa\"aaa"""", 10), |
| 16 | + row(""""\x27"""", 6), |
| 17 | + row(""""\\"""", 4), |
| 18 | + row(""""\\\\"""", 6), |
| 19 | + row(""""\\\\""""", 7), |
| 20 | + ) { string, expected -> |
| 21 | + matchsticks.numberOfCharactersOfCode(string) shouldBe expected |
| 22 | + } |
| 23 | + } |
| 24 | + |
| 25 | + "the number of characters of the in-memory string" { |
| 26 | + val matchsticks = Matchsticks() |
| 27 | + forAll( |
| 28 | + row("""""""", 0), |
| 29 | + row(""""abc"""", 3), |
| 30 | + row(""""aaa\"aaa"""", 7), |
| 31 | + row(""""\x27"""", 1), |
| 32 | + row(""""\\x27"""", 2), |
| 33 | + row(""""\\"""", 1), |
| 34 | + row(""""\\\\"""", 2), |
| 35 | + row(""""\\\\""""", 3), |
| 36 | + row(""""\\\""""", 2), |
| 37 | + row(""""\\""""", 2), |
| 38 | + ) { string, expected -> |
| 39 | + matchsticks.numberOfCharactersInMemory(string) shouldBe expected |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + "unescape ascii characters from hexadecimal escapes" { |
| 44 | + """"\x27"""".unescape() shouldBe """_""" |
| 45 | + """"\xb7"""".unescape() shouldBe """_""" |
| 46 | + } |
| 47 | + |
| 48 | + "part 1: the total number of code chars minus number of in-memory chars" { |
| 49 | + val input = listOf( |
| 50 | + """""""", |
| 51 | + """"abc"""", |
| 52 | + """"aaa\"aaa"""", |
| 53 | + """"\x27"""", |
| 54 | + ) |
| 55 | + Matchsticks().part1(input) shouldBe 12 |
| 56 | + } |
| 57 | + |
| 58 | + "the number of characters of encoded string" { |
| 59 | + val matchsticks = Matchsticks() |
| 60 | + forAll( |
| 61 | + row("""""""", 6), |
| 62 | + row(""""abc"""", 9), |
| 63 | + row(""""aaa\"aaa"""", 16), |
| 64 | + row(""""\x27"""", 11), |
| 65 | + ) { string, expected -> |
| 66 | + matchsticks.numberOfCharactersEncoded(string) shouldBe expected |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + "part 2: the total number of newly encoded chars minus number of code chars" { |
| 71 | + val input = listOf( |
| 72 | + """""""", |
| 73 | + """"abc"""", |
| 74 | + """"aaa\"aaa"""", |
| 75 | + """"\x27"""", |
| 76 | + ) |
| 77 | + Matchsticks().part2(input) shouldBe 19 |
| 78 | + } |
| 79 | +}) |
0 commit comments