2
2
(:use structured-data
3
3
midje.sweet))
4
4
5
- (facts " do-a-thing"
5
+ (facts " 1 do-a-thing"
6
6
(do-a-thing 3 ) => 46656.0
7
7
(do-a-thing 1 ) => 4.0
8
8
(do-a-thing 0 ) => 1.0 )
9
9
10
- (facts " spiff"
10
+ (facts " 2 spiff"
11
11
(spiff [1 2 3 ]) => 4
12
12
(spiff [1 2 -34 4 5 6 ]) => -33 )
13
13
14
- (facts " cutify"
14
+ (facts " 3 cutify"
15
15
(cutify []) => [" <3" ]
16
16
(cutify [1 2 3 ]) => [1 2 3 " <3" ]
17
17
(cutify [" a" " b" ]) => [" a" " b" " <3" ])
18
18
19
- (facts " spiff-destructuring"
19
+ (facts " 4 spiff-destructuring"
20
20
(spiff-destructuring [1 2 3 ]) => 4
21
21
(spiff-destructuring [1 2 -34 4 5 6 ]) => -33 )
22
22
23
- (facts " width"
23
+ (facts " 5 width"
24
24
(width (rectangle [1 1 ] [5 1 ])) => 4
25
25
(width (rectangle [1 1 ] [1 1 ])) => 0
26
26
(width (rectangle [3 1 ] [10 4 ])) => 7 )
27
27
28
- (facts " height"
28
+ (facts " 5 height"
29
29
(height (rectangle [1 1 ] [5 1 ])) => 0
30
30
(height (rectangle [1 1 ] [5 5 ])) => 4
31
31
(height (rectangle [0 0 ] [2 3 ])) => 3 )
32
32
33
- (facts " square?"
33
+ (facts " 6 square?"
34
34
(square? (rectangle [1 1 ] [2 2 ])) => true
35
35
(square? (rectangle [1 1 ] [2 3 ])) => false
36
36
(square? (rectangle [1 1 ] [1 1 ])) => true
37
37
(square? (rectangle [3 2 ] [1 0 ])) => true
38
38
(square? (rectangle [3 2 ] [1 1 ])) => false )
39
39
40
- (facts " area"
40
+ (facts " 7 area"
41
41
(area (rectangle [1 1 ] [5 1 ])) => 0
42
42
(area (rectangle [0 0 ] [1 1 ])) => 1
43
43
(area (rectangle [0 0 ] [4 3 ])) => 12
44
44
(area (rectangle [3 1 ] [10 4 ])) => 21 )
45
45
46
- (facts " contains-point?"
46
+ (facts " 8 contains-point?"
47
47
(contains-point? (rectangle [0 0 ] [2 2 ])
48
48
(point 1 1 )) => true
49
49
(contains-point? (rectangle [0 0 ] [2 2 ])
57
57
(contains-point? (rectangle [1 1 ] [1 1 ])
58
58
(point 1 1 )) => true )
59
59
60
- (facts " contains-rectangle?"
60
+ (facts " 9 contains-rectangle?"
61
61
(contains-rectangle? (rectangle [0 0 ] [3 3 ])
62
62
(rectangle [1 1 ] [2 2 ])) => true
63
63
(contains-rectangle? (rectangle [0 0 ] [2 2 ])
95
95
:authors [friedman, felleisen]}
96
96
books [cities, wild-seed, embassytown, little-schemer]]
97
97
98
- (facts " title-length"
98
+ (facts " 10 title-length"
99
99
(title-length cities) => 21
100
100
(title-length wild-seed) => 9
101
101
(title-length little-schemer) => 18 )
102
102
103
- (facts " author-count"
103
+ (facts " 11 author-count"
104
104
(author-count cities) => 1
105
105
(author-count wild-seed) => 1
106
106
(author-count little-schemer) => 2 )
107
107
108
- (facts " multiple-authors?"
108
+ (facts " 12 multiple-authors?"
109
109
(multiple-authors? cities) => false
110
110
(multiple-authors? wild-seed) => false
111
111
(multiple-authors? little-schemer) => true )
112
112
113
- (facts " add-author"
113
+ (facts " 13 add-author"
114
114
(add-author little-schemer {:name " Gerald J. Sussman" })
115
115
=> {:title " The Little Schemer"
116
116
:authors [{:birth-year 1944 , :name " Daniel Friedman" }
119
119
(add-author {:authors [{:name " Juhana" }]} {:name " Jani" })
120
120
=> {:authors [{:name " Juhana" } {:name " Jani" }]})
121
121
122
- (facts " alive?"
122
+ (facts " 14 alive?"
123
123
(alive? china) => true
124
124
(alive? octavia) => false )
125
125
126
- (facts " element-lengths"
126
+ (facts " 15 element-lengths"
127
127
(element-lengths [" foo" " bar" " " " quux" ]) => [3 3 0 4 ]
128
128
(element-lengths [" x" [:a :b :c ] {:y 42 }]) => [1 3 1 ])
129
129
130
- (facts " second-elements"
130
+ (facts " 16 second-elements"
131
131
(second-elements [[1 2 ] [2 3 ] [3 4 ]]) => [2 3 4 ]
132
132
(second-elements [[1 2 3 4 ] [1 ] [" a" " s" " d" " f" ]]) => [2 nil " s" ])
133
133
134
- (facts " titles"
134
+ (facts " 17 titles"
135
135
(titles [cities]) => [" The City and the City" ]
136
136
(titles books) => (just [" The City and the City"
137
137
" Wild Seed"
138
138
" Embassytown"
139
139
" The Little Schemer" ]
140
140
:in-any-order )))
141
141
142
- (facts " monotonic?"
142
+ (facts " 18 stars"
143
+ (stars 1 ) => " *"
144
+ (stars 7 ) => " *******"
145
+ (stars 3 ) => " ***" )
146
+
147
+ (facts " 19 monotonic?"
143
148
(monotonic? [1 2 3 ]) => true
144
149
(monotonic? [0 1 10 11 ]) => true
145
150
(monotonic? [3 2 0 -3 ]) => true
146
151
(monotonic? [3 2 2 ]) => true
147
152
(monotonic? [1 2 1 0 ]) => false )
148
153
149
- (facts " stars"
150
- (stars 1 ) => " *"
151
- (stars 7 ) => " *******"
152
- (stars 3 ) => " ***" )
153
-
154
- (facts " toggle"
154
+ (facts " 20 toggle"
155
155
(toggle #{:a :b :c } :d ) => #{:a :b :c :d }
156
156
(toggle #{:a :b :c } :a ) => #{:b :c })
157
157
158
- (facts " contains-duplicates?"
158
+ (facts " 21 contains-duplicates?"
159
159
(contains-duplicates? [1 1 2 3 -40 ]) => true
160
160
(contains-duplicates? [1 2 3 -40 ]) => false
161
161
(contains-duplicates? [1 2 3 " a" " a" ]) => true )
162
162
163
- (facts " old-book->new-book"
163
+ (facts " 22 old-book->new-book"
164
164
(old-book->new-book {:title " The Little Schemer"
165
165
:authors [friedman, felleisen]})
166
166
=> {:title " The Little Schemer" :authors #{friedman, felleisen}}
193
193
194
194
books [cities, wild-seed, embassytown, little-schemer]]
195
195
196
- (facts " has-author?"
196
+ (facts " 23 has-author?"
197
197
(has-author? cities china) => true
198
198
(has-author? cities felleisen) => false
199
199
(has-author? little-schemer felleisen) => true
200
200
(has-author? little-schemer friedman) => true
201
201
(has-author? little-schemer octavia) => false )
202
202
203
- (facts " authors"
203
+ (facts " 24 authors"
204
204
(authors [cities, wild-seed]) => #{china, octavia}
205
205
(authors [cities, wild-seed, embassytown]) => #{china, octavia}
206
206
(authors [little-schemer, cities]) => #{china, friedman, felleisen})
207
207
208
- (facts " all-author-names"
208
+ (facts " 25 all-author-names"
209
209
(all-author-names []) => #{}
210
210
(all-author-names [cities, wild-seed])
211
211
=> #{" China Miéville" " Octavia E. Butler" }
212
212
(all-author-names books)
213
213
=> #{" Matthias Felleisen" " China Miéville"
214
214
" Octavia E. Butler" " Daniel Friedman" })
215
- (facts " author->string"
215
+ (facts " 26 author->string"
216
216
(author->string felleisen) => " Matthias Felleisen"
217
217
(author->string friedman) => " Daniel Friedman (1944 - )"
218
218
(author->string octavia) => " Octavia E. Butler (1947 - 2006)" )
219
219
220
- (facts " authors->string"
220
+ (facts " 27 authors->string"
221
221
(authors->string (:authors little-schemer))
222
222
=> (every-checker (contains " Daniel Friedman (1944 - )" )
223
223
(contains " Matthias Felleisen" )
229
229
(contains " Daniel Friedman (1944 - )" )
230
230
(contains " , " )))
231
231
232
- (facts " book->string"
232
+ (facts " 28 book->string"
233
233
(book->string wild-seed)
234
234
=> " Wild Seed, written by Octavia E. Butler (1947 - 2006)"
235
235
(book->string little-schemer)
236
236
=> (every-checker (has-prefix " The Little Schemer, written by " )
237
237
(has-suffix #"Daniel Friedman \( 1944 - \) , Matthias Felleisen|Matthias Felleisen, Daniel Friedman \( 1944 - \) " )))
238
238
239
- (facts " books->string"
239
+ (facts " 29 books->string"
240
240
(books->string []) => " No books."
241
241
(books->string [cities])
242
242
=> " 1 book. The City and the City, written by China Miéville (1972 - )."
243
243
(books->string [little-schemer, cities, wild-seed])
244
244
=> #"3 books. The Little Schemer, written by (Daniel Friedman \( 1944 - \) , Matthias Felleisen|Matthias Felleisen, Daniel Friedman \( 1944 - \) ). The City and the City, written by China Miéville \( 1972 - \) . Wild Seed, written by Octavia E. Butler \( 1947 - 2006\) ." )
245
245
246
- (facts " books-by-author"
246
+ (facts " 30 books-by-author"
247
247
(books-by-author china books) => (just [cities embassytown])
248
248
(books-by-author octavia books) => (just [wild-seed]))
249
249
250
- (facts " author-by-name"
250
+ (facts " 31 author-by-name"
251
251
(author-by-name " Octavia E. Butler" authors-set) => octavia
252
252
(author-by-name " Octavia E. Butler" #{felleisen, friedman}) => nil
253
253
(author-by-name " China Miéville" authors-set) => china
254
254
(author-by-name " Goerge R. R. Martin" authors-set) => nil )
255
255
256
- (facts " living-authors"
256
+ (facts " 32 living-authors"
257
257
(living-authors authors-set) => (just #{china, felleisen, friedman})
258
258
(living-authors #{octavia}) => (just #{})
259
259
(living-authors #{china, felleisen}) => (just #{china, felleisen}))
260
260
261
- (facts " has-a-living-author?"
261
+ (facts " 33 has-a-living-author?"
262
262
(has-a-living-author? wild-seed) => false
263
263
(has-a-living-author? silmarillion) => true
264
264
(has-a-living-author? little-schemer) => true
265
265
(has-a-living-author? cities) => true
266
266
(has-a-living-author? deus-irae) => false )
267
267
268
- (facts " books-by-living-authors"
268
+ (facts " 34 books-by-living-authors"
269
269
(books-by-living-authors books) => (just #{little-schemer cities embassytown})
270
270
(books-by-living-authors (concat books [deus-irae, silmarillion]))
271
271
=> (just #{little-schemer cities embassytown silmarillion})))
0 commit comments