Skip to content

Commit ca77a6d

Browse files
Simplify example file structure (#720)
* Simplify example file structure * Add back example lists file for list-ops
1 parent 7e3903f commit ca77a6d

File tree

168 files changed

+121
-179
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

168 files changed

+121
-179
lines changed

_generators/list-ops-generator.clj

+19-29
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
(second
1818
(str/split (:metadata data) #"="))
1919

20-
(defn get-meta
20+
(defn get-meta
2121
"Returns a vector containing the exercise title and blurb"
2222
[data]
2323
(mapv last
24-
(map #(map str/trim (str/split % #"="))
25-
(str/split-lines (:metadata data)))))
24+
(map #(map str/trim (str/split % #"="))
25+
(str/split-lines (:metadata data)))))
2626

2727
(defn init-deps! [data]
2828
(fs/create-dirs (fs/path "exercises" "practice"
@@ -38,8 +38,7 @@
3838
:exec-fn cognitect.test-runner.api/test}}}"))
3939

4040
(comment
41-
(init-deps! data)
42-
)
41+
(init-deps! data))
4342

4443
(defn init-lein! [data]
4544
(let [slug (:exercise (:canonical-data data))]
@@ -52,8 +51,7 @@
5251
"))))
5352

5453
(comment
55-
(init-lein! data)
56-
)
54+
(init-lein! data))
5755

5856
(defn test-ns-form [data]
5957
(str "(ns " (:exercise data) "-test
@@ -67,14 +65,13 @@
6765
(let [[args body] (str/split s #"->")
6866
arg-strs (mapv str (edn/read-string args))
6967
[arg1 op arg2] (str/split (str/trim body) #"\s")]
70-
(str "(fn [" (apply str (interpose " " arg-strs)) "] "
68+
(str "(fn [" (apply str (interpose " " arg-strs)) "] "
7169
"(" op " " arg1 " " arg2 "))")))
7270

7371
(comment
74-
(trans-fn "(x) -> x + 1")
72+
(trans-fn "(x) -> x + 1")
7573
(trans-fn "(x, y) -> x * y")
76-
(trans-fn "(acc, el) -> el * acc")
77-
)
74+
(trans-fn "(acc, el) -> el * acc"))
7875

7976
(defn testing-form [slug test-case]
8077
(let [property (symbol (str slug "/" (:property test-case)))
@@ -85,8 +82,7 @@
8582
(reverse (into (list property) args)) ")))")))
8683

8784
(comment
88-
(testing-form "list-ops" (first (:cases (first (:cases (:canonical-data data))))))
89-
)
85+
(testing-form "list-ops" (first (:cases (first (:cases (:canonical-data data)))))))
9086

9187
(defn testing-forms
9288
"Outputs a sequence of the test cases for a given property name
@@ -98,8 +94,7 @@
9894
(map #(testing-form (:exercise (:canonical-data data)) %) test-cases)))
9995

10096
(comment
101-
(testing-forms "append" data)
102-
)
97+
(testing-forms "append" data))
10398

10499
(defn deftest-forms [data]
105100
(for [property (distinct (map :property (mapcat :cases
@@ -110,8 +105,7 @@
110105
")")))
111106

112107
(comment
113-
(deftest-forms data)
114-
)
108+
(deftest-forms data))
115109

116110
(defn init-tests! [data]
117111
(let [path (fs/path "exercises" "practice"
@@ -127,8 +121,7 @@
127121
(deftest-forms data)))))))
128122

129123
(comment
130-
(init-tests! data)
131-
)
124+
(init-tests! data))
132125

133126
(defn init-src! [data]
134127
(spit (str (fs/file "exercises" "practice" (:exercise (:canonical-data data)) "src"
@@ -141,8 +134,7 @@
141134
(str "(defn " property " []\n )")))))))
142135

143136
(comment
144-
(init-src! data)
145-
)
137+
(init-src! data))
146138

147139
(defn init-description! [data]
148140
(let [path ["exercises" "practice" (:exercise (:canonical-data data)) ".docs"]]
@@ -152,26 +144,24 @@
152144
(:description data)))))
153145

154146
(comment
155-
(init-description! data)
156-
)
147+
(init-description! data))
157148

158149
(defn config [data author blurb]
159150
(let [slug (:exercise (:canonical-data data))]
160151
{:authors [author],
161152
:contributors [],
162-
:files {:solution [(str "src/" (str/replace slug "-" "_") ".clj")],
163-
:test [(str "test/" (str/replace slug "-" "_") "_test.clj")],
164-
:example [".meta/src/example.clj"]},
153+
:files {:solution [(str "src/" (str/replace slug "-" "_") ".clj")],
154+
:test [(str "test/" (str/replace slug "-" "_") "_test.clj")],
155+
:example [".meta/example.clj"]},
165156
:blurb blurb}))
166157

167158
(defn init-config! [data]
168159
(let [path ["exercises" "practice" (:exercise (:canonical-data data)) ".meta"]]
169160
(when-not (fs/directory? (apply fs/path path))
170-
(fs/create-dirs (apply fs/path (conj path "src")))
161+
(fs/create-dirs (apply fs/path (conj path "src")))
171162
(spit (str (apply fs/file (conj path "config.json")))
172163
(json/generate-string (config data "porkostomus" (last (get-meta data)))
173164
{:pretty true})))))
174165

175166
(comment
176-
(init-config! data)
177-
)
167+
(init-config! data))

_generators/zipper-generator.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
:contributors [],
125125
:files {:solution [(str "src/" (str/replace slug "-" "_") ".clj")],
126126
:test [(str "test/" (str/replace slug "-" "_") "_test.clj")],
127-
:example [".meta/src/example.clj"]},
127+
:example [".meta/example.clj"]},
128128
:blurb blurb}))
129129

130130
(defn init-config! [data]

_test/check_exercises.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
:let [slug (exercise "slug")
1111
path-to-exercise (partial str "exercises/practice/" slug "/")
1212
exercise-tests (symbol (str slug "-test"))]]
13-
(load-file (path-to-exercise ".meta/src/example.clj"))
13+
(load-file (path-to-exercise ".meta/example.clj"))
1414
(load-file (path-to-exercise "test/" (->snake_case slug) "_test.clj"))
1515
(is (successful? (run-tests exercise-tests)))))

config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"test/%{snake_slug}_test.clj"
2727
],
2828
"example": [
29-
".meta/src/example.clj"
29+
".meta/example.clj"
3030
],
3131
"exemplar": [
3232
".meta/exemplar.clj"

exercises/practice/accumulate/.meta/config.json

+4-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
2-
"authors": [
3-
"geofflane"
4-
],
2+
"authors": ["geofflane"],
53
"contributors": [
64
"AndreaCrotti",
75
"canweriotnow",
@@ -14,15 +12,9 @@
1412
"yurrriq"
1513
],
1614
"files": {
17-
"solution": [
18-
"src/accumulate.clj"
19-
],
20-
"test": [
21-
"test/accumulate_test.clj"
22-
],
23-
"example": [
24-
".meta/src/example.clj"
25-
]
15+
"solution": ["src/accumulate.clj"],
16+
"test": ["test/accumulate_test.clj"],
17+
"example": [".meta/example.clj"]
2618
},
2719
"blurb": "Implement the `accumulate` operation, which, given a collection and an operation to perform on each element of the collection, returns a new collection containing the result of applying that operation to each element of the input collection.",
2820
"source": "Conversation with James Edward Gray II",

exercises/practice/acronym/.meta/config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"test/acronym_test.clj"
1616
],
1717
"example": [
18-
".meta/src/example.clj"
18+
".meta/example.clj"
1919
]
2020
},
2121
"blurb": "Convert a long phrase to its acronym.",

exercises/practice/all-your-base/.meta/config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"test/all_your_base_test.clj"
1616
],
1717
"example": [
18-
".meta/src/example.clj"
18+
".meta/example.clj"
1919
]
2020
},
2121
"blurb": "Convert a number, represented as a sequence of digits in one base, to any other base."

exercises/practice/allergies/.meta/config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"test/allergies_test.clj"
2222
],
2323
"example": [
24-
".meta/src/example.clj"
24+
".meta/example.clj"
2525
]
2626
},
2727
"blurb": "Given a person's allergy score, determine whether or not they're allergic to a given item, and their full list of allergies.",

exercises/practice/anagram/.meta/config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"test/anagram_test.clj"
2727
],
2828
"example": [
29-
".meta/src/example.clj"
29+
".meta/example.clj"
3030
]
3131
},
3232
"blurb": "Given a word and a list of possible anagrams, select the correct sublist.",

exercises/practice/armstrong-numbers/.meta/config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"test/armstrong_numbers_test.clj"
1919
],
2020
"example": [
21-
".meta/src/example.clj"
21+
".meta/example.clj"
2222
]
2323
},
2424
"blurb": "Determine if a number is an Armstrong number.",

exercises/practice/atbash-cipher/.meta/config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"test/atbash_cipher_test.clj"
2121
],
2222
"example": [
23-
".meta/src/example.clj"
23+
".meta/example.clj"
2424
]
2525
},
2626
"blurb": "Create an implementation of the atbash cipher, an ancient encryption system created in the Middle East.",

exercises/practice/bank-account/.meta/config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"test/bank_account_test.clj"
2222
],
2323
"example": [
24-
".meta/src/example.clj"
24+
".meta/example.clj"
2525
]
2626
},
2727
"blurb": "Simulate a bank account supporting opening/closing, withdraws, and deposits of money. Watch out for concurrent transactions!"

exercises/practice/beer-song/.meta/config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"test/beer_song_test.clj"
2626
],
2727
"example": [
28-
".meta/src/example.clj"
28+
".meta/example.clj"
2929
]
3030
},
3131
"blurb": "Produce the lyrics to that beloved classic, that field-trip favorite: 99 Bottles of Beer on the Wall.",

exercises/practice/binary-search-tree/.meta/config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"test/binary_search_tree_test.clj"
2121
],
2222
"example": [
23-
".meta/src/example.clj"
23+
".meta/example.clj"
2424
]
2525
},
2626
"blurb": "Insert and search for numbers in a binary tree.",

exercises/practice/binary-search/.meta/config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"test/binary_search_test.clj"
2121
],
2222
"example": [
23-
".meta/src/example.clj"
23+
".meta/example.clj"
2424
]
2525
},
2626
"blurb": "Implement a binary search algorithm.",

exercises/practice/binary/.meta/config.json

+4-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
2-
"authors": [
3-
"rubysolo"
4-
],
2+
"authors": ["rubysolo"],
53
"contributors": [
64
"AndreaCrotti",
75
"canweriotnow",
@@ -14,15 +12,9 @@
1412
"yurrriq"
1513
],
1614
"files": {
17-
"solution": [
18-
"src/binary.clj"
19-
],
20-
"test": [
21-
"test/binary_test.clj"
22-
],
23-
"example": [
24-
".meta/src/example.clj"
25-
]
15+
"solution": ["src/binary.clj"],
16+
"test": ["test/binary_test.clj"],
17+
"example": [".meta/example.clj"]
2618
},
2719
"blurb": "Convert a binary number, represented as a string (e.g. '101010'), to its decimal equivalent using first principles.",
2820
"source": "All of Computer Science",

exercises/practice/bob/.meta/config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"test/bob_test.clj"
3030
],
3131
"example": [
32-
".meta/src/example.clj"
32+
".meta/example.clj"
3333
]
3434
},
3535
"blurb": "Bob is a lackadaisical teenager. In conversation, his responses are very limited.",

exercises/practice/change/.meta/config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"test/change_test.clj"
1717
],
1818
"example": [
19-
".meta/src/example.clj"
19+
".meta/example.clj"
2020
]
2121
},
2222
"blurb": "Correctly determine change to be given using the least number of coins.",

exercises/practice/clock/.meta/config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"test/clock_test.clj"
1515
],
1616
"example": [
17-
".meta/src/example.clj"
17+
".meta/example.clj"
1818
]
1919
},
2020
"blurb": "Implement a clock that handles times without dates.",

exercises/practice/collatz-conjecture/.meta/config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"test/collatz_conjecture_test.clj"
1515
],
1616
"example": [
17-
".meta/src/example.clj"
17+
".meta/example.clj"
1818
]
1919
},
2020
"blurb": "Calculate the number of steps to reach 1 using the Collatz conjecture.",

exercises/practice/complex-numbers/.meta/config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"test/complex_numbers_test.clj"
1414
],
1515
"example": [
16-
".meta/src/example.clj"
16+
".meta/example.clj"
1717
]
1818
},
1919
"blurb": "Implement complex numbers.",

exercises/practice/crypto-square/.meta/config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"test/crypto_square_test.clj"
2323
],
2424
"example": [
25-
".meta/src/example.clj"
25+
".meta/example.clj"
2626
]
2727
},
2828
"blurb": "Implement the classic method for composing secret messages called a square code.",

exercises/practice/diamond/.meta/config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"test/diamond_test.clj"
1616
],
1717
"example": [
18-
".meta/src/example.clj"
18+
".meta/example.clj"
1919
]
2020
},
2121
"blurb": "Given a letter, print a diamond starting with 'A' with the supplied letter at the widest point.",

exercises/practice/difference-of-squares/.meta/config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"test/difference_of_squares_test.clj"
2222
],
2323
"example": [
24-
".meta/src/example.clj"
24+
".meta/example.clj"
2525
]
2626
},
2727
"blurb": "Find the difference between the square of the sum and the sum of the squares of the first N natural numbers.",

exercises/practice/dominoes/.meta/config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"test/dominoes_test.clj"
1515
],
1616
"example": [
17-
".meta/src/example.clj"
17+
".meta/example.clj"
1818
]
1919
},
2020
"blurb": "Make a chain of dominoes."

0 commit comments

Comments
 (0)