[Haskell-cafe] Testing polymorphic properties with QuickCheck
Tom Ellis
tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk
Wed Feb 18 20:50:01 UTC 2015
On Thu, Feb 19, 2015 at 07:41:25AM +1100, Stuart Hungerford wrote:
> prop_left_add_id :: (Eq a, Monoid a) => a -> Bool
> prop_left_add_id x = zero |+| x == x
>
> monoid_suite :: TestTree
> monoid_suite = testGroup "monoid" [
> testProperty "left additive identity (Integer)"
> (prop_left_add_id :: Integer -> Bool),
>
> testProperty "left additive identity (Rational)"
> (prop_left_add_id :: Rational -> Bool),
>
> testProperty "left additive identity ((Integer, Integer))"
> (prop_left_add_id :: (Integer, Integer) -> Bool),
> -- ...]
I'm not quite sure what you're asking specifically, but maybe this will
help:
{-# LANGUAGE ScopedTypeVariables #-}
monoid_suite :: forall m. (Eq m, Monoid m) => String -> Proxy m -> TestTree
monoid_suite typename _ = testGroup "monoid" [
testProperty ("left additive identity (" ++ typename ++ ")")
(prop_left_add_id :: m -> Bool),
... <other general monoid properties here>
]
monoid_suite_integer :: TestTree
monoid_suite_integer = monoid_suite "Integer" (Proxy :: Integer)
monoid_suite_rational :: TestTree
monoid_suite_rational = monoid_suite "Rational" (Proxy :: Rational)
monoid_suite_pair :: TestTree
monoid_suite_pair = monoid_suite "(Integer, Integer)" (Proxy :: (Integer, Integer))
More information about the Haskell-Cafe
mailing list