unit testing - Typed racket error with check-random -


i'm trying convert project on typed racket racket , i'm encountering errors working code because of testing engine.

i've reduced smallest piece of code can create reproduces problem:

#lang typed/racket  ; provides check-expect , others testing (require typed/test-engine/racket-tests)  (: bar (-> positive-integer integer))  (check-random (bar 6) (random 6))  (define (bar x)   (random x))  (test) 

and errors are:

. type checker: type mismatch   expected: pseudo-random-generator   given: in: (check-random (bar 6) (random 6))  . type checker: type mismatch   expected: positive-integer   given: in: (check-random (bar 6) (random 6))  . type checker: summary: 3 errors encountered in:   (check-random (bar 6) (random 6))   (check-random (bar 6) (random 6))   (check-random (bar 6) (random 6)) 

does have advice on how fix this? want able use type checking features if possible.

thanks

sure, can help, depends lot on want, , you're going this.

short overview: there multiple testing frameworks racket. you're using 1 that's built teaching languages. has several nice features, speaking rackunit testing framework used others.

it appears me typed version of teaching-language-test-framework doesn't include support check-random. i'll check on over mailing list. steer toward rackunit.

unfortunately, rackunit doesn't include "check-random" form. fortunately, it's not hard implement. here's implementation, attached code.

#lang typed/racket  ; provides check-expect , others testing (require typed/rackunit)  ;; create new prng, set seed given number, run thunk. (: run-with-seed (all (t) ((-> t) positive-integer -> t))) (define (run-with-seed thunk seed)   (parameterize ([current-pseudo-random-generator                   (make-pseudo-random-generator)])     (random-seed seed)     (thunk)))  ;; run check-equal both sides same prng seed (define-syntax check-random-equal?   (syntax-rules ()     [(_ b) (let ([seed (add1 (random (sub1 (expt 2 31))))])                (check-equal? (run-with-seed (λ () a) seed)                              (run-with-seed (λ () b) seed)))]))  (: bar (-> positive-integer integer)) (define (bar x)   (random x))  (check-random-equal? (bar 6)                      (random 6))             

i should tell several important differences between 2 testing frameworks.

  • you don't need call "(test)" @ end; tests run interleaved rest of code.
  • since tests interleaved code, must appear below of definitions required run test.
  • nothing printed when test succeeds.

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -