12345678910111213141516171819202122232425262728293031323334 |
- {-# LANGUAGE OverloadedStrings #-}
- module Day1Spec (spec) where
- import Test.Hspec
- import Day1
- import Day1.Internal
- import qualified Data.Text as T
-
- readTestFile :: IO String
- readTestFile = readFile "ressources/day01-input-test"
-
- equals :: (HasCallStack, Show a, Eq a) => a -> a -> Expectation
- equals = flip shouldBe
-
- spec :: Spec
- spec =
- describe "Day1" $ do
- it "sorts elves" $ do
- let input = [ elf 6000, elf 4000, elf 11000]
- sortElves input `shouldBe` [ elf 11000, elf 6000, elf 4000]
- it "converts a list of strings to a list of either int or caloriecount" $ do
- readTestFile >>=
- equals [ elf 6000, elf 4000, elf 11000, elf 24000, elf 10000 ]
- . (parseElfInput . T.pack)
- it "parser text to int" $ do
- intOrZero "1000" `shouldBe` 1000
- it "finds the elf with the highest calorie count" $ do
- readTestFile >>=
- equals (elf 24000) . (findElfWithHighestCalorieCount . T.pack)
- it "sums the calorie counts" $ do
- readTestFile >>=
- equals (calories 45000) . (findCaloriesOfTop3Elves . T.pack)
-
-
|