You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Day1Spec.hs 1.1KB

12345678910111213141516171819202122232425262728293031323334
  1. {-# LANGUAGE OverloadedStrings #-}
  2. module Day1Spec (spec) where
  3. import Test.Hspec
  4. import Day1
  5. import Day1.Internal
  6. import qualified Data.Text as T
  7. readTestFile :: IO String
  8. readTestFile = readFile "ressources/day01-input-test"
  9. equals :: (HasCallStack, Show a, Eq a) => a -> a -> Expectation
  10. equals = flip shouldBe
  11. spec :: Spec
  12. spec =
  13. describe "Day1" $ do
  14. it "sorts elves" $ do
  15. let input = [ elf 6000, elf 4000, elf 11000]
  16. sortElves input `shouldBe` [ elf 11000, elf 6000, elf 4000]
  17. it "converts a list of strings to a list of either int or caloriecount" $ do
  18. readTestFile >>=
  19. equals [ elf 6000, elf 4000, elf 11000, elf 24000, elf 10000 ]
  20. . (parseElfInput . T.pack)
  21. it "parser text to int" $ do
  22. intOrZero "1000" `shouldBe` 1000
  23. it "finds the elf with the highest calorie count" $ do
  24. readTestFile >>=
  25. equals (elf 24000) . (findElfWithHighestCalorieCount . T.pack)
  26. it "sums the calorie counts" $ do
  27. readTestFile >>=
  28. equals (calories 45000) . (findCaloriesOfTop3Elves . T.pack)