ifigueroap / racket-quickcheck

Quickcheck Clone implemented in Racket
Other
32 stars 16 forks source link

Provide variant #32

Closed pmatos closed 6 years ago

pmatos commented 6 years ago

I think we need to provide variant to allow others to define their custom arbitrary values. Following the example of the definition of arbitrary-natural, here's the definition of arbitrary/64 which generates arbitrary 64bit values:

(define arbitrary/64
  (arbitrary (sized (lambda (n) (choose-integer 0 (- (expt 2 64) 1))))
                 (lambda (n gen) (variant n gen))))

However, this is not possible if variant is not provided.

pmatos commented 6 years ago

Interestingly I just noticed that I can have a generator? passed to a property instead of an arbitrary?, therefore this is possible and it works:

(define arbitrary/64 (choose-integer 0 (- (expt 2 64) 1)))