From c8409658933a4fe03fdc29522e9754d561ce3562 Mon Sep 17 00:00:00 2001 From: Aaron Bedra Date: Fri, 5 Feb 2010 13:57:38 -0500 Subject: [PATCH] updating the path to enlightenment, adding a repl runner, and adding the about vectors koans. --- console | 8 ++++++ .../{about-asserts.clj => about_asserts.clj} | 0 koans/about_vectors.clj | 28 +++++++++++++++++++ koans/path_to_enlightenment.clj | 15 +++++++--- project.clj | 3 +- 5 files changed, 49 insertions(+), 5 deletions(-) create mode 100755 console rename koans/{about-asserts.clj => about_asserts.clj} (100%) create mode 100644 koans/about_vectors.clj diff --git a/console b/console new file mode 100755 index 0000000..ed73d9c --- /dev/null +++ b/console @@ -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 \ No newline at end of file diff --git a/koans/about-asserts.clj b/koans/about_asserts.clj similarity index 100% rename from koans/about-asserts.clj rename to koans/about_asserts.clj diff --git a/koans/about_vectors.clj b/koans/about_vectors.clj new file mode 100644 index 0000000..691ff79 --- /dev/null +++ b/koans/about_vectors.clj @@ -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)))) \ No newline at end of file diff --git a/koans/path_to_enlightenment.clj b/koans/path_to_enlightenment.clj index bf0e338..9228384 100644 --- a/koans/path_to_enlightenment.clj +++ b/koans/path_to_enlightenment.clj @@ -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.") diff --git a/project.clj b/project.clj index 9ededd9..c4a7634 100644 --- a/project.clj +++ b/project.clj @@ -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]) \ No newline at end of file