2. areduce
Apply an expression for each array element
user => (defn asum [numbers]
(areduce numbers i ret (float 0)
(+ ret (aget numbers i))))
user=> (asum (float-array [1 2 3]))
6
3. with-precision
Set a precision and rounding to work with point decimal values
user => (with-precision 20 (/ 1M 3))
0.33333333333333333333M
4. with-redefs
Mock temporally a value for a function or a variable. Available just in
clojure 1.3
(defn address-lookup []
(does some processing))
user> (with-redefs [address-lookup (fn [] "123 Main St.")]
(println (address-lookup)))
"123 Main St.”
nill
10. What is It?
It's an API to make your clojure tests more readable .
It's based in facts
It has a lot of functionality to create test complex test cases
11. How to Use It?
Create a new project
./cake new midje-evaluation
Copy this file to your root project folder
https://raw.github.com/marick/Midje/master/examples/cake-midje/tasks.clj
Write your tests and install the project
cake midje
12. More About Midje
About the sintax
(:use midje.sweet)
(fact
( [some function variable or object to test]) => [assertions])
(fact
(+ 1 2) => 3)
13. More about Midje
It has the Metaconstants concept.
(defn numerical-reverser [n]
(String/parseInt (string-reverser (str n))))
The function string-reverser doesn't exists. It's provided by test.
(fact
(numerical-reverser 103) => 301
(provided
(string-reverser "103") => "301"))
14. More About Midje
It has a lot of checkers
(fact #{1 2 3} => (just [odd? odd? Even?])
(fact "as" => (contains [s a] :in-any-order))
(fact "12x" => (has-prefix #"d+"))
(fact "x12" => (has-suffix #"d+"))
15. More About Midje
You can mix wih def-test functions
(:use clojure.test)
(:use midje.sweet)
(deftest a-clojure-test-test
(is (= 1 "I am a deftest expected result.")))
(fact
(+ 1 2) => 3)
16. More About Midje
It can store the function state
(fact
(function-to-test) => [6 12]
(provided
(function-to-evaluate) =streams=> [ [1 2] [5 10] ] ))