Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed tutorial appropriately

  • Loading branch information...
commit 58421d4876d1b3566ae8f3b3e0fff7b0b4a80881 1 parent 6f95e91
Dmitri Naumov authored April 14, 2012

Showing 1 changed file with 15 additions and 15 deletions. Show diff stats Hide diff stats

  1. 30  test/contracts/test/tutorial.clj
30  test/contracts/test/tutorial.clj
... ...
@@ -1,6 +1,6 @@
1  
-;; This tutorial will give you a brief introduction to contract
2  
-;; programming and an overview of the clojure-contracts
3  
-;; facilities. It's better if you'd start a REPL and follow along.
  1
+;; This tutorial gives you a brief introduction to contract
  2
+;; programming with clojure-contracts. It's better if you'd start a
  3
+;; REPL and follow along.
4 4
 
5 5
 
6 6
 ;;; # Contract programming
@@ -72,7 +72,7 @@
72 72
   (constrained-inc 1) => 2
73 73
   (inc nil) => (throws NullPointerException)
74 74
   (constrained-inc nil) => (throws AssertionError
75  
-                                   #"Expecting: number?"
  75
+                                   #"Expecting: <first arg> is: number?"
76 76
                                    #"Given: nil"))
77 77
 
78 78
 ;; Here, `fact` is the Midje's macro which groups together a bunch of
@@ -95,7 +95,7 @@
95 95
     (+ "1" 2) => (throws ClassCastException
96 96
                          "java.lang.String cannot be cast to java.lang.Number")
97 97
     (constrained-plus "1" 2) => (throws AssertionError
98  
-                                        #"Expecting: number?"
  98
+                                        #"Expecting: <first arg> is: number?"
99 99
                                         #"Given: \"1\"")))
100 100
 
101 101
 ;; Notice that double opening parens - we created anonymous contract
@@ -132,8 +132,8 @@
132 132
 
133 133
 (fact "What a shame!"
134 134
   (factorial 1) => (throws AssertionError
135  
-                           #"Postcondition failed for var #'contracts.test.tutorial/factorial"
136  
-                           #"Expecting: pos?"
  135
+                           #"Postcondition failed for #'contracts.test.tutorial/factorial"
  136
+                           #"Expecting: <result> is: pos?"
137 137
                            #"Given: 0"))
138 138
 
139 139
 ;; Oops! Contract system complains that function have violated its
@@ -151,7 +151,7 @@
151 151
   (factorial 1) => 1
152 152
   (factorial 0) => 1
153 153
   (factorial -1) => (throws AssertionError
154  
-                            #"Expecting: \(c/not neg\?\)"
  154
+                            #"Expecting: <first arg> is: \(c/not neg\?\)"
155 155
                             #"Given: -1"))
156 156
 
157 157
 ;; *Morale*:
@@ -203,12 +203,12 @@
203 203
 (fact
204 204
   (sum [1 2 3]) => 6
205 205
   (sum [1 2 :boom]) => (throws AssertionError
206  
-                               #"Precondition failed for var #'contracts.test.tutorial/sum"
207  
-                               #"Expecting: \(c/coll-of number\?\)"
  206
+                               #"Precondition failed for #'contracts.test.tutorial/sum"
  207
+                               #"Expecting: <first arg> is: \(c/coll-of number\?\)"
208 208
                                #"Given: \[1 2 :boom\]")
209 209
   (sum inc [1 2 3]) => 9
210 210
   (sum 1 [2 3]) => (throws AssertionError
211  
-                           #"Expecting: fn\?"
  211
+                           #"Expecting: <first arg> is: fn\?"
212 212
                            #"Given: 1"))
213 213
 
214 214
 ;; Seems fine... but is it so? Consider the following code:
@@ -250,7 +250,7 @@
250 250
 (fact "Functional nirvana."
251 251
   (sum str [4 8 15 16 23 42]) => (throws AssertionError
252 252
                                          #"Postcondition failed"
253  
-                                         #"Expecting: number\?"
  253
+                                         #"Expecting: <result> is: number\?"
254 254
                                          #"Given: \"4\""))
255 255
 
256 256
 ;; That's much clearer: contract system tells the caller that his
@@ -305,7 +305,7 @@
305 305
 (fact
306 306
   (harmonic-mean 10 30) => 15
307 307
   (harmonic-mean 10 -10) => (throws AssertionError
308  
-                                    #"Expecting: \(c/not zero\?\)"
  308
+                                    #"Expecting: \(\+ x y\) is: \(c/not zero\?\)"
309 309
                                     #"Given: 0"))
310 310
 
311 311
 ;; One thing to note is that arguments' names in contract don't have
@@ -325,7 +325,7 @@
325 325
                               hash-map)]
326 326
     (constrained-hash-map :a 1 :b 2) => {:a 1 :b 2}
327 327
     (constrained-hash-map :a 1 :boo) => (throws AssertionError
328  
-                                                #"Expecting: \(comp even\? count\)"
  328
+                                                #"Expecting: keys\+vals is: \(comp even\? count\)"
329 329
                                                 #"Given: \(:a 1 :boo\)")))
330 330
 
331 331
 
@@ -373,7 +373,7 @@
373 373
   (arithmetic-mean 8 2) => 5
374 374
   (Math/sqrt (* 8 2)) => 4.0
375 375
   (arithmetic-mean -1 -2) => (throws AssertionError
376  
-                                     #"Expecting:"
  376
+                                     #"Expecting: x is:"
377 377
                                      #"\(c/and number\? \(c/not neg\?\)\)"
378 378
                                      #"Given: -1"))
379 379
 

0 notes on commit 58421d4

Please sign in to comment.
Something went wrong with that request. Please try again.