Closed isovector closed 4 years ago
-- | Ensures a generator produces every possible data constructor.
producesAllValues :: forall a. Data a => Gen a -> Property
producesAllValues gen = ioProperty $ do
res <-
labelledExamplesResult $ forAllShow gen (const "") $ \p ->
classify True (show $ toConstr p) $ True
let all_cons =
S.fromList $ fmap show $ dataTypeConstrs $ dataTypeOf @a undefined
gen_cons = M.keysSet $ classes res
missing_cons = all_cons S.\\ gen_cons
pure $ flip whenFail (null missing_cons) $ do
putStrLn "Generator failed to produce the following data constructors:"
for_ missing_cons $ putStrLn . mappend "• "
-- | Lifts QuickSpec's observational equality to a property
(=-=) :: (Show t, Show o, Observe t o a) => a -> a -> Property
a =-= b = property $ \t -> observe t a === observe t b
This first one is just within
, and the last is already merged into quickspec
I have a few helpful combinators I use in many projects. If you're interested, I'd be happy to open a PR for each.