views:

83

answers:

3

I have a function with a bug:

user> (-> 42 int-to-bytes bytes-to-int)
42
user> (-> 128 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?
A: 

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

Arthur Ulfeldt
Does just having a map of booleans give you an implied assertion on each member?
Greg Harman
Voted to delete my (incorrect) answer below, but I think @Arthur's comment there is a useful bit of information:the (is ..) function is the assertion.
Greg Harman
its a map of the results of evaluating the assertions. by the time the result makes it into the map it has already spit its error message to the console. then dorun discards the results of the map.
Arthur Ulfeldt
+5  A: 

dorun + map => doseq

(doseq [x (big-test-numbers)]
  (is (= x (-> x int-to-bytes bytes-to-int))))
Brian Carper
+1  A: 

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

Jouni K. Seppänen
the list has 10000 tests.
Arthur Ulfeldt