racket-quickcheck icon indicating copy to clipboard operation
racket-quickcheck copied to clipboard

Document that properties can be nested

Open dbp opened this issue 2 years ago • 0 comments

From the documentation, it would seem that this shouldn't work:

(quickcheck (property [(x arbitrary-integer)]
                (property [(y arbitrary-integer)]
      (= (* x y) (* y x)))

But it does; if the body is changed to fail, the reporting does the right thing: tells you the x and y that cause the issue.

And indeed, so does this:

(quickcheck (property [(x arbitrary-integer)]
                        (if (< x 10)
                           (property [(y arbitrary-integer)]
                             (= (* x y) (* y x)))
                           (property [(y arbitrary-integer)]
                              (= (* x y) (* y x 2))))

This is great, but nothing on the documentation makes it obvious this would be possible! For property:

"The ids are bound to the result of the given gen/arb-exprs inside the body expressions. The body expressions are used as the bodies of a predicate function that will be run with newly generated values from the specified generators or arbitraries."

dbp avatar Jan 27 '23 15:01 dbp