minor cleanups to contract-random-generate's API
This commit is contained in:
parent
42acb08399
commit
1f1d1a38aa
|
@ -2766,8 +2766,8 @@ parts of the contract system.
|
|||
@section{Random generation}
|
||||
|
||||
@defproc[(contract-random-generate [ctc contract?]
|
||||
[fuel int?]
|
||||
[fail (-> any/c) (λ () (error ...))])
|
||||
[fuel 5 exact-nonnegative-integer?]
|
||||
[fail (or/c #f (-> any)) #f])
|
||||
any/c]{
|
||||
Attempts to randomly generate a value which will match the contract. The fuel
|
||||
argument limits how hard the generator tries to generate a value matching the
|
||||
|
|
|
@ -107,9 +107,17 @@
|
|||
(append ctcs (definitely-available-contracts))])
|
||||
(thunk)))
|
||||
|
||||
; generate : contract int -> ctc value or error
|
||||
(define (contract-random-generate ctc fuel [_fail #f])
|
||||
(define (contract-random-generate ctc [fuel 5] [_fail #f])
|
||||
(define def-ctc (coerce-contract 'contract-random-generate ctc))
|
||||
(unless (exact-nonnegative-integer? fuel)
|
||||
(raise-argument-error 'contract-random-generate
|
||||
"exact-nonnegative-integer?"
|
||||
fuel))
|
||||
(unless (or (not _fail) (and (procedure? _fail) (procedure-arity-includes? _fail 0)))
|
||||
(raise-argument-error 'contract-random-generate
|
||||
(format "~s" '(or/c #f (-> any)))
|
||||
3
|
||||
ctc fuel _fail))
|
||||
(define proc
|
||||
(parameterize ([generate-env (make-hash)])
|
||||
(generate/choose def-ctc fuel)))
|
||||
|
|
Loading…
Reference in New Issue
Block a user