Skip to content

Commit 0ab503e

Browse files
committed
Tests as a separate project
1 parent 5ca6222 commit 0ab503e

File tree

2 files changed

+3
-352
lines changed

2 files changed

+3
-352
lines changed

project.clj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
(defproject structured-data "1.0.0-SNAPSHOT"
22
:dependencies [[org.clojure/clojure "1.5.1"]
3-
[midje-grader "0.1.0-SNAPSHOT"]]
4-
:profiles {:dev {:dependencies [[midje "1.5.1"]]
5-
:plugins [[lein-midje "3.1.1"]]}})
3+
[iloveponies.tests/structured-data "0.1.0-SNAPSHOT"]]
4+
:profiles {:dev {:plugins [[lein-midje "3.1.1"]]}})
65

test/structured_data_test.clj

Lines changed: 1 addition & 349 deletions
Original file line numberDiff line numberDiff line change
@@ -1,350 +1,2 @@
11
(ns structured-data-test
2-
(:use structured-data
3-
midje.sweet))
4-
5-
(facts "do-a-thing" {:exercise 1
6-
:points 1}
7-
(do-a-thing 3) => 46656.0
8-
(do-a-thing 1) => 4.0
9-
(do-a-thing 0) => 1.0)
10-
11-
(facts "spiff" {:exercise 2
12-
:points 1}
13-
(spiff [1 2 3]) => 4
14-
(spiff [1 2 -34 4 5 6]) => -33)
15-
16-
(facts "cutify" {:exercise 3
17-
:points 1}
18-
(cutify []) => ["<3"]
19-
(cutify [1 2 3]) => [1 2 3 "<3"]
20-
(cutify ["a" "b"]) => ["a" "b" "<3"])
21-
22-
(facts "spiff-destructuring" {:exercise 4
23-
:points 1}
24-
(spiff-destructuring [1 2 3]) => 4
25-
(spiff-destructuring [1 2 -34 4 5 6]) => -33)
26-
27-
(facts {:exercise 5
28-
:points 1}
29-
(tabular
30-
(facts "width"
31-
(width (rectangle ?bottom-left ?top-right)) => ?width)
32-
?bottom-left ?top-right ?width
33-
[1 1] [5 1] 4
34-
[1 1] [1 1] 0
35-
[3 1] [10 4] 7
36-
[-1 -1] [0 0] 1
37-
[-5 2] [0 2] 5)
38-
39-
(tabular
40-
(facts "height"
41-
(height (rectangle ?bottom-left ?top-right)) => ?height)
42-
?bottom-left ?top-right ?height
43-
[1 1] [5 1] 0
44-
[-1 -1] [0 0] 1
45-
[2 -7] [4 4] 11
46-
[1 1] [5 5] 4
47-
[0 0] [2 3] 3))
48-
49-
(tabular
50-
(facts "square?" {:exercise 6
51-
:points 1}
52-
(square? (rectangle ?bottom-left ?top-right)) => ?square?)
53-
?bottom-left ?top-right ?square?
54-
[1 1] [2 2] true
55-
[1 1] [2 3] false
56-
[1 1] [1 1] true
57-
[3 2] [1 0] true
58-
[3 2] [1 1] false
59-
[-1 -1] [0 0] true
60-
[-2 -4] [0 -2] true
61-
[-2 -3] [1 1] false)
62-
63-
(tabular
64-
(facts "area" {:exercise 7
65-
:points 1}
66-
(area (rectangle ?bottom-left ?top-right)) => ?area)
67-
?bottom-left ?top-right ?area
68-
[1 1] [5 1] 0
69-
[0 0] [1 1] 1
70-
[0 0] [4 3] 12
71-
[-1 -1] [3 7] 32
72-
[-2 -7] [-1 -2] 5
73-
[3 1] [10 4] 21)
74-
75-
(tabular
76-
(facts "contains-point?" {:exercise 8
77-
:points 1}
78-
(contains-point? (rectangle ?bottom-left ?top-right)
79-
?point)
80-
=> ?contains?)
81-
?bottom-left ?top-right ?point ?contains?
82-
[0 0] [2 2] [1 1] true
83-
[0 0] [2 2] [2 1] true
84-
[0 0] [2 2] [-3 1] false
85-
[-2 -5] [1 5] [-2 -1] true
86-
[-2 -5] [1 5] [-3 -1] false
87-
[0 0] [2 2] [1 3] false
88-
[1 1] [2 2] [1 1] true
89-
[1 1] [1 1] [1 1] true
90-
91-
[-1 2] [3 7] [-6 10] false
92-
[-1 2] [3 7] [0 10] false
93-
[-1 2] [3 7] [5 11] false
94-
[-1 2] [3 7] [5 4] false
95-
[-1 2] [3 7] [6 1] false
96-
[-1 2] [3 7] [0 0] false
97-
[-1 2] [3 7] [-2 0] false
98-
[-1 2] [3 7] [-5 5] false)
99-
100-
(tabular
101-
(facts "contains-rectangle?" {:exercise 9
102-
:points 1}
103-
(contains-rectangle? (rectangle ?x1 ?y1)
104-
(rectangle ?x2 ?y2)) => ?contains?)
105-
?x1 ?y1 ?x2 ?y2 ?contains?
106-
[0 0] [3 3] [1 1] [2 2] true
107-
[0 0] [2 2] [1 1] [3 3] false
108-
[0 0] [1 1] [0 0] [1 1] true
109-
[0 0] [1 1] [1 1] [2 2] false
110-
[-2 -2] [2 2] [-1 -1] [1 1] true
111-
[-2 -2] [2 2] [0 0] [3 4] false)
112-
113-
(def china {:name "China Miéville", :birth-year 1972})
114-
(def octavia {:name "Octavia E. Butler"
115-
:birth-year 1947
116-
:death-year 2006})
117-
(def friedman {:name "Daniel Friedman" :birth-year 1944})
118-
(def felleisen {:name "Matthias Felleisen"})
119-
120-
(def cities {:title "The City and the City" :authors [china]})
121-
(def wild-seed {:title "Wild Seed", :authors [octavia]})
122-
(def embassytown {:title "Embassytown", :authors [china]})
123-
(def little-schemer {:title "The Little Schemer"
124-
:authors [friedman, felleisen]})
125-
126-
(def books [cities, wild-seed, embassytown, little-schemer])
127-
128-
(let [china {:name "China Miéville", :birth-year 1972}
129-
octavia {:name "Octavia E. Butler"
130-
:birth-year 1947
131-
:death-year 2006}
132-
friedman {:name "Daniel Friedman" :birth-year 1944}
133-
felleisen {:name "Matthias Felleisen"}
134-
cities {:title "The City and the City" :authors [china]}
135-
wild-seed {:title "Wild Seed", :authors [octavia]}
136-
embassytown {:title "Embassytown", :authors [china]}
137-
little-schemer {:title "The Little Schemer"
138-
:authors [friedman, felleisen]}
139-
books [cities, wild-seed, embassytown, little-schemer]]
140-
141-
(facts "title-length" {:exercise 10
142-
:points 1}
143-
(title-length cities) => 21
144-
(title-length wild-seed) => 9
145-
(title-length little-schemer) => 18)
146-
147-
(facts "author-count" {:exercise 11
148-
:points 1}
149-
(author-count cities) => 1
150-
(author-count wild-seed) => 1
151-
(author-count little-schemer) => 2)
152-
153-
(facts "multiple-authors?" {:exercise 12
154-
:points 1}
155-
(multiple-authors? cities) => false
156-
(multiple-authors? wild-seed) => false
157-
(multiple-authors? little-schemer) => true)
158-
159-
(facts "add-author" {:exercise 13
160-
:points 1}
161-
(add-author little-schemer {:name "Gerald J. Sussman"})
162-
=> {:title "The Little Schemer"
163-
:authors [{:birth-year 1944, :name "Daniel Friedman"}
164-
{:name "Matthias Felleisen"}
165-
{:name "Gerald J. Sussman"}]}
166-
(add-author {:authors [{:name "Juhana"}]} {:name "Jani"})
167-
=> {:authors [{:name "Juhana"} {:name "Jani"}]})
168-
169-
(facts "alive?" {:exercise 14
170-
:points 1}
171-
(alive? china) => true
172-
(alive? octavia) => false)
173-
174-
(facts "element-lengths" {:exercise 15
175-
:points 1}
176-
(element-lengths ["foo" "bar" "" "quux"]) => [3 3 0 4]
177-
(element-lengths ["x" [:a :b :c] {:y 42}]) => [1 3 1])
178-
179-
(facts "second-elements" {:exercise 16
180-
:points 1}
181-
(second-elements [[1 2] [2 3] [3 4]]) => [2 3 4]
182-
(second-elements [[1 2 3 4] [1] ["a" "s" "d" "f"]]) => [2 nil "s"])
183-
184-
(facts "titles" {:exercise 17
185-
:points 1}
186-
(titles [cities]) => ["The City and the City"]
187-
(titles books) => (just ["The City and the City"
188-
"Wild Seed"
189-
"Embassytown"
190-
"The Little Schemer"]
191-
:in-any-order)))
192-
193-
(facts "stars" {:exercise 18
194-
:points 1}
195-
(stars 1) => "*"
196-
(stars 7) => "*******"
197-
(stars 3) => "***")
198-
199-
(facts "monotonic?" {:exercise 19
200-
:points 1}
201-
(monotonic? [1 2 3]) => true
202-
(monotonic? [0 1 10 11]) => true
203-
(monotonic? [3 2 0 -3]) => true
204-
(monotonic? [3 2 2]) => true
205-
(monotonic? [1 2 1 0]) => false)
206-
207-
(facts "toggle" {:exercise 20
208-
:points 1}
209-
(toggle #{:a :b :c} :d) => #{:a :b :c :d}
210-
(toggle #{:a :b :c} :a) => #{:b :c})
211-
212-
(facts "contains-duplicates?" {:exercise 21
213-
:points 1}
214-
(contains-duplicates? [1 1 2 3 -40]) => true
215-
(contains-duplicates? [1 2 2 3 -40]) => true
216-
(contains-duplicates? [1 2 3 -40]) => false
217-
(contains-duplicates? [1 2 3 "a" "a"]) => true)
218-
219-
(facts "old-book->new-book" {:exercise 22
220-
:points 1}
221-
(old-book->new-book {:title "The Little Schemer"
222-
:authors [friedman, felleisen]})
223-
=> {:title "The Little Schemer" :authors #{friedman, felleisen}}
224-
(old-book->new-book {:title "Wild Seed", :authors [octavia]})
225-
=> {:title "Wild Seed", :authors #{octavia}}
226-
(old-book->new-book
227-
{:awards ["Hugo" "World Fantasy Award" "Arthur C. Clarke Award"
228-
"British Science Fiction Award"]
229-
:title "The City and the City"
230-
:authors [{:birth-year 1972, :name "China Miéville"}]})
231-
=> {:awards ["Hugo" "World Fantasy Award" "Arthur C. Clarke Award"
232-
"British Science Fiction Award"]
233-
:title "The City and the City"
234-
:authors #{{:birth-year 1972, :name "China Miéville"}}})
235-
236-
237-
(let [china {:name "China Miéville", :birth-year 1972}
238-
octavia {:name "Octavia E. Butler"
239-
:birth-year 1947
240-
:death-year 2006}
241-
friedman {:name "Daniel Friedman" :birth-year 1944}
242-
felleisen {:name "Matthias Felleisen"}
243-
jrrtolkien {:name "J. R. R. Tolkien" :birth-year 1892 :death-year 1973}
244-
christopher {:name "Christopher Tolkien" :birth-year 1924}
245-
kay {:name "Guy Gavriel Kay" :birth-year 1954}
246-
dick {:name "Philip K. Dick", :birth-year 1928, :death-year 1982}
247-
zelazny {:name "Roger Zelazny", :birth-year 1937, :death-year 1995}
248-
249-
authors-set #{china, felleisen, octavia, friedman}
250-
251-
cities {:title "The City and the City" :authors #{china}}
252-
wild-seed {:title "Wild Seed", :authors #{octavia}}
253-
embassytown {:title "Embassytown", :authors #{china}}
254-
little-schemer {:title "The Little Schemer"
255-
:authors #{friedman, felleisen}}
256-
silmarillion {:title "Silmarillion"
257-
:authors #{jrrtolkien, christopher, kay}}
258-
deus-irae {:title "Deus Irae", :authors #{dick, zelazny}}
259-
260-
books [cities, wild-seed, embassytown, little-schemer]]
261-
262-
(facts "has-author?" {:exercise 23
263-
:points 1}
264-
(has-author? cities china) => true
265-
(has-author? cities felleisen) => false
266-
(has-author? little-schemer felleisen) => true
267-
(has-author? little-schemer friedman) => true
268-
(has-author? little-schemer octavia) => false)
269-
270-
(facts "authors" {:exercise 24
271-
:points 1}
272-
(authors [cities, wild-seed]) => #{china, octavia}
273-
(authors [cities, wild-seed, embassytown]) => #{china, octavia}
274-
(authors [little-schemer, cities]) => #{china, friedman, felleisen})
275-
276-
(facts "all-author-names" {:exercise 25
277-
:points 1}
278-
(all-author-names []) => #{}
279-
(all-author-names [cities, wild-seed])
280-
=> #{"China Miéville" "Octavia E. Butler"}
281-
(all-author-names books)
282-
=> #{"Matthias Felleisen" "China Miéville"
283-
"Octavia E. Butler" "Daniel Friedman"})
284-
285-
(facts "author->string" {:exercise 26
286-
:points 1}
287-
(author->string felleisen) => "Matthias Felleisen"
288-
(author->string friedman) => "Daniel Friedman (1944 - )"
289-
(author->string octavia) => "Octavia E. Butler (1947 - 2006)")
290-
291-
(facts "authors->string" {:exercise 27
292-
:points 1}
293-
(authors->string (:authors little-schemer))
294-
=> (every-checker (contains "Daniel Friedman (1944 - )")
295-
(contains "Matthias Felleisen")
296-
(contains ", "))
297-
(authors->string #{octavia}) => "Octavia E. Butler (1947 - 2006)"
298-
(authors->string #{}) => ""
299-
(authors->string #{octavia, friedman})
300-
=> (every-checker (contains "Octavia E. Butler (1947 - 2006)")
301-
(contains "Daniel Friedman (1944 - )")
302-
(contains ", ")))
303-
304-
(facts "book->string" {:exercise 28
305-
:points 1}
306-
(book->string wild-seed)
307-
=> "Wild Seed, written by Octavia E. Butler (1947 - 2006)"
308-
(book->string little-schemer)
309-
=> (every-checker (has-prefix "The Little Schemer, written by ")
310-
(has-suffix #"Daniel Friedman \(1944 - \), Matthias Felleisen|Matthias Felleisen, Daniel Friedman \(1944 - \)")))
311-
312-
(facts "books->string" {:exercise 29
313-
:points 1}
314-
(books->string []) => "No books."
315-
(books->string [cities])
316-
=> "1 book. The City and the City, written by China Miéville (1972 - )."
317-
(books->string [little-schemer, cities, wild-seed])
318-
=> #"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\).")
319-
320-
(facts "books-by-author" {:exercise 30
321-
:points 1}
322-
(books-by-author china books) => (just [cities embassytown])
323-
(books-by-author octavia books) => (just [wild-seed]))
324-
325-
(facts "author-by-name" {:exercise 31
326-
:points 1}
327-
(author-by-name "Octavia E. Butler" authors-set) => octavia
328-
(author-by-name "Octavia E. Butler" #{felleisen, friedman}) => nil
329-
(author-by-name "China Miéville" authors-set) => china
330-
(author-by-name "Goerge R. R. Martin" authors-set) => nil)
331-
332-
(facts "living-authors" {:exercise 32
333-
:points 1}
334-
(living-authors authors-set) => (just #{china, felleisen, friedman})
335-
(living-authors #{octavia}) => (just #{})
336-
(living-authors #{china, felleisen}) => (just #{china, felleisen}))
337-
338-
(facts "has-a-living-author?" {:exercise 33
339-
:points 1}
340-
(has-a-living-author? wild-seed) => false
341-
(has-a-living-author? silmarillion) => true
342-
(has-a-living-author? little-schemer) => true
343-
(has-a-living-author? cities) => true
344-
(has-a-living-author? deus-irae) => false)
345-
346-
(facts "books-by-living-authors" {:exercise 34
347-
:points 1}
348-
(books-by-living-authors books) => (just #{little-schemer cities embassytown})
349-
(books-by-living-authors (concat books [deus-irae, silmarillion]))
350-
=> (just #{little-schemer cities embassytown silmarillion})))
2+
(:use iloveponies.tests.structured-data))

0 commit comments

Comments
 (0)