I'm using QuickCheck to do generative testing in Clojure.
However I don't know it well and often I end up doing convoluted things. One thing that I need to do quite often is something like that:
- generate a first prime number from a list of prime-numbers (so far so good)
- generate a second prime number which is smaller than the first one
- generate a third prime number which is smaller than the first one
However I have no idea as to how to do that cleanly using QuickCheck.
Here's an even simpler, silly, example which doesn't work:
(prop/for-all [a (gen/choose 1 10)
b (gen/such-that #(= a %) (gen/choose 1 10))]
(= a b))
It doesn't work because a cannot be resolved (prop/for-all
isn't like a let
statement).
So how can I generate the three primes, with the condition that the two latter ones are inferior to the first one?