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

View File

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

View File

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

View File

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

View File

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

View File

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