Skip to content

Commit d42d497

Browse files
committed
allergies: add generators and regenerate tests
1 parent 18137b3 commit d42d497

File tree

3 files changed

+90
-50
lines changed

3 files changed

+90
-50
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
(ns allergies-generator
2+
(:require [clojure.string :as str]))
3+
4+
(defn- create-context [test-case]
5+
(let [[parent-description description] (:path test-case)]
6+
(-> parent-description
7+
(str/replace #"list when:" "allergies")
8+
(str "" description))))
9+
10+
(defn- update-input [input]
11+
(if-let [item (get input :item)]
12+
(assoc input :item (symbol (str (keyword item))))
13+
input))
14+
15+
(defn- update-expected [expected]
16+
(if (sequential? expected)
17+
(mapv #(symbol (str (keyword %))) expected)
18+
expected))
19+
20+
(defn update-test-case [test-case]
21+
(-> test-case
22+
(update :input update-input)
23+
(update :expected update-expected)
24+
(assoc :context (create-context test-case))))
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
(ns allergies-test
2+
(:require [clojure.test :refer [deftest testing is]]
3+
allergies))
4+
5+
{{#test_cases.allergicTo}}
6+
(deftest allergic-to?_test_{{idx}}
7+
(testing {{context}}
8+
(is ({{#expected}}true?{{else}}false?{{/expected}} (allergies/allergic-to? {{input.score}} {{input.item}})))))
9+
{{/test_cases.allergicTo}}
10+
11+
{{#test_cases.list}}
12+
(deftest allergies_test_{{idx}}
13+
(testing {{context}}
14+
(is (= {{expected}}
15+
(allergies/allergies {{input.score}})))))
16+
{{/test_cases.list}}

exercises/practice/allergies/test/allergies_test.clj

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,211 +3,211 @@
33
allergies))
44

55
(deftest allergic-to?_test_1
6-
(testing "testing for eggs allergy -> not allergic to anything"
6+
(testing "testing for eggs allergy not allergic to anything"
77
(is (false? (allergies/allergic-to? 0 :eggs)))))
88

99
(deftest allergic-to?_test_2
10-
(testing "testing for eggs allergy -> allergic only to eggs"
10+
(testing "testing for eggs allergy allergic only to eggs"
1111
(is (true? (allergies/allergic-to? 1 :eggs)))))
1212

1313
(deftest allergic-to?_test_3
14-
(testing "testing for eggs allergy -> allergic to eggs and something else"
14+
(testing "testing for eggs allergy allergic to eggs and something else"
1515
(is (true? (allergies/allergic-to? 3 :eggs)))))
1616

1717
(deftest allergic-to?_test_4
18-
(testing "testing for eggs allergy -> allergic to something, but not eggs"
18+
(testing "testing for eggs allergy allergic to something, but not eggs"
1919
(is (false? (allergies/allergic-to? 2 :eggs)))))
2020

2121
(deftest allergic-to?_test_5
22-
(testing "testing for eggs allergy -> allergic to everything"
22+
(testing "testing for eggs allergy allergic to everything"
2323
(is (true? (allergies/allergic-to? 255 :eggs)))))
2424

2525
(deftest allergic-to?_test_6
26-
(testing "testing for peanuts allergy -> not allergic to anything"
26+
(testing "testing for peanuts allergy not allergic to anything"
2727
(is (false? (allergies/allergic-to? 0 :peanuts)))))
2828

2929
(deftest allergic-to?_test_7
30-
(testing "testing for peanuts allergy -> allergic only to peanuts"
30+
(testing "testing for peanuts allergy allergic only to peanuts"
3131
(is (true? (allergies/allergic-to? 2 :peanuts)))))
3232

3333
(deftest allergic-to?_test_8
34-
(testing "testing for peanuts allergy -> allergic to peanuts and something else"
34+
(testing "testing for peanuts allergy allergic to peanuts and something else"
3535
(is (true? (allergies/allergic-to? 7 :peanuts)))))
3636

3737
(deftest allergic-to?_test_9
38-
(testing "testing for peanuts allergy -> allergic to something, but not peanuts"
38+
(testing "testing for peanuts allergy allergic to something, but not peanuts"
3939
(is (false? (allergies/allergic-to? 5 :peanuts)))))
4040

4141
(deftest allergic-to?_test_10
42-
(testing "testing for peanuts allergy -> allergic to everything"
42+
(testing "testing for peanuts allergy allergic to everything"
4343
(is (true? (allergies/allergic-to? 255 :peanuts)))))
4444

4545
(deftest allergic-to?_test_11
46-
(testing "testing for shellfish allergy -> not allergic to anything"
46+
(testing "testing for shellfish allergy not allergic to anything"
4747
(is (false? (allergies/allergic-to? 0 :shellfish)))))
4848

4949
(deftest allergic-to?_test_12
50-
(testing "testing for shellfish allergy -> allergic only to shellfish"
50+
(testing "testing for shellfish allergy allergic only to shellfish"
5151
(is (true? (allergies/allergic-to? 4 :shellfish)))))
5252

5353
(deftest allergic-to?_test_13
54-
(testing "testing for shellfish allergy -> allergic to shellfish and something else"
54+
(testing "testing for shellfish allergy allergic to shellfish and something else"
5555
(is (true? (allergies/allergic-to? 14 :shellfish)))))
5656

5757
(deftest allergic-to?_test_14
58-
(testing "testing for shellfish allergy -> allergic to something, but not shellfish"
58+
(testing "testing for shellfish allergy allergic to something, but not shellfish"
5959
(is (false? (allergies/allergic-to? 10 :shellfish)))))
6060

6161
(deftest allergic-to?_test_15
62-
(testing "testing for shellfish allergy -> allergic to everything"
62+
(testing "testing for shellfish allergy allergic to everything"
6363
(is (true? (allergies/allergic-to? 255 :shellfish)))))
6464

6565
(deftest allergic-to?_test_16
66-
(testing "testing for strawberries allergy -> not allergic to anything"
66+
(testing "testing for strawberries allergy not allergic to anything"
6767
(is (false? (allergies/allergic-to? 0 :strawberries)))))
6868

6969
(deftest allergic-to?_test_17
70-
(testing "testing for strawberries allergy -> allergic only to strawberries"
70+
(testing "testing for strawberries allergy allergic only to strawberries"
7171
(is (true? (allergies/allergic-to? 8 :strawberries)))))
7272

7373
(deftest allergic-to?_test_18
74-
(testing "testing for strawberries allergy -> allergic to strawberries and something else"
74+
(testing "testing for strawberries allergy allergic to strawberries and something else"
7575
(is (true? (allergies/allergic-to? 28 :strawberries)))))
7676

7777
(deftest allergic-to?_test_19
78-
(testing "testing for strawberries allergy -> allergic to something, but not strawberries"
78+
(testing "testing for strawberries allergy allergic to something, but not strawberries"
7979
(is (false? (allergies/allergic-to? 20 :strawberries)))))
8080

8181
(deftest allergic-to?_test_20
82-
(testing "testing for strawberries allergy -> allergic to everything"
82+
(testing "testing for strawberries allergy allergic to everything"
8383
(is (true? (allergies/allergic-to? 255 :strawberries)))))
8484

8585
(deftest allergic-to?_test_21
86-
(testing "testing for tomatoes allergy -> not allergic to anything"
86+
(testing "testing for tomatoes allergy not allergic to anything"
8787
(is (false? (allergies/allergic-to? 0 :tomatoes)))))
8888

8989
(deftest allergic-to?_test_22
90-
(testing "testing for tomatoes allergy -> allergic only to tomatoes"
90+
(testing "testing for tomatoes allergy allergic only to tomatoes"
9191
(is (true? (allergies/allergic-to? 16 :tomatoes)))))
9292

9393
(deftest allergic-to?_test_23
94-
(testing "testing for tomatoes allergy -> allergic to tomatoes and something else"
94+
(testing "testing for tomatoes allergy allergic to tomatoes and something else"
9595
(is (true? (allergies/allergic-to? 56 :tomatoes)))))
9696

9797
(deftest allergic-to?_test_24
98-
(testing "testing for tomatoes allergy -> allergic to something, but not tomatoes"
98+
(testing "testing for tomatoes allergy allergic to something, but not tomatoes"
9999
(is (false? (allergies/allergic-to? 40 :tomatoes)))))
100100

101101
(deftest allergic-to?_test_25
102-
(testing "testing for tomatoes allergy -> allergic to everything"
102+
(testing "testing for tomatoes allergy allergic to everything"
103103
(is (true? (allergies/allergic-to? 255 :tomatoes)))))
104104

105105
(deftest allergic-to?_test_26
106-
(testing "testing for chocolate allergy -> not allergic to anything"
106+
(testing "testing for chocolate allergy not allergic to anything"
107107
(is (false? (allergies/allergic-to? 0 :chocolate)))))
108108

109109
(deftest allergic-to?_test_27
110-
(testing "testing for chocolate allergy -> allergic only to chocolate"
110+
(testing "testing for chocolate allergy allergic only to chocolate"
111111
(is (true? (allergies/allergic-to? 32 :chocolate)))))
112112

113113
(deftest allergic-to?_test_28
114-
(testing "testing for chocolate allergy -> allergic to chocolate and something else"
114+
(testing "testing for chocolate allergy allergic to chocolate and something else"
115115
(is (true? (allergies/allergic-to? 112 :chocolate)))))
116116

117117
(deftest allergic-to?_test_29
118-
(testing "testing for chocolate allergy -> allergic to something, but not chocolate"
118+
(testing "testing for chocolate allergy allergic to something, but not chocolate"
119119
(is (false? (allergies/allergic-to? 80 :chocolate)))))
120120

121121
(deftest allergic-to?_test_30
122-
(testing "testing for chocolate allergy -> allergic to everything"
122+
(testing "testing for chocolate allergy allergic to everything"
123123
(is (true? (allergies/allergic-to? 255 :chocolate)))))
124124

125125
(deftest allergic-to?_test_31
126-
(testing "testing for pollen allergy -> not allergic to anything"
126+
(testing "testing for pollen allergy not allergic to anything"
127127
(is (false? (allergies/allergic-to? 0 :pollen)))))
128128

129129
(deftest allergic-to?_test_32
130-
(testing "testing for pollen allergy -> allergic only to pollen"
130+
(testing "testing for pollen allergy allergic only to pollen"
131131
(is (true? (allergies/allergic-to? 64 :pollen)))))
132132

133133
(deftest allergic-to?_test_33
134-
(testing "testing for pollen allergy -> allergic to pollen and something else"
134+
(testing "testing for pollen allergy allergic to pollen and something else"
135135
(is (true? (allergies/allergic-to? 224 :pollen)))))
136136

137137
(deftest allergic-to?_test_34
138-
(testing "testing for pollen allergy -> allergic to something, but not pollen"
138+
(testing "testing for pollen allergy allergic to something, but not pollen"
139139
(is (false? (allergies/allergic-to? 160 :pollen)))))
140140

141141
(deftest allergic-to?_test_35
142-
(testing "testing for pollen allergy -> allergic to everything"
142+
(testing "testing for pollen allergy allergic to everything"
143143
(is (true? (allergies/allergic-to? 255 :pollen)))))
144144

145145
(deftest allergic-to?_test_36
146-
(testing "testing for cats allergy -> not allergic to anything"
146+
(testing "testing for cats allergy not allergic to anything"
147147
(is (false? (allergies/allergic-to? 0 :cats)))))
148148

149149
(deftest allergic-to?_test_37
150-
(testing "testing for cats allergy -> allergic only to cats"
150+
(testing "testing for cats allergy allergic only to cats"
151151
(is (true? (allergies/allergic-to? 128 :cats)))))
152152

153153
(deftest allergic-to?_test_38
154-
(testing "testing for cats allergy -> allergic to cats and something else"
154+
(testing "testing for cats allergy allergic to cats and something else"
155155
(is (true? (allergies/allergic-to? 192 :cats)))))
156156

157157
(deftest allergic-to?_test_39
158-
(testing "testing for cats allergy -> allergic to something, but not cats"
158+
(testing "testing for cats allergy allergic to something, but not cats"
159159
(is (false? (allergies/allergic-to? 64 :cats)))))
160160

161161
(deftest allergic-to?_test_40
162-
(testing "testing for cats allergy -> allergic to everything"
162+
(testing "testing for cats allergy allergic to everything"
163163
(is (true? (allergies/allergic-to? 255 :cats)))))
164164

165165
(deftest allergies_test_1
166-
(testing "list when: -> no allergies"
166+
(testing "allergies ▶ no allergies"
167167
(is (= []
168168
(allergies/allergies 0)))))
169169

170170
(deftest allergies_test_2
171-
(testing "list when: -> just eggs"
171+
(testing "allergies ▶ just eggs"
172172
(is (= [:eggs]
173173
(allergies/allergies 1)))))
174174

175175
(deftest allergies_test_3
176-
(testing "list when: -> just peanuts"
176+
(testing "allergies ▶ just peanuts"
177177
(is (= [:peanuts]
178178
(allergies/allergies 2)))))
179179

180180
(deftest allergies_test_4
181-
(testing "list when: -> just strawberries"
181+
(testing "allergies ▶ just strawberries"
182182
(is (= [:strawberries]
183183
(allergies/allergies 8)))))
184184

185185
(deftest allergies_test_5
186-
(testing "list when: -> eggs and peanuts"
186+
(testing "allergies ▶ eggs and peanuts"
187187
(is (= [:eggs :peanuts]
188188
(allergies/allergies 3)))))
189189

190190
(deftest allergies_test_6
191-
(testing "list when: -> more than eggs but not peanuts"
191+
(testing "allergies ▶ more than eggs but not peanuts"
192192
(is (= [:eggs :shellfish]
193193
(allergies/allergies 5)))))
194194

195195
(deftest allergies_test_7
196-
(testing "list when: -> lots of stuff"
196+
(testing "allergies ▶ lots of stuff"
197197
(is (= [:strawberries :tomatoes :chocolate :pollen :cats]
198198
(allergies/allergies 248)))))
199199

200200
(deftest allergies_test_8
201-
(testing "list when: -> everything"
201+
(testing "allergies ▶ everything"
202202
(is (= [:eggs :peanuts :shellfish :strawberries :tomatoes :chocolate :pollen :cats]
203203
(allergies/allergies 255)))))
204204

205205
(deftest allergies_test_9
206-
(testing "list when: -> no allergen score parts"
206+
(testing "allergies ▶ no allergen score parts"
207207
(is (= [:eggs :shellfish :strawberries :tomatoes :chocolate :pollen :cats]
208208
(allergies/allergies 509)))))
209209

210210
(deftest allergies_test_10
211-
(testing "list when: -> no allergen score parts without highest valid score"
211+
(testing "allergies ▶ no allergen score parts without highest valid score"
212212
(is (= [:eggs]
213213
(allergies/allergies 257)))))

0 commit comments

Comments
 (0)