major refactoring. things are much simpler now

This commit is contained in:
Aaron Bedra 2010-02-06 11:49:53 -05:00
parent c840965893
commit 1aa5b6251a
7 changed files with 24 additions and 77 deletions

3
.gitignore vendored
View File

@ -1 +1,2 @@
lib
lib
.DS_Store

View File

@ -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

View File

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

View File

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

View File

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

View File

@ -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")

View File

@ -1,6 +1,6 @@
#!/bin/sh
CLASSPATH=koans
CLASSPATH=.
for f in lib/*.jar; do
CLASSPATH=$CLASSPATH:$f