updating the path to enlightenment, adding a repl runner, and adding

the about vectors koans.
This commit is contained in:
Aaron Bedra 2010-02-05 13:57:38 -05:00
parent 11476f961c
commit c840965893
5 changed files with 49 additions and 5 deletions

8
console Executable file
View File

@ -0,0 +1,8 @@
#!/bin/sh
CLASSPATH=src
for f in lib/*.jar; do
CLASSPATH=$CLASSPATH:$f
done
java -cp $CLASSPATH jline.ConsoleRunner clojure.main -r

28
koans/about_vectors.clj Normal file
View File

@ -0,0 +1,28 @@
(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,4 +1,5 @@
(load "about-asserts")
(load "about_asserts")
(load "about_vectors")
(defmacro meditate-on
"Runs tests but exits if an assertion fails"
@ -6,12 +7,18 @@
`(try
(~test-function)
(catch Throwable t#
(println (str (:zen (meta #'~test-function)) "\n"
(:name (meta #'~test-function))
" returned " 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)
(meditate-on test-assert-equality)
(meditate-on test-fill-in-values)
(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.")

View File

@ -1,6 +1,7 @@
(defproject functional-koans "0.0.1"
:description "The functional koans"
:dependencies [[org.clojure/clojure "1.1.0"]
[org.clojure/clojure-contrib "1.0-SNAPSHOT"]]
[org.clojure/clojure-contrib "1.0-SNAPSHOT"]
[jline "0.9.94"]]
:dev-dependencies [[lein-clojars "0.5.0-SNAPSHOT"]]
:namespaces [koans])