-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolutionSpec.hs
72 lines (67 loc) · 2.49 KB
/
SolutionSpec.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
module Day17.SolutionSpec (spec) where
import Advent.Utils (occurrences)
import qualified Data.Map.Strict as Map
import Day17.Solution
( CubeState (..),
Point3D (..),
Point4D (..),
executeCycles,
parsePocketDimension,
part1,
part2,
)
import Test.Hspec
spec :: Spec
spec = parallel $ do
it "solves Part 1" $ do
input <- readFile "./test/Day17/input.txt"
part1 input `shouldBe` "215"
it "solves Part 2" $ do
input <- readFile "./test/Day17/input.txt"
part2 input `shouldBe` "1728"
let examplePocketDimension3D =
Map.fromList
[ (Point3D (0, 0, 0), Inactive),
(Point3D (0, 1, 0), Inactive),
(Point3D (0, 2, 0), Active),
(Point3D (1, 0, 0), Active),
(Point3D (1, 1, 0), Inactive),
(Point3D (1, 2, 0), Active),
(Point3D (2, 0, 0), Inactive),
(Point3D (2, 1, 0), Active),
(Point3D (2, 2, 0), Active)
]
let examplePocketDimension4D =
Map.fromList
[ (Point4D (0, 0, 0, 0), Inactive),
(Point4D (0, 1, 0, 0), Inactive),
(Point4D (0, 2, 0, 0), Active),
(Point4D (1, 0, 0, 0), Active),
(Point4D (1, 1, 0, 0), Inactive),
(Point4D (1, 2, 0, 0), Active),
(Point4D (2, 0, 0, 0), Inactive),
(Point4D (2, 1, 0, 0), Active),
(Point4D (2, 2, 0, 0), Active)
]
describe "parsePocketDimension" $ do
context "parsing 3D pockets" $ do
it "parses input" $ do
input <- readFile "./test/Day17/example.txt"
parsePocketDimension input `shouldBe` Right examplePocketDimension3D
context "parsing 4D pockets" $ do
it "parses input" $ do
input <- readFile "./test/Day17/example.txt"
parsePocketDimension input `shouldBe` Right examplePocketDimension4D
describe "executeCycles" $ do
context "given 3D pockets" $ do
let cycles = 6 :: Int
let expected = 112 :: Int
context ("when running " ++ show cycles ++ " cycles") $ do
it ("has " ++ show expected ++ " active cubes") $ do
(occurrences Active . executeCycles cycles) examplePocketDimension3D `shouldBe` expected
context "given 4D pockets" $ do
let cycles = 6 :: Int
let expected = 848 :: Int
context ("when running " ++ show cycles ++ " cycles") $ do
it ("has " ++ show expected ++ " active cubes") $ do
(occurrences Active . executeCycles cycles) examplePocketDimension4D `shouldBe` expected