You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Day8Spec.hs 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. {-# LANGUAGE QuasiQuotes #-}
  2. module Day8Spec (spec) where
  3. import Test.Hspec
  4. import Text.Heredoc
  5. import Control.Arrow ((>>>))
  6. import qualified Data.Matrix as M
  7. import qualified Data.Vector as V
  8. import Day8
  9. testInput :: String
  10. testInput = [str|30373
  11. |25512
  12. |65332
  13. |33549
  14. |35390
  15. |]
  16. testVisibility :: Visibillity
  17. testVisibility = M.fromList 5 5
  18. [x,x,x,x,x,
  19. x,x,x,o,x,
  20. x,x,o,x,x,
  21. x,o,x,o,x,
  22. x,x,x,x,x
  23. ]
  24. where
  25. x = True
  26. o = False
  27. smallForest :: String
  28. smallForest = [str|1234
  29. |5678
  30. |9012
  31. |]
  32. parsedSmallForest :: Forest
  33. parsedSmallForest = M.fromList 3 4 $ [1..9] ++ [0,1,2]
  34. spec :: Spec
  35. spec =
  36. describe "Day8" $ do
  37. describe "Part1" $ do
  38. it "parses a forest" $ do
  39. parseForest smallForest `shouldBe` parsedSmallForest
  40. it "checks visibility" $ do
  41. let forest = parseForest testInput
  42. checkVisibility forest `shouldBe` testVisibility
  43. it "counts visible things" $ do
  44. let v = parseForest >>>
  45. checkVisibility >>>
  46. countVisible $ testInput
  47. v `shouldBe` 21
  48. describe "Part2" $ do
  49. it "calculates viewing distance from height" $ do
  50. viewingDistance 5 (V.fromList [3]) `shouldBe` 1
  51. viewingDistance 5 (V.fromList [5,2]) `shouldBe` 1
  52. viewingDistance 5 (V.fromList [1,2]) `shouldBe` 2
  53. viewingDistance 5 (V.fromList [3,5,3]) `shouldBe` 2
  54. it "calculates the scenic score" $ do
  55. let s = parseForest >>>
  56. findMaxScenicScore $ testInput
  57. s `shouldBe` 8