Open 97jaz opened 7 years ago
From reading the source and the original paper on Quickcheck, I'm getting a better sense of what's going on, but it makes me think that variant
should have been provided.
To give some background, I'm trying to produce arbitrary dates. I got this to work -- I hope correctly -- by doing this:
(require rackunit
quickcheck
(only-in quickcheck/generator
variant
lift->generator)
datetime/date)
(define (choose-date lower upper)
(define lo (date->jdn lower))
(define hi (date->jdn upper))
(lift->generator
jdn->date
(choose-integer lo hi)))
(define arbitrary-date
(arbitrary
(sized
(λ (n)
(choose-date (jdn->date (- n))
(jdn->date n))))
(λ (n gen)
(variant (if (>= n 0)
(* 2 n)
(+ (* 2 (- n)) 1))
gen))))
This solution has a couple of deficiencies: it requires two undocumented procedures from quickcheck, and it reproduces the variant-choosing logic from the implementation of arbitrary-integer
(which, I think, is to ensure that the first argument to variant
is nonnegative).
Have I overlooked a better way of accomplishing this?
The documentation for the
arbitrary
struct says:And
trans
has the contract:But nothing indicates how the first argument to that function is used to narrow the set.