garnet/haskell/Main.hs

46 lines
1.8 KiB
Haskell
Raw Normal View History

2025-12-02 01:37:59 +00:00
module Main (main) where
2025-12-04 21:16:46 +00:00
import Data.Bool
2025-12-02 08:23:53 +00:00
import Data.ByteString.Lazy qualified as BL
import Data.Functor
2025-12-04 21:16:46 +00:00
import Data.List.Extra
2025-12-02 09:11:42 +00:00
import Data.Text.IO qualified as T
import Data.Text.Lazy.Encoding (encodeUtf8)
2025-12-02 15:19:11 +00:00
import Puzzle
import Puzzles.Day1 qualified as Day1
import Puzzles.Day2 qualified as Day2
2025-12-03 11:18:04 +00:00
import Puzzles.Day3 qualified as Day3
2025-12-04 10:00:15 +00:00
import Puzzles.Day4 qualified as Day4
2025-12-02 08:23:53 +00:00
import Test.Tasty
import Test.Tasty.Golden (goldenVsString)
2025-12-02 09:30:39 +00:00
import Test.Tasty.Ingredients.ConsoleReporter
2025-12-02 09:08:43 +00:00
import Text.Megaparsec hiding (Pos)
2025-12-02 00:32:49 +00:00
main :: IO ()
2025-12-02 08:23:53 +00:00
main =
2025-12-02 09:38:31 +00:00
defaultMain
. localOption (Always :: UseColor)
2025-12-02 11:22:17 +00:00
. testGroup "tests"
2025-12-04 21:16:46 +00:00
$ enumerate <&> \isRealData@(bool "examples" "real" -> t) ->
2025-12-02 14:35:17 +00:00
testGroup t $
[ Day1.puzzle
, Day2.puzzle
2025-12-03 11:18:04 +00:00
, Day3.puzzle
2025-12-04 10:00:15 +00:00
, Day4.puzzle
2025-12-02 14:35:17 +00:00
]
2025-12-04 20:11:16 +00:00
<&> \Puzzle{number, parser, parts, extraTests} ->
2025-12-02 14:35:17 +00:00
let
pt = show number
parseFile fp =
either (fail . ("parse failure: " <>) . errorBundlePretty) pure
. runParser (parser <* eof) fp
=<< T.readFile fp
in
withResource (parseFile $ "../inputs/" <> t <> "/" <> pt) mempty \input ->
2025-12-02 14:35:17 +00:00
testGroup pt $
2025-12-04 20:11:37 +00:00
( zip (map show [1 :: Int ..]) parts <&> \(n, pp) ->
goldenVsString n ("../outputs/" <> t <> "/" <> pt <> "/" <> n) $
encodeUtf8 . pp <$> input
2025-12-04 20:11:16 +00:00
)
2025-12-04 21:16:46 +00:00
<> [testGroup "extra" $ extraTests isRealData ("../outputs/" <> t <> "/" <> pt <> "/extra/") input]