From d740f2de7f3592f3a710e0f635e17acbb7fb0319 Mon Sep 17 00:00:00 2001 From: Jens Kadenbach Date: Fri, 2 Dec 2022 17:08:04 +0100 Subject: [PATCH] Playing around with monads in D1 spec --- test/Day1Spec.hs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/test/Day1Spec.hs b/test/Day1Spec.hs index dafa3a8..ce57ee9 100644 --- a/test/Day1Spec.hs +++ b/test/Day1Spec.hs @@ -5,6 +5,12 @@ 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 @@ -12,15 +18,17 @@ spec = 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 - input <- readFile "ressources/day01-input-test" - parseElfInput (T.pack input) `shouldBe` - [ elf 6000, elf 4000, elf 11000, elf 24000, elf 10000 ] + 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 - input <- readFile "ressources/day01-input-test" - findElfWithHighestCalorieCount (T.pack input) `shouldBe` elf 24000 + readTestFile >>= + equals (elf 24000) . (findElfWithHighestCalorieCount . T.pack) it "sums the calorie counts" $ do - input <- readFile "ressources/day01-input-test" - findCaloriesOfTop3Elves (T.pack input) `shouldBe` calories 45000 + readTestFile >>= + equals (calories 45000) . (findCaloriesOfTop3Elves . T.pack) + +