开发者

How to map a test onto a list of numbers

开发者 https://www.devze.com 2022-12-30 06:21 出处:网络
I have a function with a bug: user> (-> 42 int-to-bytes bytes-to-int) 42 user> (-> 1开发者_如何学运维28 int-to-bytes bytes-to-int)

I have a function with a bug:

user> (-> 42 int-to-bytes bytes-to-int)
42
user> (-> 1开发者_如何学运维28 int-to-bytes bytes-to-int)
-128
user> 

looks like I need to handle overflow when converting back...

Better write a test to make sure this never happens again. This project is using clojure.contrib.test-is so i write:

(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)))

This should be testing converting to a seq of bytes and back again produces the origional result on a list of 10000 random numbers. Looks OK in theory? except none of the tests ever run.

Testing com.cryptovide.miscTest

Ran 23 tests containing 34 assertions.
0 failures, 0 errors.
  • why don't the tests run?
  • what can I do to make them run?


dorun + map => doseq

(doseq [x (big-test-numbers)]
  (is (= x (-> x int-to-bytes bytes-to-int))))


Avoid the need to write the map (or doseq) expression altogether by using are to write the test.


bitten by the lazy-bug again. needed a (dorun around the map :) * blush *

0

精彩评论

暂无评论...
验证码 换一张
取 消