aboutsummaryrefslogtreecommitdiff
path: root/src/clojure/contrib/test_clojure
diff options
context:
space:
mode:
authorFrantisek Sodomka <fsodomka@gmail.com>2009-05-14 20:27:45 +0000
committerFrantisek Sodomka <fsodomka@gmail.com>2009-05-14 20:27:45 +0000
commitc78f45d08b62f9b53b1503d1e9c83e6d7adca83f (patch)
treef5f54d5c413dbd5a97ae2583bbf19ed14a087550 /src/clojure/contrib/test_clojure
parent585ef55bb7996bd86c11daad1877ef12ddb783fb (diff)
test-clojure: common helper functions in test-utils; control: do
Diffstat (limited to 'src/clojure/contrib/test_clojure')
-rw-r--r--src/clojure/contrib/test_clojure/control.clj46
-rw-r--r--src/clojure/contrib/test_clojure/logic.clj8
-rw-r--r--src/clojure/contrib/test_clojure/sequences.clj5
-rw-r--r--src/clojure/contrib/test_clojure/test_utils.clj18
4 files changed, 64 insertions, 13 deletions
diff --git a/src/clojure/contrib/test_clojure/control.clj b/src/clojure/contrib/test_clojure/control.clj
index 483250d7..134711c8 100644
--- a/src/clojure/contrib/test_clojure/control.clj
+++ b/src/clojure/contrib/test_clojure/control.clj
@@ -10,17 +10,59 @@
;;
(ns clojure.contrib.test-clojure.control
- (:use clojure.contrib.test-is))
+ (:use clojure.contrib.test-is
+ [clojure.contrib.test-clojure.test-utils :only (exception)]))
+
+;; *** Helper functions ***
+
+(defn maintains-identity [f]
+ (are (= (f _) _)
+ nil
+ false true
+ 0 42
+ 0.0 3.14
+ 2/3
+ 0M 1M
+ \c
+ "" "abc"
+ 'sym
+ :kw
+ () '(1 2)
+ [] [1 2]
+ {} {:a 1 :b 2}
+ #{} #{1 2} ))
+
; http://clojure.org/special_forms
; http://clojure.org/macros
-; do
+(deftest test-do
+ (are (= _1 _2)
+ ; no params => nil
+ (do) nil
+
+ ; return last
+ (do 1) 1
+ (do 1 2) 2
+ (do 1 2 3 4 5) 5
+
+ ; evaluate and return last
+ (let [a (atom 0)]
+ (do (reset! a (+ @a 1)) ; 1
+ (reset! a (+ @a 1)) ; 2
+ (reset! a (+ @a 1)) ; 3
+ @a)) 3 )
+
+ ; identity (= (do x) x)
+ (maintains-identity (fn [_] (do _))) )
+
+
; loop/recur
; throw, try
; [if (logic.clj)], if-not, if-let
; when, when-not, when-let, when-first
+
; cond, condp
; [for, doseq (for.clj)]
diff --git a/src/clojure/contrib/test_clojure/logic.clj b/src/clojure/contrib/test_clojure/logic.clj
index 1dba6d35..40a94c37 100644
--- a/src/clojure/contrib/test_clojure/logic.clj
+++ b/src/clojure/contrib/test_clojure/logic.clj
@@ -9,12 +9,8 @@
;; Created 1/29/2009
(ns clojure.contrib.test-clojure.logic
- (:use clojure.contrib.test-is))
-
-;; *** Helper functions ***
-
-(defn exception []
- (throw (new Exception "Exception which should never occur")))
+ (:use clojure.contrib.test-is
+ [clojure.contrib.test-clojure.test-utils :only (exception)]))
;; *** Tests ***
diff --git a/src/clojure/contrib/test_clojure/sequences.clj b/src/clojure/contrib/test_clojure/sequences.clj
index 72251295..7c2721b4 100644
--- a/src/clojure/contrib/test_clojure/sequences.clj
+++ b/src/clojure/contrib/test_clojure/sequences.clj
@@ -10,11 +10,6 @@
(ns clojure.contrib.test-clojure.sequences
(:use clojure.contrib.test-is))
-;; *** Helper functions ***
-
-(defn exception []
- (throw (new Exception "Exception which should never occur")))
-
;; *** Tests ***
diff --git a/src/clojure/contrib/test_clojure/test_utils.clj b/src/clojure/contrib/test_clojure/test_utils.clj
new file mode 100644
index 00000000..6fe22161
--- /dev/null
+++ b/src/clojure/contrib/test_clojure/test_utils.clj
@@ -0,0 +1,18 @@
+;; Copyright (c) Frantisek Sodomka. All rights reserved. The use and
+;; distribution terms for this software are covered by the Eclipse Public
+;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can
+;; be found in the file epl-v10.html at the root of this distribution. By
+;; using this software in any fashion, you are agreeing to be bound by the
+;; terms of this license. You must not remove this notice, or any other,
+;; from this software.
+
+(ns clojure.contrib.test-clojure.test-utils
+ (:use [clojure.contrib.combinatorics :only (combinations)]))
+
+
+(defn exception
+ "Use this function to ensure that execution of a program doesn't
+ reach certain point."
+ []
+ (throw (new Exception "Exception which should never occur")))
+