如何将测试映射到数字列表

Art*_*ldt 4 unit-testing clojure

我有一个bug的函数:

user> (-> 42 int-to-bytes bytes-to-int)
42
user> (-> 128 int-to-bytes bytes-to-int)
-128
user> 
Run Code Online (Sandbox Code Playgroud)

看起来我需要在转换回来时处理溢出...

最好写一个测试,以确保再也不会发生这种情况.这个项目使用的是clojure.contrib.test-是这样我写的:

(deftest int-to-bytes-to-int
  (let [lots-of-big-numbers (big-test-numbers)]
    (map #(is (= (-> %
                     int-to-bytes
                     bytes-to-int)
                 %))
         lots-of-big-numbers)))
Run Code Online (Sandbox Code Playgroud)

这应该是测试转换为seq的字节然后再次在10000个随机数的列表上产生原始结果.理论上看起来不错?除了没有任何测试运行.

Testing com.cryptovide.miscTest

Ran 23 tests containing 34 assertions.
0 failures, 0 errors.
Run Code Online (Sandbox Code Playgroud)
  • 为什么不进行测试?
  • 我该怎么办才能让他们跑步?

Bri*_*per 5

dorun+ map=>doseq

(doseq [x (big-test-numbers)]
  (is (= x (-> x int-to-bytes bytes-to-int))))
Run Code Online (Sandbox Code Playgroud)