|
@@ -5,6 +5,12 @@ import Day1
|
5
|
5
|
import Day1.Internal
|
6
|
6
|
import qualified Data.Text as T
|
7
|
7
|
|
|
8
|
+readTestFile :: IO String
|
|
9
|
+readTestFile = readFile "ressources/day01-input-test"
|
|
10
|
+
|
|
11
|
+equals :: (HasCallStack, Show a, Eq a) => a -> a -> Expectation
|
|
12
|
+equals = flip shouldBe
|
|
13
|
+
|
8
|
14
|
spec :: Spec
|
9
|
15
|
spec =
|
10
|
16
|
describe "Day1" $ do
|
|
@@ -12,15 +18,17 @@ spec =
|
12
|
18
|
let input = [ elf 6000, elf 4000, elf 11000]
|
13
|
19
|
sortElves input `shouldBe` [ elf 11000, elf 6000, elf 4000]
|
14
|
20
|
it "converts a list of strings to a list of either int or caloriecount" $ do
|
15
|
|
- input <- readFile "ressources/day01-input-test"
|
16
|
|
- parseElfInput (T.pack input) `shouldBe`
|
17
|
|
- [ elf 6000, elf 4000, elf 11000, elf 24000, elf 10000 ]
|
|
21
|
+ readTestFile >>=
|
|
22
|
+ equals [ elf 6000, elf 4000, elf 11000, elf 24000, elf 10000 ]
|
|
23
|
+ . (parseElfInput . T.pack)
|
18
|
24
|
it "parser text to int" $ do
|
19
|
25
|
intOrZero "1000" `shouldBe` 1000
|
20
|
26
|
it "finds the elf with the highest calorie count" $ do
|
21
|
|
- input <- readFile "ressources/day01-input-test"
|
22
|
|
- findElfWithHighestCalorieCount (T.pack input) `shouldBe` elf 24000
|
|
27
|
+ readTestFile >>=
|
|
28
|
+ equals (elf 24000) . (findElfWithHighestCalorieCount . T.pack)
|
23
|
29
|
it "sums the calorie counts" $ do
|
24
|
|
- input <- readFile "ressources/day01-input-test"
|
25
|
|
- findCaloriesOfTop3Elves (T.pack input) `shouldBe` calories 45000
|
|
30
|
+ readTestFile >>=
|
|
31
|
+ equals (calories 45000) . (findCaloriesOfTop3Elves . T.pack)
|
|
32
|
+
|
|
33
|
+
|
26
|
34
|
|