Add way to specify extra tests

This commit is contained in:
George Thomas 2025-12-04 20:11:16 +00:00
parent 0508947a65
commit 8f67916e1a
6 changed files with 10 additions and 1 deletions

View File

@ -26,7 +26,7 @@ main =
, Day3.puzzle , Day3.puzzle
, Day4.puzzle , Day4.puzzle
] ]
<&> \Puzzle{number, parser, parts} -> <&> \Puzzle{number, parser, parts, extraTests} ->
let let
pt = show number pt = show number
parseFile fp = parseFile fp =
@ -36,6 +36,9 @@ main =
in in
withResource (parseFile $ "../inputs/" <> t <> "/" <> pt) mempty \input -> withResource (parseFile $ "../inputs/" <> t <> "/" <> pt) mempty \input ->
testGroup pt $ testGroup pt $
(
zip (map show [1 :: Int ..]) parts <&> \(n, pp) -> zip (map show [1 :: Int ..]) parts <&> \(n, pp) ->
goldenVsString n ("../outputs/" <> t <> "/" <> pt <> "/" <> n) $ goldenVsString n ("../outputs/" <> t <> "/" <> pt <> "/" <> n) $
BL.fromStrict . encodeUtf8 . pp <$> input BL.fromStrict . encodeUtf8 . pp <$> input
)
<> [testGroup "extra" extraTests]

View File

@ -2,10 +2,12 @@ module Puzzle where
import Data.Text (Text) import Data.Text (Text)
import Data.Void import Data.Void
import Test.Tasty
import Text.Megaparsec import Text.Megaparsec
data Puzzle = forall input. Puzzle data Puzzle = forall input. Puzzle
{ number :: Word { number :: Word
, parser :: Parsec Void Text input , parser :: Parsec Void Text input
, parts :: [input -> Text] , parts :: [input -> Text]
, extraTests :: [TestTree]
} }

View File

@ -37,6 +37,7 @@ puzzle =
| p' == 0 -> abs c + 1 | p' == 0 -> abs c + 1
| otherwise -> abs c | otherwise -> abs c
] ]
, extraTests = []
} }
data Direction = L | R data Direction = L | R

View File

@ -25,6 +25,7 @@ puzzle =
. concatMap . concatMap
(mapMaybe (\n -> guard (isRepetitionN n) $> n) . uncurry enumFromTo) (mapMaybe (\n -> guard (isRepetitionN n) $> n) . uncurry enumFromTo)
] ]
, extraTests = []
} }
newtype ID = ID Int newtype ID = ID Int

View File

@ -26,6 +26,7 @@ puzzle =
. sum . sum
. map (digitsToInt . fromMaybe (error "battery list too short") . maxBatteries 12) . map (digitsToInt . fromMaybe (error "battery list too short") . maxBatteries 12)
] ]
, extraTests = []
} }
newtype Bank = Bank (NonEmpty Battery) newtype Bank = Bank (NonEmpty Battery)

View File

@ -27,6 +27,7 @@ puzzle =
. unfoldr ((\r -> guard (fst r /= 0) $> r) . (removeAccessibleRolls <<<<$>>>>) . findAccessible) . unfoldr ((\r -> guard (fst r /= 0) $> r) . (removeAccessibleRolls <<<<$>>>>) . findAccessible)
. addCoords . addCoords
] ]
, extraTests = []
} }
addCoords :: (Num a, Enum a) => [[c]] -> [[(V2 a, c)]] addCoords :: (Num a, Enum a) => [[c]] -> [[(V2 a, c)]]