Creating New Test Data Inside the QuickCheck Property

I have problems with a programming problem here. Half of the problem is that the problem itself is rather complicated, and the other half is that I don’t remember how to find my way around QuickCheck.

I know that if you write a function that takes several arguments with an instance Arbitrary, QuickCheck will let you use this method as a test. I cannot figure out how to create new test arguments inside this method. I want to write something like

prop13 :: Foo -> Bar -> Bool
prop13 foo bar =
  if foobar foo bar
    then fn1 foo
    else newInput $ \ baz -> fn2 foo bar baz

but I can't figure out how the hell to do it.

In fact, no, I really want to write

prop13 :: Foo -> Bar -> Property
prop13 foo bar =
  if foobar foo bar
    then label "foobar=YES" $ fn1 foo
    else label "foobar=NO"  $ newInput $ \ baz -> fn2 foo bar baz

so that I can verify that it does not accept one branch at 100% of the time or something ridiculous.

, , , baz - . QuickCheck, - , . ( , ...)

? "", , , ...

+3
2

classify <condition> <string>$ <property>

,

prop_Insert x xs = ordered xs ==> classify (ordered (x:xs)) "at-head" $ classify (ordered (xs ++ [x])) "at-tail" $ ordered (insert x xs) where types = x :: Int

, , .

Main> quickCheck prop_Insert OK, passed 100 tests. 58% at-head, at-tail. 22% at-tail. 4% at-head.

, .

( )

, somePredicate data ==> , . :

prop_max xs = (not . null xs) ==> head (sort xs) == maximum xs

, . , newtype Arbitrary (. Positive, NonEmpty .. )

+4

. -, forAll:

else forAll arbitrary $ \ baz -> fn2 foo bar baz

, ...

( , .)

+4

All Articles