On this page:
test-random

2 SchemeUnit Integration

 (require (planet cce/fasttest:3:8/schemeunit))

This module provides the test-random macro for generating SchemeUnit 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 SchemeUnit 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 (planet schematics/schemeunit:2:10/test)
             (planet schematics/schemeunit:2:10/text-ui))
  > (random-seed 1)
  > (test/text-ui
     (test-random
      ([x (random-integer)]
       [y (random-integer)])
      (check-pred integer? (+ x y))))

  100 success(es) 0 failure(s) 0 error(s) 100 test(s) run

  0

  > (random-seed 1)
  > (test/text-ui
     (test-random #:name "test w/ options"
                  #:limit 4
                  #:repeat 5
      ([x (random-integer)]
       [y (random-integer)])
      (check-pred positive? (+ x y))))

  

  test w/ options > 1

  1 has a FAILURE

  x: -165

  y: 7

  name: check-pred

  location: eval:119:0

  params:

  #<procedure:positive?>

  -158

  

  test w/ options > 3

  3 has a FAILURE

  x: -688

  y: 37

  name: check-pred

  location: eval:119:0

  params:

  #<procedure:positive?>

  -651

  

  test w/ options > 5

  5 has an ERROR

  test w/ options: Out of random values.  Failed attempts include:

  

  

  

   === context ===

  /Users/cce/git/release/plt/add-on/planet/4.90.0.1/cache/schematics/schemeunit.plt/2/12/plt/result.ss:70:5

  /Users/cce/git/release/plt/add-on/planet/4.90.0.1/cache/schematics/schemeunit.plt/2/12/plt/../generic/foldts.ss:57:6: loop

  test/text-ui

  /Users/cce/git/release/plt/collects/racket/private/more-scheme.rkt:158:2: call-with-break-parameterization

  /Users/cce/git/release/plt/collects/racket/sandbox.rkt:704:9: loop

  

  

  2 success(es) 2 failure(s) 1 error(s) 5 test(s) run

  3

  > (random-seed 1)
  > (test/text-ui
     (test-random #:name "test w/ bind options"
                  #:repeat 4
      ([x (random-integer)
          #:where (odd? x)
          #:limit 4]
       [y (random-integer)
          #:where (odd? y)
          #:limit 4])
      (check-pred even? (+ x y))))

  

  test w/ bind options > 3

  3 has an ERROR

  test w/ bind options: Out of random values.  See trial #4 for list of attempts.

  

   === context ===

  /Users/cce/git/release/plt/add-on/planet/4.90.0.1/cache/schematics/schemeunit.plt/2/12/plt/result.ss:70:5

  /Users/cce/git/release/plt/add-on/planet/4.90.0.1/cache/schematics/schemeunit.plt/2/12/plt/../generic/foldts.ss:57:6: loop

  test/text-ui

  /Users/cce/git/release/plt/collects/racket/private/more-scheme.rkt:158:2: call-with-break-parameterization

  /Users/cce/git/release/plt/collects/racket/sandbox.rkt:704:9: loop

  

  

  

  test w/ bind options > 4

  4 has an ERROR

  test w/ bind options: Out of random values.  Failed attempts include:

  

  x = -123

  y = 2716

  

  x = -123

  y = 886

  

  x = -688

  

  

   === context ===

  /Users/cce/git/release/plt/add-on/planet/4.90.0.1/cache/schematics/schemeunit.plt/2/12/plt/result.ss:70:5

  /Users/cce/git/release/plt/add-on/planet/4.90.0.1/cache/schematics/schemeunit.plt/2/12/plt/../generic/foldts.ss:57:6: loop

  test/text-ui

  /Users/cce/git/release/plt/collects/racket/private/more-scheme.rkt:158:2: call-with-break-parameterization

  /Users/cce/git/release/plt/collects/racket/sandbox.rkt:704:9: loop

  

  

  2 success(es) 0 failure(s) 2 error(s) 4 test(s) run

  2