12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- {-# LANGUAGE QuasiQuotes #-}
- module Day8Spec (spec) where
-
- import Test.Hspec
- import Text.Heredoc
- import Control.Arrow ((>>>))
-
- import qualified Data.Matrix as M
- import qualified Data.Vector as V
- import Day8
-
- testInput :: String
- testInput = [str|30373
- |25512
- |65332
- |33549
- |35390
- |]
-
- testVisibility :: Visibillity
- testVisibility = M.fromList 5 5
- [x,x,x,x,x,
- x,x,x,o,x,
- x,x,o,x,x,
- x,o,x,o,x,
- x,x,x,x,x]
- where
- x = True
- o = False
-
- smallForest :: String
- smallForest = [str|1234
- |5678
- |9012
- |]
-
- parsedSmallForest :: Forest
- parsedSmallForest = M.fromList 3 4 $ [1..9] ++ [0,1,2]
-
- spec :: Spec
- spec =
- describe "Day8" $ do
- describe "Part1" $ do
- it "parses a forest" $ do
- parseForest smallForest `shouldBe` parsedSmallForest
- it "checks visibility" $ do
- let forest = parseForest testInput
- checkVisibility forest `shouldBe` testVisibility
- it "counts visible things" $ do
- let v = parseForest >>>
- checkVisibility >>>
- countVisible $ testInput
- v `shouldBe` 21
- describe "Part2" $ do
- it "calculates viewing distance from height" $ do
- viewingDistance 5 (V.fromList [3]) `shouldBe` 1
- viewingDistance 5 (V.fromList [5,2]) `shouldBe` 1
- viewingDistance 5 (V.fromList [1,2]) `shouldBe` 2
- viewingDistance 5 (V.fromList [3,5,3]) `shouldBe` 2
- it "calculates the scenic score" $ do
- let s = parseForest >>>
- findMaxScenicScore $ testInput
- s `shouldBe` 8
|