11package eu .sim642 .adventofcode2024
22
3- import Day20 ._
3+ import Day20 .*
44import org .scalatest .funsuite .AnyFunSuite
5- import eu .sim642 .adventofcodelib .IterableImplicits ._
5+ import eu .sim642 .adventofcodelib .IterableImplicits .*
6+ import org .scalatestplus .scalacheck .ScalaCheckPropertyChecks
67
7- class Day20Test extends AnyFunSuite {
8+ class Day20Test extends AnyFunSuite with ScalaCheckPropertyChecks {
89
910 val exampleInput =
1011 """ ###############
@@ -25,17 +26,25 @@ class Day20Test extends AnyFunSuite {
2526
2627 test(" Part 1 examples" ) {
2728 val cheats = Part1 .findCheats(parseGrid(exampleInput)).groupCount(_.save)
28- assert(cheats(2 ) == 14 )
29- assert(cheats(4 ) == 14 )
30- assert(cheats(6 ) == 2 )
31- assert(cheats(8 ) == 4 )
32- assert(cheats(10 ) == 2 )
33- assert(cheats(12 ) == 3 )
34- assert(cheats(20 ) == 1 )
35- assert(cheats(36 ) == 1 )
36- assert(cheats(38 ) == 1 )
37- assert(cheats(40 ) == 1 )
38- assert(cheats(64 ) == 1 )
29+
30+ val saveExpectedCount = Table (
31+ (" save" , " expectedCount" ),
32+ (2 , 14 ),
33+ (4 , 14 ),
34+ (6 , 2 ),
35+ (8 , 4 ),
36+ (10 , 2 ),
37+ (12 , 3 ),
38+ (20 , 1 ),
39+ (36 , 1 ),
40+ (38 , 1 ),
41+ (40 , 1 ),
42+ (64 , 1 ),
43+ )
44+
45+ forAll(saveExpectedCount) { (save, expectedCount) =>
46+ assert(cheats(save) == expectedCount)
47+ }
3948 }
4049
4150 test(" Part 1 input answer" ) {
@@ -44,20 +53,28 @@ class Day20Test extends AnyFunSuite {
4453
4554 test(" Part 2 examples" ) {
4655 val cheats = Part2 .findCheats(parseGrid(exampleInput)).groupCount(_.save)
47- assert(cheats(50 ) == 32 )
48- assert(cheats(52 ) == 31 )
49- assert(cheats(54 ) == 29 )
50- assert(cheats(56 ) == 39 )
51- assert(cheats(58 ) == 25 )
52- assert(cheats(60 ) == 23 )
53- assert(cheats(62 ) == 20 )
54- assert(cheats(64 ) == 19 )
55- assert(cheats(66 ) == 12 )
56- assert(cheats(68 ) == 14 )
57- assert(cheats(70 ) == 12 )
58- assert(cheats(72 ) == 22 )
59- assert(cheats(74 ) == 4 )
60- assert(cheats(76 ) == 3 )
56+
57+ val saveExpectedCount = Table (
58+ (" save" , " expectedCount" ),
59+ (50 , 32 ),
60+ (52 , 31 ),
61+ (54 , 29 ),
62+ (56 , 39 ),
63+ (58 , 25 ),
64+ (60 , 23 ),
65+ (62 , 20 ),
66+ (64 , 19 ),
67+ (66 , 12 ),
68+ (68 , 14 ),
69+ (70 , 12 ),
70+ (72 , 22 ),
71+ (74 , 4 ),
72+ (76 , 3 ),
73+ )
74+
75+ forAll(saveExpectedCount) { (save, expectedCount) =>
76+ assert(cheats(save) == expectedCount)
77+ }
6178 }
6279
6380 test(" Part 2 input answer" ) {
0 commit comments