Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Day2Spec.hs 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 implement winAgainst and loseAgainst for shapes" $ do
  14. winAgainst Rock `shouldBe` Paper
  15. winAgainst Paper `shouldBe` Scissors
  16. winAgainst Scissors `shouldBe` Rock
  17. loseAgainst Rock `shouldBe` Scissors
  18. loseAgainst Paper `shouldBe` Rock
  19. loseAgainst Scissors `shouldBe` Paper
  20. it "should have scores for shapes" $ do
  21. shapeScore Rock `shouldBe` Score 1
  22. shapeScore Paper `shouldBe` Score 2
  23. shapeScore Scissors `shouldBe` Score 3
  24. it "can sum up scores" $ do
  25. Score 1 <> Score 2 `shouldBe` Score 3
  26. it "can play games" $ do
  27. play (Game (Rock, Paper)) `shouldBe` shapeScore Paper <> gameWin
  28. describe "Day2 - Part1" $ do
  29. it "can parse game plan" $ do
  30. parseGameList input `shouldBe` games
  31. it "can parse a single game" $ do
  32. readGame "A Y" `shouldBe` Game (Rock, Paper)
  33. readGame "B X" `shouldBe` Game (Paper, Rock)
  34. readGame "C Z" `shouldBe` Game (Scissors, Scissors)
  35. it "can sum up games" $ do
  36. playGames games `shouldBe` Score 15
  37. it "can play game plan" $ do
  38. day2_1 input `shouldBe` Score 15
  39. describe "Day2 - Part2" $ do
  40. it "can parse game plan as hints" $ do
  41. readGameHints input `shouldBe` gameHints
  42. it "can convert game plan" $ do
  43. map executePlan gameHints `shouldBe` [Game (Rock, Rock),
  44. Game (Paper, Rock), Game (Scissors, Rock)]
  45. it "can play a game plan" $ do
  46. day2_2 input `shouldBe` Score 12
  47. where
  48. games = [Game (Rock, Paper), Game (Paper, Rock), Game (Scissors, Scissors)]
  49. gameHints = [GameHint (Rock, Draw), GameHint (Paper, Lose), GameHint (Scissors, Win)]