From 1aa5b6251a2b2c552d1f0a57a88dbd073afc7a9b Mon Sep 17 00:00:00 2001 From: Aaron Bedra Date: Sat, 6 Feb 2010 11:49:53 -0500 Subject: [PATCH] major refactoring. things are much simpler now --- .gitignore | 3 ++- console | 8 -------- koans/about_asserts.clj | 18 ------------------ koans/about_equalities.clj | 9 +++++++++ koans/about_vectors.clj | 28 ---------------------------- koans/path_to_enlightenment.clj | 33 ++++++++++++--------------------- path_to_enlightenment | 2 +- 7 files changed, 24 insertions(+), 77 deletions(-) delete mode 100755 console delete mode 100644 koans/about_asserts.clj create mode 100644 koans/about_equalities.clj delete mode 100644 koans/about_vectors.clj diff --git a/.gitignore b/.gitignore index 7951405..439c43a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -lib \ No newline at end of file +lib +.DS_Store diff --git a/console b/console deleted file mode 100755 index ed73d9c..0000000 --- a/console +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -CLASSPATH=src - -for f in lib/*.jar; do - CLASSPATH=$CLASSPATH:$f -done - -java -cp $CLASSPATH jline.ConsoleRunner clojure.main -r \ No newline at end of file diff --git a/koans/about_asserts.clj b/koans/about_asserts.clj deleted file mode 100644 index 718af9f..0000000 --- a/koans/about_asserts.clj +++ /dev/null @@ -1,18 +0,0 @@ -(def __ nil) - -(defn #^{:zen "We shall contemplate truth by testing reality, via asserts."} - test-truth - [] - (assert false)) ;; This should be true - -(defn #^{:zen "To understand reality, we must compare our expectations against reality."} - test-assert-equality - [] - (let [expected-value 0 - actual-value (+ 1 1)] - (assert (= expected-value actual-value)))) - -(defn #^{:zen "Sometimes we will ask you to fill in the values"} - test-fill-in-values - [] - (assert (= __ (+ 1 1)))) \ No newline at end of file diff --git a/koans/about_equalities.clj b/koans/about_equalities.clj new file mode 100644 index 0000000..fb38a63 --- /dev/null +++ b/koans/about_equalities.clj @@ -0,0 +1,9 @@ +(meditations + "We shall contemplate truth by testing reality, via equality." + (= true false) + + "To understand reality, we must compare our expectations against reality." + (= 0 (+ 1 1)) + + "Sometimes we will ask you to fill in the values" + (= __ (+ 1 1))) \ No newline at end of file diff --git a/koans/about_vectors.clj b/koans/about_vectors.clj deleted file mode 100644 index 691ff79..0000000 --- a/koans/about_vectors.clj +++ /dev/null @@ -1,28 +0,0 @@ -(def __ nil) - -(defn test-creating-vectors [] - (let [empty-vector (vec nil)] - (assert (= clojure.lang.PersistentVector (class empty-vector))) - (assert (= __ (.size empty-vector))))) - -(defn test-vector-literals [] - (let [vector (vec nil)] - (assert (= [] vector))) - (let [vector (vec '(1))] - (assert (= [1] vector))) - (let [vector (vec '(1 2))] - (assert (= [1 __] vector))) - (let [vector (vec nil)] - (assert (= __ (conj vector 333))))) - -(defn test-accessing-vector-elements [] - (let [vector [:peanut, :butter, :and, :jelly]] - (assert (= __ (nth vector 0))) - (assert (= __ (first vector))) - (assert (= __ (nth vector 3))) - (assert (= __ (last vector))))) - -(defn test-vectors-and-ranges [] - (assert (not (= [1 2 3 4 5] (range 1 5)))) - (assert (= [1 2 3 4] (range 1 5))) - (assert (= __ (range 5 10)))) \ No newline at end of file diff --git a/koans/path_to_enlightenment.clj b/koans/path_to_enlightenment.clj index 9228384..9be1872 100644 --- a/koans/path_to_enlightenment.clj +++ b/koans/path_to_enlightenment.clj @@ -1,24 +1,15 @@ -(load "about_asserts") -(load "about_vectors") +(ns koans.path-to-enlightenment + (:use clojure.test)) -(defmacro meditate-on - "Runs tests but exits if an assertion fails" - [test-function] - `(try - (~test-function) - (catch Throwable t# - (println (str "\n\"" (:zen (meta #'~test-function)) "\"\n" - "[FAILURE] - "(:name (meta #'~test-function)) - " failed\n" t# "\n")) - (System/exit 1)))) +(def __ nil) -(meditate-on test-truth) -(meditate-on test-assert-equality) -(meditate-on test-fill-in-values) +(defmacro meditations [& forms] + (let [pairs (partition 2 forms)] + `(do + ~@(doall (map + (fn [[doc# code#]] + `(when-not (is ~code# ~doc#) + (System/exit 1))) + pairs))))) -(meditate-on test-creating-vectors) -(meditate-on test-vector-literals) -(meditate-on test-accessing-vector-elements) -(meditate-on test-vectors-and-ranges) - -(println "You have achieved clojure zen. Go out into the universe and spread your newfound knowledge.") +(load "about_equalities") \ No newline at end of file diff --git a/path_to_enlightenment b/path_to_enlightenment index e7c5a1a..dfba636 100755 --- a/path_to_enlightenment +++ b/path_to_enlightenment @@ -1,6 +1,6 @@ #!/bin/sh -CLASSPATH=koans +CLASSPATH=. for f in lib/*.jar; do CLASSPATH=$CLASSPATH:$f