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.

Day2Spec.hs 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. {-# LANGUAGE OverloadedStrings #-}
  2. module Day2Spec (spec) where
  3. import Test.Hspec
  4. import Day2.Shared
  5. import Day2.Part1
  6. import Day2.Part2
  7. input :: String
  8. input = "A Y\nB X\nC Z"
  9. spec :: Spec
  10. spec =
  11. describe "Day2" $ do
  12. describe "Day2 - Shared" $ do
  13. it "should have scores for shapes" $ do
  14. shapeScore Rock `shouldBe` Score 1
  15. shapeScore Paper `shouldBe` Score 2
  16. shapeScore Scissors `shouldBe` Score 3
  17. it "can sum up scores" $ do
  18. Score 1 <> Score 2 `shouldBe` Score 3
  19. it "can play games" $ do
  20. play (Game (Rock, Paper)) `shouldBe` shapeScore Paper <> gameWin
  21. describe "Day2 - Part1" $ do
  22. it "can parse game plan" $ do
  23. parseGameList input `shouldBe` games
  24. it "can parse a single game" $ do
  25. readGame "A Y" `shouldBe` Game (Rock, Paper)
  26. readGame "B X" `shouldBe` Game (Paper, Rock)
  27. readGame "C Z" `shouldBe` Game (Scissors, Scissors)
  28. it "can sum up games" $ do
  29. playGames games `shouldBe` Score 15
  30. it "can play game plan" $ do
  31. day2_1 input `shouldBe` Score 15
  32. describe "Day2 - Part1" $ do
  33. it "can parse game plan as hints" $ do
  34. readGameHints input `shouldBe` gameHints
  35. it "can convert game plan" $ do
  36. map executePlan gameHints `shouldBe` [Game (Rock, Rock),
  37. Game (Paper, Rock), Game (Scissors, Rock)]
  38. it "can play a game plan" $ do
  39. day2_2 input `shouldBe` Score 12
  40. where
  41. games = [Game (Rock, Paper), Game (Paper, Rock), Game (Scissors, Scissors)]
  42. gameHints = [GameHint (Rock, Draw), GameHint (Paper, Lose), GameHint (Scissors, Win)]