Created
January 10, 2014 14:06
-
-
Save thegeez/8352754 to your computer and use it in GitHub Desktop.
4clojure in an editor
This file contains 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
;; 1. Common test utility | |
(require '[clojure.walk :as walk]) | |
(defmacro to-test [name & source] | |
`(defn ~(symbol (str name "-test")) [] ~@(for [case (filter list? source)] | |
`(assert ~(walk/postwalk-replace {'__ name} case))))) | |
;; 2. for each problem I write: | |
(def pNN | |
(fn ...solution here...)) | |
;; 3. type (to-test solution-fn-name ) | |
;; 4. copy paste the problem test cases from 4clojure into the to-test | |
;; form (the text will include "test not run") | |
;; example problem 21: | |
(to-test pNN | |
(= (__ 2 [1 2 3 4 5]) '(3 4 5 1 2)) | |
test not run | |
(= (__ -2 [1 2 3 4 5]) '(4 5 1 2 3)) | |
test not run | |
(= (__ 6 [1 2 3 4 5]) '(2 3 4 5 1)) | |
test not run | |
(= (__ 1 '(:a :b :c)) '(:b :c :a)) | |
test not run | |
(= (__ -4 '(:a :b :c)) '(:c :a :b)) | |
) | |
;; 5. run (pNN-test) to run all the created assertions of the test | |
;; case | |
;; 6. edit pNN and test again | |
;; 7. (pNN-test) returns nil for succes! | |
;; 8. copy the (fn ...) body from pNN into 4clojure |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment