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

Lines changed: 19 additions & 29 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 12 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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."

0 commit comments

Comments
 (0)