Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

base test for contract

  • Loading branch information...
commit 9b4725a41045814c6e4d6f73ef71c02948fc1aea 1 parent 64dfa8b
@fogus fogus authored
View
25 src/main/clojure/clojure/core/contracts.clj
@@ -38,28 +38,3 @@
(list `alter-var-root (list `var n#)
(list `fn '[f c] (list `with-constraints 'f 'c)) c#))
nil)))
-
-(comment
- (def doubler-contract
- (contract doubler
- "ensures dublig"
- [x] [number? => (= (* 2 x) %)]
-
- [x y] [(every? number? [x y])
- =>
- (= (* 2 (+ x y)) %)]))
-
- (def x2 (fn f
- ([n] (* 2 n))
- ([n x] (+ (f n) (f x)))))
-
- (def doubler (partial doubler-contract x2))
-
- (doubler 2)
- (doubler 2 3)
-
- (def bad-doubler (partial doubler-contract (comp dec x2)))
-
- (bad-doubler 2)
- (bad-doubler 2 3)
-)
View
38 src/test/clojure/clojure/core/contracts_tests.clj
@@ -1,13 +1,37 @@
(ns clojure.core.contracts-tests
- (:use [clojure.core.contracts :only (contract)]
+ (:use [clojure.core.contracts :only (contract with-constraints provide)]
[clojure.test :only [deftest is]]
clojure.core.contracts.impl.transformers))
-(defn defer []
- (is (nil? (println "DEFERING TEST!!!"))))
+(defn defer [desc]
+ (is (nil? (println (str "DEFERING TEST: " desc)))))
-(deftest contracts
- (defer))
-(deftest regressions
- (defer))
+(deftest test-simple-contract
+ (let [doubler-contract (contract doubler
+ "ensures dublig"
+ [x] [number? => (= (* 2 x) %)]
+ [x y] [(every? number? [x y])
+ =>
+ (= (* 2 (+ x y)) %)])
+
+ x2 (fn f
+ ([n] (* 2 n))
+ ([n x] (+ (f n) (f x))))
+
+ good-doubler (partial doubler-contract x2)
+ bad-doubler (partial doubler-contract (comp dec x2))]
+
+ (is (= 4 (good-doubler 2)))
+ (is (= 10 (good-doubler 2 3)))
+ (is (thrown? AssertionError (bad-doubler 2)))
+ (is (thrown? AssertionError (bad-doubler 2 3)))))
+
+(deftest test-with-constraints
+ (defer "with-constraints"))
+
+(deftest test-provide
+ (defer "provide"))
+
+(deftest test-regressions
+ (defer "regression testing"))
Please sign in to comment.
Something went wrong with that request. Please try again.