Playing around with monads in D1 spec
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user