SlideShare a Scribd company logo
Clojure Example Functions

                        ilegra - LDC
By Jackson dos Santos
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
with-precision
Set a precision and rounding to work with point decimal values


user => (with-precision 20 (/ 1M 3))
0.33333333333333333333M
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
4Clojure Problems Solved
4Clojure Problem
4Clojure Problem
4Clojure Problem
About Midje
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
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
More About Midje
About the sintax


(:use midje.sweet)


(fact
 ( [some function variable or object to test]) => [assertions])


(fact
 (+ 1 2) => 3)
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"))
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+"))
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)
More About Midje
It can store the function state
 (fact
  (function-to-test) => [6 12]
  (provided
   (function-to-evaluate) =streams=> [ [1 2] [5 10] ] ))

More Related Content

PDF
大量地区化解决方案V5
PDF
Testing in those hard to reach places
 
PDF
Useful javascript
PDF
Google App Engine Developer - Day3
PDF
Clojure functions examples
PDF
The Ring programming language version 1.3 book - Part 46 of 88
ZIP
とある断片の超動的言語
PDF
Groovy collection api
大量地区化解决方案V5
Testing in those hard to reach places
 
Useful javascript
Google App Engine Developer - Day3
Clojure functions examples
The Ring programming language version 1.3 book - Part 46 of 88
とある断片の超動的言語
Groovy collection api

What's hot (20)

PDF
はじめてのGroovy
PDF
Pymongo for the Clueless
PDF
Bindings: the zen of montage
PDF
AJUG April 2011 Raw hadoop example
PDF
Blender-like SceneView Hotkeys Unity extensions
PDF
Functions
PDF
The Ring programming language version 1.7 book - Part 71 of 196
PDF
Python For Data Science Cheat Sheet
PDF
Python 3.x Dictionaries and Sets Cheatsheet
PDF
Everything is composable
ODP
Promise
PDF
Designing Immutability Data Flows in Ember
PDF
The Ring programming language version 1.5.2 book - Part 41 of 181
PDF
PMED Undergraduate Workshop - R Tutorial for PMED Undegraduate Workshop - Xi...
PPT
Oop lecture9 13
PDF
Mozilla とブラウザゲーム
PDF
Functional Core, Reactive Shell
PDF
The Ring programming language version 1.5.1 book - Part 63 of 180
ODT
Logic Equations Resolver J Script
PDF
The Ring programming language version 1.6 book - Part 69 of 189
はじめてのGroovy
Pymongo for the Clueless
Bindings: the zen of montage
AJUG April 2011 Raw hadoop example
Blender-like SceneView Hotkeys Unity extensions
Functions
The Ring programming language version 1.7 book - Part 71 of 196
Python For Data Science Cheat Sheet
Python 3.x Dictionaries and Sets Cheatsheet
Everything is composable
Promise
Designing Immutability Data Flows in Ember
The Ring programming language version 1.5.2 book - Part 41 of 181
PMED Undergraduate Workshop - R Tutorial for PMED Undegraduate Workshop - Xi...
Oop lecture9 13
Mozilla とブラウザゲーム
Functional Core, Reactive Shell
The Ring programming language version 1.5.1 book - Part 63 of 180
Logic Equations Resolver J Script
The Ring programming language version 1.6 book - Part 69 of 189
Ad

Viewers also liked (8)

PPT
Presentation about ClosureScript fraemework
PPSX
Jboss AS7 New Main Features
PDF
Introduction to HashiCorp Consul
Presentation about ClosureScript fraemework
Jboss AS7 New Main Features
Introduction to HashiCorp Consul
Ad

Similar to Clojure functions midje (20)

PDF
Clojure - A new Lisp
PDF
Learn a language : LISP
PPTX
Schema, validation and generative testing
ODP
Clojure made simple - Lightning talk
KEY
(map Clojure everyday-tasks)
PDF
Clojure class
PDF
Clojure functions
PDF
Pune Clojure Course Outline
PDF
Predictably
PDF
Continuation Passing Style and Macros in Clojure - Jan 2012
ODP
Clojure made really really simple
PDF
Practical REPL-driven Development with Clojure
PDF
Clojure and Modularity
PDF
Clojure Interoperability
PDF
Exploring Clojurescript
PDF
QuickCheck - Software Testing
ODP
Clojure: Practical functional approach on JVM
PDF
Brief intro to clojure
PPT
PDF
Scala by Luc Duponcheel
Clojure - A new Lisp
Learn a language : LISP
Schema, validation and generative testing
Clojure made simple - Lightning talk
(map Clojure everyday-tasks)
Clojure class
Clojure functions
Pune Clojure Course Outline
Predictably
Continuation Passing Style and Macros in Clojure - Jan 2012
Clojure made really really simple
Practical REPL-driven Development with Clojure
Clojure and Modularity
Clojure Interoperability
Exploring Clojurescript
QuickCheck - Software Testing
Clojure: Practical functional approach on JVM
Brief intro to clojure
Scala by Luc Duponcheel

More from Jackson dos Santos Olveira (20)

PDF
AWS Control Tower
PDF
PDF
An introduction to predictionIO
PDF
Apache mahout - introduction
PDF
Managing computational resources with Apache Mesos
PDF
Introduction to CFEngine
PDF
PDF
Jboss Teiid - The data you have on the place you need
PDF
Apache PIG introduction
PPSX
Celery Introduction
PPT
Elastic search introduction
PDF
Clojure functions 4
PDF
Jython Presentation
PDF
Clojure functions 3
PDF
Google application engine
PPT
Google application engine
AWS Control Tower
An introduction to predictionIO
Apache mahout - introduction
Managing computational resources with Apache Mesos
Introduction to CFEngine
Jboss Teiid - The data you have on the place you need
Apache PIG introduction
Celery Introduction
Elastic search introduction
Clojure functions 4
Jython Presentation
Clojure functions 3
Google application engine
Google application engine

Recently uploaded (20)

PPTX
A Presentation on Artificial Intelligence
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
cuic standard and advanced reporting.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Machine learning based COVID-19 study performance prediction
PDF
Encapsulation theory and applications.pdf
A Presentation on Artificial Intelligence
“AI and Expert System Decision Support & Business Intelligence Systems”
cuic standard and advanced reporting.pdf
20250228 LYD VKU AI Blended-Learning.pptx
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Advanced methodologies resolving dimensionality complications for autism neur...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
NewMind AI Weekly Chronicles - August'25-Week II
Per capita expenditure prediction using model stacking based on satellite ima...
Unlocking AI with Model Context Protocol (MCP)
MYSQL Presentation for SQL database connectivity
Programs and apps: productivity, graphics, security and other tools
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Mobile App Security Testing_ A Comprehensive Guide.pdf
sap open course for s4hana steps from ECC to s4
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Machine learning based COVID-19 study performance prediction
Encapsulation theory and applications.pdf

Clojure functions midje

  • 1. Clojure Example Functions ilegra - LDC By Jackson dos Santos
  • 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] ] ))