This commit is contained in:
Jens Kadenbach
2022-12-01 15:57:27 +01:00
commit c104561d8b
16 changed files with 2670 additions and 0 deletions

25
test/Spec.hs Normal file
View File

@@ -0,0 +1,25 @@
{-# LANGUAGE OverloadedStrings #-}
import Test.Hspec
import Day1
import Day1.Internal
import qualified Data.Text as T
main :: IO ()
main = hspec $ do
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
input <- readFile "ressources/day01-input-test"
elfToCalories (T.pack input) `shouldBe`
[ elf 6000, elf 4000, elf 11000, elf 24000, elf 10000 ]
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
it "sums the calorie counts" $ do
input <- readFile "ressources/day01-input-test"
findCaloriesOfTop3Elves (T.pack input) `shouldBe` calories 45000