Clojure Example Functions                        ilegra - LDCBy Jackson dos Santos
areduceApply an expression for each array elementuser => (defn asum [numbers]        (areduce numbers i ret (float 0)     ...
with-precisionSet a precision and rounding to work with point decimal valuesuser => (with-precision 20 (/ 1M 3))0.33333333...
with-redefsMock temporally a value for a function or a variable. Available just in  clojure 1.3(defn address-lookup [] (do...
4Clojure Problems Solved
4Clojure Problem
4Clojure Problem
4Clojure Problem
About Midje
What is It?    Its an API to make your clojure tests more readable   .    Its based in facts    It has a lot of functio...
How to Use It?   Create a new project         ./cake new midje-evaluation   Copy this file to your root project folder ...
More About MidjeAbout the sintax(:use midje.sweet)(fact ( [some function variable or object to test]) => [assertions])(fac...
More about MidjeIt has the Metaconstants concept.(defn numerical-reverser [n]  (String/parseInt (string-reverser (str n)))...
More About MidjeIt has a lot of checkers(fact #{1 2 3} => (just [odd? odd? Even?])(fact "as" => (contains [s a] :in-any-or...
More About MidjeYou can mix wih def-test functions(:use clojure.test)(:use midje.sweet)(deftest a-clojure-test-test (is (=...
More About MidjeIt can store the function state (fact  (function-to-test) => [6 12]  (provided   (function-to-evaluate) =s...
Upcoming SlideShare
Loading in …5
×

Clojure functions midje

949 views
900 views

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
949
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Clojure functions midje

  1. 1. Clojure Example Functions ilegra - LDCBy Jackson dos Santos
  2. 2. areduceApply an expression for each array elementuser => (defn asum [numbers] (areduce numbers i ret (float 0) (+ ret (aget numbers i))))user=> (asum (float-array [1 2 3]))6
  3. 3. with-precisionSet a precision and rounding to work with point decimal valuesuser => (with-precision 20 (/ 1M 3))0.33333333333333333333M
  4. 4. with-redefsMock 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
  5. 5. 4Clojure Problems Solved
  6. 6. 4Clojure Problem
  7. 7. 4Clojure Problem
  8. 8. 4Clojure Problem
  9. 9. About Midje
  10. 10. What is It? Its an API to make your clojure tests more readable . Its based in facts It has a lot of functionality to create test complex test cases
  11. 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. 12. More About MidjeAbout the sintax(:use midje.sweet)(fact ( [some function variable or object to test]) => [assertions])(fact (+ 1 2) => 3)
  13. 13. More about MidjeIt has the Metaconstants concept.(defn numerical-reverser [n] (String/parseInt (string-reverser (str n))))The function string-reverser doesnt exists. Its provided by test.(fact (numerical-reverser 103) => 301 (provided (string-reverser "103") => "301"))
  14. 14. More About MidjeIt 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. 15. More About MidjeYou 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. 16. More About MidjeIt can store the function state (fact (function-to-test) => [6 12] (provided (function-to-evaluate) =streams=> [ [1 2] [5 10] ] ))

×