Playing around with monads in D1 spec
This commit is contained in:
@@ -5,6 +5,12 @@ import Day1
|
|||||||
import Day1.Internal
|
import Day1.Internal
|
||||||
import qualified Data.Text as T
|
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 :: Spec
|
||||||
spec =
|
spec =
|
||||||
describe "Day1" $ do
|
describe "Day1" $ do
|
||||||
@@ -12,15 +18,17 @@ spec =
|
|||||||
let input = [ elf 6000, elf 4000, elf 11000]
|
let input = [ elf 6000, elf 4000, elf 11000]
|
||||||
sortElves input `shouldBe` [ elf 11000, elf 6000, elf 4000]
|
sortElves input `shouldBe` [ elf 11000, elf 6000, elf 4000]
|
||||||
it "converts a list of strings to a list of either int or caloriecount" $ do
|
it "converts a list of strings to a list of either int or caloriecount" $ do
|
||||||
input <- readFile "ressources/day01-input-test"
|
readTestFile >>=
|
||||||
parseElfInput (T.pack input) `shouldBe`
|
equals [ elf 6000, elf 4000, elf 11000, elf 24000, elf 10000 ]
|
||||||
[ elf 6000, elf 4000, elf 11000, elf 24000, elf 10000 ]
|
. (parseElfInput . T.pack)
|
||||||
it "parser text to int" $ do
|
it "parser text to int" $ do
|
||||||
intOrZero "1000" `shouldBe` 1000
|
intOrZero "1000" `shouldBe` 1000
|
||||||
it "finds the elf with the highest calorie count" $ do
|
it "finds the elf with the highest calorie count" $ do
|
||||||
input <- readFile "ressources/day01-input-test"
|
readTestFile >>=
|
||||||
findElfWithHighestCalorieCount (T.pack input) `shouldBe` elf 24000
|
equals (elf 24000) . (findElfWithHighestCalorieCount . T.pack)
|
||||||
it "sums the calorie counts" $ do
|
it "sums the calorie counts" $ do
|
||||||
input <- readFile "ressources/day01-input-test"
|
readTestFile >>=
|
||||||
findCaloriesOfTop3Elves (T.pack input) `shouldBe` calories 45000
|
equals (calories 45000) . (findCaloriesOfTop3Elves . T.pack)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user