選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Day8Spec.hs 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. where
  24. x = True
  25. o = False
  26. smallForest :: String
  27. smallForest = [str|1234
  28. |5678
  29. |9012
  30. |]
  31. parsedSmallForest :: Forest
  32. parsedSmallForest = M.fromList 3 4 $ [1..9] ++ [0,1,2]
  33. spec :: Spec
  34. spec =
  35. describe "Day8" $ do
  36. describe "Part1" $ do
  37. it "parses a forest" $ do
  38. parseForest smallForest `shouldBe` parsedSmallForest
  39. it "checks visibility" $ do
  40. let forest = parseForest testInput
  41. checkVisibility forest `shouldBe` testVisibility
  42. it "counts visible things" $ do
  43. let v = parseForest >>>
  44. checkVisibility >>>
  45. countVisible $ testInput
  46. v `shouldBe` 21
  47. describe "Part2" $ do
  48. it "calculates viewing distance from height" $ do
  49. viewingDistance 5 (V.fromList [3]) `shouldBe` 1
  50. viewingDistance 5 (V.fromList [5,2]) `shouldBe` 1
  51. viewingDistance 5 (V.fromList [1,2]) `shouldBe` 2
  52. viewingDistance 5 (V.fromList [3,5,3]) `shouldBe` 2
  53. it "calculates the scenic score" $ do
  54. let s = parseForest >>>
  55. findMaxScenicScore $ testInput
  56. s `shouldBe` 8