Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added test framework, fixed dumb bug in chapter 3

  • Loading branch information...
commit 19c7c5b0f1a4ed588e92eee07e766226a9773b3e 1 parent 84d29ad
@stuarthalloway authored
View
16 README
@@ -5,18 +5,30 @@ The purpose of this port is to explore the intersection between
Lisp and Clojure's signature features: access to the JVM and a
functional programming style base on immutable collections.
-
WHAT YOU SHOULD DO FIRST
------------------------
Read Practical Common Lisp. It's great. Buy a copy.
http://gigamonkeys.com/book/
-
THEN...
----------------------
Get yourself some Clojure (http://clojure.org) and take
a look at the code in this project.
+BEGGING YOUR PARDON...
+----------------------
+I wrote this code before I settled on a test framework that I would
+use for Clojure code. Such testing as there is is minimal, and has
+been added after the fact when dealing with bugs.
+
+For a more representative example of how I think Clojure code should
+be tested, check out http://github.com/stuarthalloway/clj-relevance.
+
+IF THIS WAS FUN...
+----------------------
+You might also enjoy my book, Programming Clojure:
+
+ http://www.pragprog.com/titles/shcloj/programming-clojure
LICENSES
----------------------
View
1  bin/repl.sh
@@ -0,0 +1 @@
+java -cp src:test:lib/jline-0.9.94.jar:lib/clojure.jar:lib/clojure-contrib.jar jline.ConsoleRunner clojure.main -r
View
1  bin/runtests.sh
@@ -0,0 +1 @@
+java -Xmx1G -cp test:src:lib/clojure.jar:lib/clojure-contrib.jar:lib/hsqldb.jar:lib/ant.jar:lib/ant-launcher.jar clojure.lang.Script test/test.clj
View
BIN  lib/clojure-contrib.jar
Binary file not shown
View
BIN  lib/clojure.jar
Binary file not shown
View
BIN  lib/jline-0.9.94.jar
Binary file not shown
View
14 pcl/chap_03/chap_03.clj → src/pcl/chap_03.clj
@@ -1,7 +1,5 @@
-; use namespaces
-(clojure/in-ns 'pcl.chap_03)
-(clojure/refer 'clojure)
-(use 'clojure.contrib.duck-streams)
+(ns pcl.chap-03
+ (:use clojure.contrib.duck-streams))
; struct instead of plist
(defstruct cd :title :artist :rating :ripped)
@@ -18,8 +16,8 @@
; use two doseqs (String/format not as flexible as CL format)
; better way than wrapping cd in (seq cd)?
(defn dump-db [db]
- (doseq rec db
- (doseq [key value] rec
+ (doseq [rec db]
+ (doseq [[key value] rec]
(print (format "%10s: %s\n" (name key) value)))
(println)))
@@ -58,11 +56,11 @@
cds
(recur cds))))))
-; probably a simpler, more efficient approach
+;; probably a simpler, more efficient approach
(defn save-db [db filename]
(spit
filename
- (with-out-str (print db))))
+ (pr-str db)))
(defn load-db [filename]
(with-in-str (slurp filename)
View
0  pcl/chap_05/chap_05.clj → src/pcl/chap_05.clj
File renamed without changes
View
0  pcl/chap_06/chap_06.clj → src/pcl/chap_06.clj
File renamed without changes
View
0  pcl/chap_07/chap_07.clj → src/pcl/chap_07.clj
File renamed without changes
View
0  pcl/chap_08/chap_08.clj → src/pcl/chap_08.clj
File renamed without changes
View
0  pcl/chap_09/chap_09.clj → src/pcl/chap_09.clj
File renamed without changes
View
0  pcl/chap_09b/chap_09b.clj → src/pcl/chap_09b.clj
File renamed without changes
View
0  pcl/chap_09c/chap_09c.clj → src/pcl/chap_09c.clj
File renamed without changes
View
0  pcl/chap_11/chap_11.clj → src/pcl/chap_11.clj
File renamed without changes
View
0  pcl/chap_16/chap_16.clj → src/pcl/chap_16.clj
File renamed without changes
View
0  pcl/chap_17/chap_17.clj → src/pcl/chap_17.clj
File renamed without changes
View
0  pcl/chap_23/chap_23.clj → src/pcl/chap_23.clj
File renamed without changes
View
8 test/pcl/chap_03_test.clj
@@ -0,0 +1,8 @@
+(ns pcl.chap-03-test
+ (:use clojure.test pcl.chap-03))
+
+(deftest loading-and-saving-db
+ (testing "read matches write"
+ (let [data {:a "foo"}]
+ (save-db data "test/output/test.db")
+ (is (= data (load-db "test/output/test.db"))))))
View
11 test/test.clj
@@ -0,0 +1,11 @@
+(ns test
+ (:use clojure.test))
+
+(def tests
+ ['pcl.chap-03-test])
+
+(doseq [test tests] (require test))
+
+(apply run-tests tests)
+
+(shutdown-agents)
Please sign in to comment.
Something went wrong with that request. Please try again.