Hello, I have suggestion about clojure.contrib.test-is.

It is useful and sometimes necessary to generate testing data.
Currently, data can be generated by a piece of code and passed to an
'is' function. For example, I want to test for equality of many
things, to see if each is equal to each:

(use 'clojure.contrib.combinatorics)
(use 'clojure.contrib.test-is)

(deftest each-is-equal-to-each
  (let [data [0 0.0 0M]
        test-data (combinations data 2)]
    (doseq [td test-data]
      (is (apply = td)))))

Now, I can easily extend 'data' to do more tests (e.g. byte 0, float
0, ...). This will work, but it is not as readable as I would like it
to be.

Another approach would be to allow 'are' macro to accept generated
testing data:

user=> (combinations [0 0.0 0M] 2)
((0 0.0) (0 0M) (0.0 0M))
user=> (apply concat (combinations [0 0.0 0M] 2))
(0 0.0 0 0M 0.0 0M)

(are (= _1 _2)
  (apply concat (combinations [0 0.0 0M] 2)))


Older style of tests could be then rewritten as:

(are (= _1 _2)
  3 (+ 1 2)
  0 (+ -1 1))

becomes

(are (= _1 _2)
  (list
    3 (+ 1 2)
    0 (+ -1 1)))

or nicer:

(are (= _1 _2)
  [3 (+ 1 2)
   0 (+ -1 1)])

Comments welcome, Frantisek
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to