2 RackUnit Integration
This module provides the test-random macro for generating RackUnit
test suites that generate and record random inputs.
(test-random opt ... | ([lhs rhs bind-opt ...] | ...) | body ...+) |
|
|
opt | | = | | #:name name | | | | | | #:repeat repeat | | | | | | #:limit limit | | | | | | bind-opt | | = | | #:where bind-where | | | | | | #:limit bind-limit |
|
The
test-random form constructs a RackUnit
test-suite that
conducts multiple trials of
body ...+. During a trial, each variable
lhs is bound to the value of the corresponding expression
rhs.
Bindings proceed left-to-right with
let*-scope, and each
rhs
is re-run to permit new random values.
The suite conducts repeat trials (default 100).
After each rhs is run, its corresponding where expression (if
any) is run; if where evaluates to #t, the rhs is
re-run. Each rhs is run at most the minimum of limit and the
corresponding bind-limit, defaulting to 10000.
Examples: |
> (require rackunit rackunit/text-ui) | > (random-seed 1) | | 100 success(es) 0 failure(s) 0 error(s) 100 test(s) run | 0 | > (random-seed 1) | | -------------------- | test w/ options > Trial #1 | Trial #1 | FAILURE | name: check-pred | location: eval:119:0 | params: #<procedure:positive?> | -158 |
| x: -165 | y: 7 | Check failure |
| === context === | /Applications/Racket v5.1.3/collects/rackunit/private/check.rkt:122:29 | /Applications/Racket v5.1.3/collects/rackunit/private/result.rkt:99:3 | /Applications/Racket v5.1.3/collects/rackunit/private/test-suite.rkt:28:2 | /Users/cce/git/planet/fasttest/rackunit.rkt:74:8: for-loop | the-tests | /Applications/Racket v5.1.3/collects/rackunit/private/test-suite.rkt:60:0: apply-test-suite | /Applications/Racket v5.1.3/collects/rackunit/text-ui.rkt:221:0: core | /Applications/Racket v5.1.3/collects/racket/private/more-scheme.rkt:151:2: call-with-break-parameterization | /Applications/Racket v5.1.3/collects/racket/sandbox.rkt:727:9: loop |
| -------------------- | -------------------- | test w/ options > Trial #3 | Trial #3 | FAILURE | name: check-pred | location: eval:119:0 | params: #<procedure:positive?> | -651 |
| x: -688 | y: 37 | Check failure |
| === context === | /Applications/Racket v5.1.3/collects/rackunit/private/check.rkt:122:29 | /Applications/Racket v5.1.3/collects/rackunit/private/result.rkt:99:3 | /Applications/Racket v5.1.3/collects/rackunit/private/test-suite.rkt:28:2 | /Users/cce/git/planet/fasttest/rackunit.rkt:74:8: for-loop | the-tests | /Applications/Racket v5.1.3/collects/rackunit/private/test-suite.rkt:60:0: apply-test-suite | /Applications/Racket v5.1.3/collects/rackunit/text-ui.rkt:221:0: core | /Applications/Racket v5.1.3/collects/racket/private/more-scheme.rkt:151:2: call-with-break-parameterization | /Applications/Racket v5.1.3/collects/racket/sandbox.rkt:727:9: loop |
| -------------------- | -------------------- | test w/ options > Trials #5 to #5 (unsatisfied :where clauses) | Trials #5 to #5 (unsatisfied :where clauses) | FAILURE | name: fail | location: rackunit.rkt:78:14 | params: | message: "Out of 4 attempts to generate input data for 5 trials, only 4 satisfied the preconditions from the :where option. Consider increasing the maximum number of attempts to generate input data with the :limit option or decreasing the number of trials of the property with the :repeat option.\n\nFailed input data sets include:\n" | Check failure |
| === context === | /Applications/Racket v5.1.3/collects/rackunit/private/check.rkt:122:29 | /Applications/Racket v5.1.3/collects/rackunit/private/result.rkt:99:3 | /Applications/Racket v5.1.3/collects/rackunit/private/test-suite.rkt:28:2 | /Users/cce/git/planet/fasttest/rackunit.rkt:74:8: for-loop | the-tests | /Applications/Racket v5.1.3/collects/rackunit/private/test-suite.rkt:60:0: apply-test-suite | /Applications/Racket v5.1.3/collects/rackunit/text-ui.rkt:221:0: core | /Applications/Racket v5.1.3/collects/racket/private/more-scheme.rkt:151:2: call-with-break-parameterization | /Applications/Racket v5.1.3/collects/racket/sandbox.rkt:727:9: loop |
| -------------------- | 2 success(es) 3 failure(s) 0 error(s) 5 test(s) run |
| 3 | > (random-seed 1) | | -------------------- | test w/ bind options > Trials #3 to #4 (unsatisfied :where clauses) | Trials #3 to #4 (unsatisfied :where clauses) | FAILURE | name: fail | location: rackunit.rkt:78:14 | params: | message: "Out of 1000 attempts to generate input data for 4 trials, only 2 satisfied the preconditions from the :where option. Consider increasing the maximum number of attempts to generate input data with the :limit option or decreasing the number of trials of the property with the :repeat option.\n\nFailed input data sets include:\nx = -123\ny = 2716\n\nx = -123\ny = 886\n\nx = -688\n" | Check failure |
| === context === | /Applications/Racket v5.1.3/collects/rackunit/private/check.rkt:122:29 | /Applications/Racket v5.1.3/collects/rackunit/private/result.rkt:99:3 | /Applications/Racket v5.1.3/collects/rackunit/private/test-suite.rkt:28:2 | /Users/cce/git/planet/fasttest/rackunit.rkt:74:8: for-loop | the-tests | /Applications/Racket v5.1.3/collects/rackunit/private/test-suite.rkt:60:0: apply-test-suite | /Applications/Racket v5.1.3/collects/rackunit/text-ui.rkt:221:0: core | /Applications/Racket v5.1.3/collects/racket/private/more-scheme.rkt:151:2: call-with-break-parameterization | /Applications/Racket v5.1.3/collects/racket/sandbox.rkt:727:9: loop |
| -------------------- | 2 success(es) 1 failure(s) 0 error(s) 3 test(s) run |
| 1 |
|