module Test.QuickCheck.Variant where
import Test.QuickCheck
class Variant a where
valid :: Gen a
invalid :: Gen a
instance (Variant a) => Variant [a] where
valid = do
x <- valid
xs <- valid
(oneof . map return) [[], [x], x:xs]
invalid = do
x <- invalid
xs <- invalid
y <- valid
ys <- valid
(oneof . map return) [[x], x:xs, x:ys, y:xs]
instance (Variant a) => Variant (Maybe a) where
invalid = do
x <- invalid
return (Just x)
valid = do
x <- valid
(oneof . map return) [Nothing, Just x]
instance (Variant a, Variant b) => Variant (Either a b) where
invalid = do
x <- invalid
y <- invalid
(oneof . map return) [Left x, Right y]
valid = do
x <- valid
y <- valid
(oneof . map return) [Left x, Right y]
instance (Variant a, Variant b) => Variant ((,) a b) where
invalid = do
x <- invalid
y <- invalid
z <- valid
w <- valid
(oneof . map return) [(x,y), (x,z), (w,y)]
valid = do
x <- valid
y <- valid
return (x, y)
instance (Variant a, Variant b, Variant c) => Variant ((,,) a b c) where
invalid = do
x <- invalid
y <- invalid
z <- invalid
w <- valid
v <- valid
u <- valid
(oneof . map return) [(x,y,z), (x,y,u), (x,v,z), (w,y,z), (w,v,z), (x,v,u), (w,y,u)]
valid = do
x <- valid
y <- valid
z <- valid
return (x, y, z)
class VarTesteable prop where
propertyValid::prop -> Property
propertyInvalid::prop -> Property
instance VarTesteable Bool where
propertyValid = property
propertyInvalid = property
instance (Arbitrary a, Variant a, Show a, Testable prop) => VarTesteable (a->prop) where
propertyValid = forAllShrink valid shrink
propertyInvalid = forAllShrink invalid shrink