Created
April 14, 2012 00:54
-
-
Save pbalduino/2381227 to your computer and use it in GitHub Desktop.
Refactoring with functional programming
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; I need to write code to make this pass: | |
; https://github.com/pbalduino/north/blob/master/test/north/test/core.clj | |
; First I wrote that | |
(defn be-true [result] | |
(assert (= result true) (format "Assertion failed. %s was expected to be true" result))) | |
; So I added be-false and slightly changed be-true | |
; Then I noticed there's duplication of code there | |
(defn be-true [result] | |
(let [expectation true] | |
(assert (= result expectation) (format "Assertion failed. %s was expected to be %s" result expectation)))) | |
(defn be-false [result] | |
(let [expectation false] | |
(assert (= result expectation) (format "Assertion failed. %s was expected to be %s" result expectation)))) | |
; Now I added be-equals and refactored the code again | |
(defn be-equals [result expectation] | |
(assert (= result expectation) (format "Assertion failed. %s was expected to be %s" result expectation))) | |
(defn be-true [result] | |
(be-equals result true)) | |
(defn be-false [result] | |
(be-equals result false)) | |
; But when I added be-not-equals I saw duplication again | |
(defn be-not-equals [result expectation] | |
(assert (not= result expectation) (format "Assertion failed. %s was expected to be %s" result expectation))) | |
(defn be-equals [result expectation] | |
(assert (= result expectation) (format "Assertion failed. %s was expected to be %s" result expectation))) | |
(defn be-true [result] | |
(be-equals result true)) | |
(defn be-false [result] | |
(be-equals result false)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment