文件
advent-of-code-2022/test/Day2Spec.hs
2022-12-02 16:49:32 +01:00

53 行
1.9 KiB
Haskell

{-# LANGUAGE OverloadedStrings #-}
module Day2Spec (spec) where
import Test.Hspec
import Day2.Shared
import Day2.Part1
import Day2.Part2
input :: String
input = "A Y\nB X\nC Z"
spec :: Spec
spec =
describe "Day2" $ do
describe "Day2 - Shared" $ do
it "should implement winAgainst and loseAgainst for shapes" $ do
winAgainst Rock `shouldBe` Paper
winAgainst Paper `shouldBe` Scissors
winAgainst Scissors `shouldBe` Rock
loseAgainst Rock `shouldBe` Scissors
loseAgainst Paper `shouldBe` Rock
loseAgainst Scissors `shouldBe` Paper
it "should have scores for shapes" $ do
shapeScore Rock `shouldBe` Score 1
shapeScore Paper `shouldBe` Score 2
shapeScore Scissors `shouldBe` Score 3
it "can sum up scores" $ do
Score 1 <> Score 2 `shouldBe` Score 3
it "can play games" $ do
play (Game (Rock, Paper)) `shouldBe` shapeScore Paper <> gameWin
describe "Day2 - Part1" $ do
it "can parse game plan" $ do
parseGameList input `shouldBe` games
it "can parse a single game" $ do
readGame "A Y" `shouldBe` Game (Rock, Paper)
readGame "B X" `shouldBe` Game (Paper, Rock)
readGame "C Z" `shouldBe` Game (Scissors, Scissors)
it "can sum up games" $ do
playGames games `shouldBe` Score 15
it "can play game plan" $ do
day2_1 input `shouldBe` Score 15
describe "Day2 - Part2" $ do
it "can parse game plan as hints" $ do
readGameHints input `shouldBe` gameHints
it "can convert game plan" $ do
map executePlan gameHints `shouldBe` [Game (Rock, Rock),
Game (Paper, Rock), Game (Scissors, Rock)]
it "can play a game plan" $ do
day2_2 input `shouldBe` Score 12
where
games = [Game (Rock, Paper), Game (Paper, Rock), Game (Scissors, Scissors)]
gameHints = [GameHint (Rock, Draw), GameHint (Paper, Lose), GameHint (Scissors, Win)]