advent-of-code/2023/haskell/tests/Main.hs

64 lines
1.8 KiB
Haskell
Raw Normal View History

2023-12-01 23:03:57 +01:00
{-# LANGUAGE OverloadedStrings #-}
module Main (main) where
import Test.HUnit
import qualified System.Exit as Exit
import qualified Day01
2023-12-02 13:42:14 +01:00
import qualified Day02
2023-12-03 13:12:15 +01:00
import qualified Day03
2023-12-01 23:03:57 +01:00
day01 :: Test
day01 = TestList
2023-12-03 13:12:15 +01:00
[ TestCase $ assertEqual "A" 142 (Day01.solveA inputA)
, TestCase $ assertEqual "B" 281 (Day01.solveB inputB)
2023-12-01 23:03:57 +01:00
]
where
inputA = ["1abc2", "pqr3stu8vwx", "a1b2c3d4e5f", "treb7uchet"]
inputB = ["two1nine", "eightwothree", "abcone2threexyz", "xtwone3four", "4nineeightseven2", "zoneight234", "7pqrstsixteen"]
2023-12-02 13:42:14 +01:00
day02 :: Test
day02 = TestList
2023-12-03 13:12:15 +01:00
[ TestCase $ assertEqual "A" 8 (Day02.solveA input)
, TestCase $ assertEqual "B" 2286 (Day02.solveB input)
2023-12-02 13:42:14 +01:00
]
where
2023-12-02 14:32:05 +01:00
input =
2023-12-02 13:42:14 +01:00
[ Day02.Game 1 [[Day02.B 3, Day02.R 4], [Day02.R 1, Day02.G 2, Day02.B 6], [Day02.G 2]]
, Day02.Game 2 [[Day02.B 1, Day02.G 2], [Day02.G 3, Day02.B 4, Day02.R 1], [Day02.G 1, Day02.B 1]]
, Day02.Game 3 [[Day02.G 8, Day02.B 6, Day02.R 20], [Day02.B 5, Day02.R 4, Day02.G 13], [Day02.G 5, Day02.R 1]]
, Day02.Game 4 [[Day02.G 1, Day02.R 3, Day02.B 6], [Day02.G 3, Day02.R 6], [Day02.G 3, Day02.B 15, Day02.R 14]]
, Day02.Game 5 [[Day02.R 6, Day02.B 1, Day02.G 3], [Day02.B 2, Day02.R 1, Day02.G 2]]
]
2023-12-01 23:03:57 +01:00
2023-12-03 13:12:15 +01:00
day03 :: Test
day03 = TestList
[ TestCase $ assertEqual "A" (Right 4361) (Day03.solveA <$> Day03.parse input)
]
where
input =
"467..114..\n\
\...*......\n\
\..35..633.\n\
\......#...\n\
\617*......\n\
\.....+.58.\n\
\..592.....\n\
\......755.\n\
\...$.*....\n\
\.664.598..\n"
2023-12-01 23:03:57 +01:00
tests :: Test
tests = TestList
[ TestLabel "day01" day01
2023-12-02 13:42:14 +01:00
, TestLabel "day02" day02
2023-12-03 13:12:15 +01:00
, TestLabel "day03" day03
2023-12-01 23:03:57 +01:00
]
main :: IO ()
main = isFailed . failures =<< runTestTT tests
where
isFailed count
| count > 0 = Exit.exitFailure
| otherwise = Exit.exitSuccess