[Haskell-cafe] How to generate dependend values with QuickCheck
jnf at arcor.de
Wed Aug 25 23:32:51 EDT 2010
I want to generate values, so that i have some arbitrary object, which has a
certain set of signals, and each set of signals has a certain set of sensor
value pairs, were the values are arbitrary.
However to demonstrate my problem I have an easy example, were I want to
generate an instance of
data QCExample = QCExample Int Int
and the second value should always be the double of the first. So I tried
instance Arbitrary QCExample where
let i1 = arbitrary
i2 = fmap (* 2) i1
in liftM2 QCExample i1 i2
but showing some of the generated test cases in ghci does not give me what I
let gen :: Gen (QCExample) = arbitrary
> QCExample (-2) 0
> QCExample (-4) (-6)
> QCExample 3 30
I know that I can filter, but this would be to inefficient.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe