我正在尝试将一个项目转换成一个类型的球拍,并且由于测试引擎的原因,我在工作代码中遇到了错误。
我已经将其简化为我所能创建的最小代码片段,该代码再现了这个问题:
#lang typed/racket
; provides check-expect and others for testing
(require typed/test-engine/racket-tests)
(: bar (-> Positive-Integer Integer))
(check-random (bar 6) (random 6))
(define (bar x)
(random x))
(test)这些错误是:
. Type Checker: type mismatch
expected: Pseudo-Random-Generator
given: Any in: (check-random (bar 6) (random 6))
. Type Checker: type mismatch
expected: Positive-Integer
given: Any 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))有人对如何解决这个问题有什么建议吗?如果可能的话,我真的希望能够使用类型检查功能。
谢谢
发布于 2017-03-28 16:34:19
当然,我可以帮忙,但这在很大程度上取决于你到底想要什么,以及你要做什么。
简要概述:有多个测试框架的球拍。你使用的是为教学语言而设计的那种。它有几个不错的特性,但一般来说,rackunit是其他人使用的测试框架。
在我看来,教学语言测试框架的类型化版本不包括对检查随机的支持。我会在邮件列表上查一下这个。那样你就会转向rackunit了。
不幸的是,rackunit不包括“检查-随机”形式。幸运的是,这并不难实现。这是我的实现,附在您的代码上。
#lang typed/racket
; provides check-expect and others for testing
(require typed/rackunit)
;; create a new prng, set the seed to the given number, run the 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 a check-equal where both sides get the same PRNG seed
(define-syntax check-random-equal?
(syntax-rules ()
[(_ a 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)) 我可能应该告诉您两个测试框架之间的几个重要区别。
https://stackoverflow.com/questions/43072656
复制相似问题