Skip to content

Commit

Permalink
Test 2024 day 20 examples with scalacheck
Browse files Browse the repository at this point in the history
  • Loading branch information
sim642 committed Dec 20, 2024
1 parent 88e7648 commit f96fb8e
Showing 1 changed file with 45 additions and 28 deletions.
73 changes: 45 additions & 28 deletions src/test/scala/eu/sim642/adventofcode2024/Day20Test.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package eu.sim642.adventofcode2024

import Day20._
import Day20.*
import org.scalatest.funsuite.AnyFunSuite
import eu.sim642.adventofcodelib.IterableImplicits._
import eu.sim642.adventofcodelib.IterableImplicits.*
import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks

class Day20Test extends AnyFunSuite {
class Day20Test extends AnyFunSuite with ScalaCheckPropertyChecks {

val exampleInput =
"""###############
Expand All @@ -25,17 +26,25 @@ class Day20Test extends AnyFunSuite {

test("Part 1 examples") {
val cheats = Part1.findCheats(parseGrid(exampleInput)).groupCount(_.save)
assert(cheats(2) == 14)
assert(cheats(4) == 14)
assert(cheats(6) == 2)
assert(cheats(8) == 4)
assert(cheats(10) == 2)
assert(cheats(12) == 3)
assert(cheats(20) == 1)
assert(cheats(36) == 1)
assert(cheats(38) == 1)
assert(cheats(40) == 1)
assert(cheats(64) == 1)

val saveExpectedCount = Table(
("save", "expectedCount"),
(2, 14),
(4, 14),
(6, 2),
(8, 4),
(10, 2),
(12, 3),
(20, 1),
(36, 1),
(38, 1),
(40, 1),
(64, 1),
)

forAll(saveExpectedCount) { (save, expectedCount) =>
assert(cheats(save) == expectedCount)
}
}

test("Part 1 input answer") {
Expand All @@ -44,20 +53,28 @@ class Day20Test extends AnyFunSuite {

test("Part 2 examples") {
val cheats = Part2.findCheats(parseGrid(exampleInput)).groupCount(_.save)
assert(cheats(50) == 32)
assert(cheats(52) == 31)
assert(cheats(54) == 29)
assert(cheats(56) == 39)
assert(cheats(58) == 25)
assert(cheats(60) == 23)
assert(cheats(62) == 20)
assert(cheats(64) == 19)
assert(cheats(66) == 12)
assert(cheats(68) == 14)
assert(cheats(70) == 12)
assert(cheats(72) == 22)
assert(cheats(74) == 4)
assert(cheats(76) == 3)

val saveExpectedCount = Table(
("save", "expectedCount"),
(50, 32),
(52, 31),
(54, 29),
(56, 39),
(58, 25),
(60, 23),
(62, 20),
(64, 19),
(66, 12),
(68, 14),
(70, 12),
(72, 22),
(74, 4),
(76, 3),
)

forAll(saveExpectedCount) { (save, expectedCount) =>
assert(cheats(save) == expectedCount)
}
}

test("Part 2 input answer") {
Expand Down

0 comments on commit f96fb8e

Please sign in to comment.