Skip to content

Commit c8608f0

Browse files
author
Jani Rahkola
committed
Merge branch 'master' of github.com:iloveponies/structured-data
Conflicts: test/structured_data_test.clj
2 parents 9678110 + 92d4bb2 commit c8608f0

File tree

1 file changed

+91
-48
lines changed

1 file changed

+91
-48
lines changed

test/structured_data_test.clj

Lines changed: 91 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -20,52 +20,85 @@
2020
(spiff-destructuring [1 2 3]) => 4
2121
(spiff-destructuring [1 2 -34 4 5 6]) => -33)
2222

23-
(facts "5 width"
24-
(width (rectangle [1 1] [5 1])) => 4
25-
(width (rectangle [1 1] [1 1])) => 0
26-
(width (rectangle [3 1] [10 4])) => 7)
27-
28-
(facts "5 height"
29-
(height (rectangle [1 1] [5 1])) => 0
30-
(height (rectangle [1 1] [5 5])) => 4
31-
(height (rectangle [0 0] [2 3])) => 3)
32-
33-
(facts "6 square?"
34-
(square? (rectangle [1 1] [2 2])) => true
35-
(square? (rectangle [1 1] [2 3])) => false
36-
(square? (rectangle [1 1] [1 1])) => true
37-
(square? (rectangle [3 2] [1 0])) => true
38-
(square? (rectangle [3 2] [1 1])) => false)
39-
40-
(facts "7 area"
41-
(area (rectangle [1 1] [5 1])) => 0
42-
(area (rectangle [0 0] [1 1])) => 1
43-
(area (rectangle [0 0] [4 3])) => 12
44-
(area (rectangle [3 1] [10 4])) => 21)
45-
46-
(facts "8 contains-point?"
47-
(contains-point? (rectangle [0 0] [2 2])
48-
(point 1 1)) => true
49-
(contains-point? (rectangle [0 0] [2 2])
50-
(point 2 1)) => true
51-
(contains-point? (rectangle [0 0] [2 2])
52-
(point -3 1)) => false
53-
(contains-point? (rectangle [0 0] [2 2])
54-
(point 1 3)) => false
55-
(contains-point? (rectangle [1 1] [2 2])
56-
(point 1 1)) => true
57-
(contains-point? (rectangle [1 1] [1 1])
58-
(point 1 1)) => true)
59-
60-
(facts "9 contains-rectangle?"
61-
(contains-rectangle? (rectangle [0 0] [3 3])
62-
(rectangle [1 1] [2 2])) => true
63-
(contains-rectangle? (rectangle [0 0] [2 2])
64-
(rectangle [1 1] [3 3])) => false
65-
(contains-rectangle? (rectangle [0 0] [1 1])
66-
(rectangle [0 0] [1 1])) => true
67-
(contains-rectangle? (rectangle [0 0] [1 1])
68-
(rectangle [1 1] [2 2])) => false)
23+
(tabular
24+
(facts "5 width"
25+
(width (rectangle ?bottom-left ?top-right)) => ?width)
26+
?bottom-left ?top-right ?width
27+
[1 1] [5 1] 4
28+
[1 1] [1 1] 0
29+
[3 1] [10 4] 7
30+
[-1 -1] [0 0] 1
31+
[-5 2] [0 2] 5)
32+
33+
(tabular
34+
(facts "5 height"
35+
(height (rectangle ?bottom-left ?top-right)) => ?height)
36+
?bottom-left ?top-right ?height
37+
[1 1] [5 1] 0
38+
[-1 -1] [0 0] 1
39+
[2 -7] [4 4] 11
40+
[1 1] [5 5] 4
41+
[0 0] [2 3] 3)
42+
43+
(tabular
44+
(facts "6 square?"
45+
(square? (rectangle ?bottom-left ?top-right)) => ?square?)
46+
?bottom-left ?top-right ?square?
47+
[1 1] [2 2] true
48+
[1 1] [2 3] false
49+
[1 1] [1 1] true
50+
[3 2] [1 0] true
51+
[3 2] [1 1] false
52+
[-1 -1] [0 0] true
53+
[-2 -4] [0 -2] true
54+
[-2 -3] [1 1] false)
55+
56+
(tabular
57+
(facts "7 area"
58+
(area (rectangle ?bottom-left ?top-right)) => ?area)
59+
?bottom-left ?top-right ?area
60+
[1 1] [5 1] 0
61+
[0 0] [1 1] 1
62+
[0 0] [4 3] 12
63+
[-1 -1] [3 7] 32
64+
[-2 -7] [-1 -2] 5
65+
[3 1] [10 4] 21)
66+
67+
(tabular
68+
(facts "8 contains-point?"
69+
(contains-point? (rectangle ?bottom-left ?top-right)
70+
?point)
71+
=> ?contains?)
72+
?bottom-left ?top-right ?point ?contains?
73+
[0 0] [2 2] [1 1] true
74+
[0 0] [2 2] [2 1] true
75+
[0 0] [2 2] [-3 1] false
76+
[-2 -5] [1 5] [-2 -1] true
77+
[-2 -5] [1 5] [-3 -1] false
78+
[0 0] [2 2] [1 3] false
79+
[1 1] [2 2] [1 1] true
80+
[1 1] [1 1] [1 1] true
81+
82+
[-1 2] [3 7] [-6 10] false
83+
[-1 2] [3 7] [0 10] false
84+
[-1 2] [3 7] [5 11] false
85+
[-1 2] [3 7] [5 4] false
86+
[-1 2] [3 7] [6 1] false
87+
[-1 2] [3 7] [0 0] false
88+
[-1 2] [3 7] [-2 0] false
89+
[-1 2] [3 7] [-5 5] false)
90+
91+
(tabular
92+
(facts "9 contains-rectangle?"
93+
(contains-rectangle? (rectangle ?x1 ?y1)
94+
(rectangle ?x2 ?y2)) => ?contains?)
95+
?x1 ?y1 ?x2 ?y2 ?contains?
96+
[0 0] [3 3] [1 1] [2 2] true
97+
[0 0] [2 2] [1 1] [3 3] false
98+
[0 0] [1 1] [0 0] [1 1] true
99+
[0 0] [1 1] [1 1] [2 2] false
100+
[-2 -2] [2 2] [-1 -1] [1 1] true
101+
[-2 -2] [2 2] [0 0] [3 4] false)
69102

70103
(def china {:name "China Miéville", :birth-year 1972})
71104
(def octavia {:name "Octavia E. Butler"
@@ -157,6 +190,7 @@
157190

158191
(facts "21 contains-duplicates?"
159192
(contains-duplicates? [1 1 2 3 -40]) => true
193+
(contains-duplicates? [1 2 2 3 -40]) => true
160194
(contains-duplicates? [1 2 3 -40]) => false
161195
(contains-duplicates? [1 2 3 "a" "a"]) => true)
162196

@@ -165,7 +199,16 @@
165199
:authors [friedman, felleisen]})
166200
=> {:title "The Little Schemer" :authors #{friedman, felleisen}}
167201
(old-book->new-book {:title "Wild Seed", :authors [octavia]})
168-
=> {:title "Wild Seed", :authors #{octavia}})
202+
=> {:title "Wild Seed", :authors #{octavia}}
203+
(old-book->new-book
204+
{:awards ["Hugo" "World Fantasy Award" "Arthur C. Clarke Award"
205+
"British Science Fiction Award"]
206+
:title "The City and the City"
207+
:authors [{:birth-year 1972, :name "China Miéville"}]})
208+
=> {:awards ["Hugo" "World Fantasy Award" "Arthur C. Clarke Award"
209+
"British Science Fiction Award"]
210+
:title "The City and the City"
211+
:authors #{{:birth-year 1972, :name "China Miéville"}}})
169212

170213

171214
(let [china {:name "China Miéville", :birth-year 1972}
@@ -268,4 +311,4 @@
268311
(facts "34 books-by-living-authors"
269312
(books-by-living-authors books) => (just #{little-schemer cities embassytown})
270313
(books-by-living-authors (concat books [deus-irae, silmarillion]))
271-
=> (just #{little-schemer cities embassytown silmarillion})))
314+
=> (just #{little-schemer cities embassytown silmarillion})))

0 commit comments

Comments
 (0)