|
| 1 | +package de.ronny_h.aoc.year2015.day12 |
| 2 | + |
| 3 | +import io.kotest.core.spec.style.StringSpec |
| 4 | +import io.kotest.matchers.shouldBe |
| 5 | + |
| 6 | +class JSAbacusFrameworkTest : StringSpec({ |
| 7 | + |
| 8 | + val day12 = JSAbacusFramework() |
| 9 | + |
| 10 | + "part 1: a sum of 6" { |
| 11 | + day12.part1(listOf("[1,2,3]")) shouldBe 6 |
| 12 | + day12.part1(listOf("{\"a\":2,\"b\":4}")) shouldBe 6 |
| 13 | + } |
| 14 | + |
| 15 | + "part 1: a sum of 3" { |
| 16 | + day12.part1(listOf("[[[3]]]")) shouldBe 3 |
| 17 | + day12.part1(listOf("{\"a\":{\"b\":4},\"c\":-1}")) shouldBe 3 |
| 18 | + } |
| 19 | + |
| 20 | + "part 1: a sum of 0" { |
| 21 | + day12.part1(listOf("{\"a\":[-1,1]}")) shouldBe 0 |
| 22 | + day12.part1(listOf("[-1,{\"a\":1}]")) shouldBe 0 |
| 23 | + day12.part1(listOf("[]")) shouldBe 0 |
| 24 | + day12.part1(listOf("{}")) shouldBe 0 |
| 25 | + } |
| 26 | + |
| 27 | + "readNonRedObject of simple array" { |
| 28 | + "[1,2,3]".filterOutRedObjects() shouldBe Pair("[1,2,3]", 7) |
| 29 | + } |
| 30 | + |
| 31 | + "readNonRedObject of simple object" { |
| 32 | + """{"a":1}""".filterOutRedObjects() shouldBe Pair("""{"a":1}""", 7) |
| 33 | + } |
| 34 | + |
| 35 | + "readNonRedObject of simple object containing value red" { |
| 36 | + """{"a":"red"}""".filterOutRedObjects() shouldBe Pair("{}", 11) |
| 37 | + } |
| 38 | + |
| 39 | + "readNonRedObject of nested object" { |
| 40 | + """{"a":{"b":"c"}}""".filterOutRedObjects() shouldBe Pair("""{"a":{"b":"c"}}""", 15) |
| 41 | + } |
| 42 | + |
| 43 | + "readNonRedObject of nested object containing value red" { |
| 44 | + """{"a":{"b":"red"}}""".filterOutRedObjects() shouldBe Pair("""{"a":{}}""", 17) |
| 45 | + } |
| 46 | + |
| 47 | + "readNonRedObject with two red objects on nested level" { |
| 48 | + """{"a":{"b":"red"},"c":{"d":"red"}}""".filterOutRedObjects() shouldBe Pair("""{"a":{},"c":{}}""", 33) |
| 49 | + } |
| 50 | + |
| 51 | + "readNonRedObject of double-nested object" { |
| 52 | + """{"a":{"b":{"c":"d"}},"e":1}""".filterOutRedObjects() shouldBe Pair( |
| 53 | + """{"a":{"b":{"c":"d"}},"e":1}""", |
| 54 | + 27 |
| 55 | + ) |
| 56 | + } |
| 57 | + |
| 58 | + "readNonRedObject of double-nested object containing red" { |
| 59 | + """{"a":{"b":{"c":"red"},"d":1}}""".filterOutRedObjects() shouldBe Pair("""{"a":{"b":{},"d":1}}""", 29) |
| 60 | + } |
| 61 | + |
| 62 | + "readNonRedObject of double-nested object containing red on mid-level" { |
| 63 | + """{"a":{"b":"red","c":{"d":0},"d":1}}""".filterOutRedObjects() shouldBe Pair("""{"a":{}}""", 35) |
| 64 | + } |
| 65 | + |
| 66 | + "part 2: a sum of 6" { |
| 67 | + day12.part2(listOf("[1,2,3]")) shouldBe 6 |
| 68 | + } |
| 69 | + |
| 70 | + "part 2: a sum of 4 when ignoring object with a value of red" { |
| 71 | + day12.part2(listOf("""[1,{"c":"red","b":2},3]""")) shouldBe 4 |
| 72 | + } |
| 73 | + |
| 74 | + "part 2: a sum of 0 when ignoring object with a value of red" { |
| 75 | + day12.part2(listOf("""{"d":"red","e":[1,2,3,4],"f":5}""")) shouldBe 0 |
| 76 | + } |
| 77 | + |
| 78 | + "part 2: a sum of 6 with red in an array" { |
| 79 | + day12.part2(listOf("""[1,"red",5]""")) shouldBe 6 |
| 80 | + } |
| 81 | +}) |
0 commit comments