This commit is contained in:
Jens Kadenbach
2022-12-02 16:18:26 +01:00
parent 024edd3e9d
commit 71972e30ec
8 changed files with 2697 additions and 2 deletions

45
test/Day2Spec.hs Normal file
View File

@@ -0,0 +1,45 @@
{-# 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 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 - Part1" $ 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)]