updating the path to enlightenment, adding a repl runner, and adding
the about vectors koans.
This commit is contained in:
parent
11476f961c
commit
c840965893
8
console
Executable file
8
console
Executable 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
28
koans/about_vectors.clj
Normal 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))))
|
@ -1,4 +1,5 @@
|
|||||||
(load "about-asserts")
|
(load "about_asserts")
|
||||||
|
(load "about_vectors")
|
||||||
|
|
||||||
(defmacro meditate-on
|
(defmacro meditate-on
|
||||||
"Runs tests but exits if an assertion fails"
|
"Runs tests but exits if an assertion fails"
|
||||||
@ -6,12 +7,18 @@
|
|||||||
`(try
|
`(try
|
||||||
(~test-function)
|
(~test-function)
|
||||||
(catch Throwable t#
|
(catch Throwable t#
|
||||||
(println (str (:zen (meta #'~test-function)) "\n"
|
(println (str "\n\"" (:zen (meta #'~test-function)) "\"\n"
|
||||||
(:name (meta #'~test-function))
|
"[FAILURE] - "(:name (meta #'~test-function))
|
||||||
" returned " t#))
|
" failed\n" t# "\n"))
|
||||||
(System/exit 1))))
|
(System/exit 1))))
|
||||||
|
|
||||||
(meditate-on test-truth)
|
(meditate-on test-truth)
|
||||||
(meditate-on test-assert-equality)
|
(meditate-on test-assert-equality)
|
||||||
(meditate-on test-fill-in-values)
|
(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.")
|
(println "You have achieved clojure zen. Go out into the universe and spread your newfound knowledge.")
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
(defproject functional-koans "0.0.1"
|
(defproject functional-koans "0.0.1"
|
||||||
:description "The functional koans"
|
:description "The functional koans"
|
||||||
:dependencies [[org.clojure/clojure "1.1.0"]
|
: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"]]
|
:dev-dependencies [[lein-clojars "0.5.0-SNAPSHOT"]]
|
||||||
:namespaces [koans])
|
:namespaces [koans])
|
Loading…
Reference in New Issue
Block a user