SlideShare una empresa de Scribd logo
1 de 16
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] ] ))

Más contenido relacionado

La actualidad más candente

Bindings: the zen of montage
Bindings: the zen of montageBindings: the zen of montage
Bindings: the zen of montage
Kris Kowal
 
Logic Equations Resolver J Script
Logic Equations Resolver   J ScriptLogic Equations Resolver   J Script
Logic Equations Resolver J Script
Roman Agaev
 

La actualidad más candente (20)

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

Destacado (8)

Aurinko
AurinkoAurinko
Aurinko
 
Haskell
HaskellHaskell
Haskell
 
Gcontract
GcontractGcontract
Gcontract
 
Presentation about ClosureScript fraemework
Presentation about ClosureScript fraemeworkPresentation about ClosureScript fraemework
Presentation about ClosureScript fraemework
 
Jboss AS7 New Main Features
Jboss AS7 New Main FeaturesJboss AS7 New Main Features
Jboss AS7 New Main Features
 
Ocaml
OcamlOcaml
Ocaml
 
Introduction to HashiCorp Consul
Introduction to HashiCorp ConsulIntroduction to HashiCorp Consul
Introduction to HashiCorp Consul
 
Ocaml
OcamlOcaml
Ocaml
 

Similar a Clojure functions midje

Parallel R in snow (english after 2nd slide)
Parallel R in snow (english after 2nd slide)Parallel R in snow (english after 2nd slide)
Parallel R in snow (english after 2nd slide)
Cdiscount
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
Dmitry Buzdin
 
Clojure in the Wild
Clojure in the WildClojure in the Wild
Clojure in the Wild
suitzero
 

Similar a Clojure functions midje (20)

Basic R Data Manipulation
Basic R Data ManipulationBasic R Data Manipulation
Basic R Data Manipulation
 
Clojure basics
Clojure basicsClojure basics
Clojure basics
 
[1062BPY12001] Data analysis with R / week 2
[1062BPY12001] Data analysis with R / week 2[1062BPY12001] Data analysis with R / week 2
[1062BPY12001] Data analysis with R / week 2
 
Very basic functional design patterns
Very basic functional design patternsVery basic functional design patterns
Very basic functional design patterns
 
Parallel R in snow (english after 2nd slide)
Parallel R in snow (english after 2nd slide)Parallel R in snow (english after 2nd slide)
Parallel R in snow (english after 2nd slide)
 
Coding in Style
Coding in StyleCoding in Style
Coding in Style
 
Vectors data frames
Vectors data framesVectors data frames
Vectors data frames
 
The Ring programming language version 1.10 book - Part 94 of 212
The Ring programming language version 1.10 book - Part 94 of 212The Ring programming language version 1.10 book - Part 94 of 212
The Ring programming language version 1.10 book - Part 94 of 212
 
NPTEL QUIZ.docx
NPTEL QUIZ.docxNPTEL QUIZ.docx
NPTEL QUIZ.docx
 
Clojure for Data Science
Clojure for Data ScienceClojure for Data Science
Clojure for Data Science
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
Day 1c access, select ordering copy.pptx
Day 1c   access, select   ordering copy.pptxDay 1c   access, select   ordering copy.pptx
Day 1c access, select ordering copy.pptx
 
Clojure in the Wild
Clojure in the WildClojure in the Wild
Clojure in the Wild
 
Python testing using mock and pytest
Python testing using mock and pytestPython testing using mock and pytest
Python testing using mock and pytest
 
6. R data structures
6. R data structures6. R data structures
6. R data structures
 
Clojure And Swing
Clojure And SwingClojure And Swing
Clojure And Swing
 
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...Optimization and Mathematical Programming in R and ROI - R Optimization Infra...
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...
 
Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side Javascript
 
Xgboost
XgboostXgboost
Xgboost
 
Python testing
Python  testingPython  testing
Python testing
 

Más de Jackson dos Santos Olveira

Más de Jackson dos Santos Olveira (20)

AWS Control Tower
AWS Control TowerAWS Control Tower
AWS Control Tower
 
Netty training
Netty trainingNetty training
Netty training
 
An introduction to predictionIO
An introduction to predictionIOAn introduction to predictionIO
An introduction to predictionIO
 
Apache mahout - introduction
Apache mahout - introductionApache mahout - introduction
Apache mahout - introduction
 
Managing computational resources with Apache Mesos
Managing computational resources with Apache MesosManaging computational resources with Apache Mesos
Managing computational resources with Apache Mesos
 
Introduction to CFEngine
Introduction to CFEngineIntroduction to CFEngine
Introduction to CFEngine
 
DBC Principles
DBC PrinciplesDBC Principles
DBC Principles
 
Racket
RacketRacket
Racket
 
Jboss Teiid - The data you have on the place you need
Jboss Teiid - The data you have on the place you needJboss Teiid - The data you have on the place you need
Jboss Teiid - The data you have on the place you need
 
Apache PIG introduction
Apache PIG introductionApache PIG introduction
Apache PIG introduction
 
Celery Introduction
Celery IntroductionCelery Introduction
Celery Introduction
 
Solid
SolidSolid
Solid
 
Elastic search introduction
Elastic search introductionElastic search introduction
Elastic search introduction
 
Android
AndroidAndroid
Android
 
Clojure functions 4
Clojure functions 4Clojure functions 4
Clojure functions 4
 
Jython Presentation
Jython PresentationJython Presentation
Jython Presentation
 
Clojure functions 3
Clojure functions 3Clojure functions 3
Clojure functions 3
 
Clojure functions
Clojure functionsClojure functions
Clojure functions
 
Prototype js
Prototype jsPrototype js
Prototype js
 
Google application engine
Google application engineGoogle application engine
Google application engine
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 

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] ] ))