major refactoring. things are much simpler now
This commit is contained in:
parent
c840965893
commit
1aa5b6251a
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
lib
|
lib
|
||||||
|
.DS_Store
|
||||||
|
8
console
8
console
@ -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
|
|
@ -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))))
|
|
9
koans/about_equalities.clj
Normal file
9
koans/about_equalities.clj
Normal 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)))
|
@ -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))))
|
|
@ -1,24 +1,15 @@
|
|||||||
(load "about_asserts")
|
(ns koans.path-to-enlightenment
|
||||||
(load "about_vectors")
|
(:use clojure.test))
|
||||||
|
|
||||||
(defmacro meditate-on
|
(def __ nil)
|
||||||
"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))))
|
|
||||||
|
|
||||||
(meditate-on test-truth)
|
(defmacro meditations [& forms]
|
||||||
(meditate-on test-assert-equality)
|
(let [pairs (partition 2 forms)]
|
||||||
(meditate-on test-fill-in-values)
|
`(do
|
||||||
|
~@(doall (map
|
||||||
|
(fn [[doc# code#]]
|
||||||
|
`(when-not (is ~code# ~doc#)
|
||||||
|
(System/exit 1)))
|
||||||
|
pairs)))))
|
||||||
|
|
||||||
(meditate-on test-creating-vectors)
|
(load "about_equalities")
|
||||||
(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.")
|
|
@ -1,6 +1,6 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
CLASSPATH=koans
|
CLASSPATH=.
|
||||||
|
|
||||||
for f in lib/*.jar; do
|
for f in lib/*.jar; do
|
||||||
CLASSPATH=$CLASSPATH:$f
|
CLASSPATH=$CLASSPATH:$f
|
||||||
|
Loading…
Reference in New Issue
Block a user