Skip to content

Commit 93219b6

Browse files
Improve naming of extension functions
1 parent c666ad5 commit 93219b6

File tree

9 files changed

+20
-23
lines changed

9 files changed

+20
-23
lines changed

docs/GENERATORS.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ There are two ways in which you can transform test cases:
4242
To update individual test cases, define the following function:
4343

4444
```clojure
45-
(defn- transform-test-case
45+
(defn update-test-case
4646
"Update a test case"
4747
[test-case]
4848
;; function body
@@ -56,7 +56,7 @@ This example removes all but the last element of the `:path` value (shortening t
5656
```clojure
5757
(ns difference-of-squares-generator)
5858

59-
(defn- transform-test-case [test-case]
59+
(defn update-test-case [test-case]
6060
(update test-case :path #(take-last 1 %)))
6161
```
6262

@@ -65,15 +65,15 @@ This example removes all but the last element of the `:path` value (shortening t
6565
To update individual test cases, define the following function:
6666

6767
```clojure
68-
(defn- transform-test-cases
68+
(defn add-remove-test-cases
6969
"Add/remove test case(s)"
7070
[test-cases]
7171
;; function body
7272
)
7373
```
7474

7575
```exercism/note
76-
If you define _both_ functions, `transform-test-cases` is called first and `transform-test-case` second.
76+
If you define _both_ functions, `add-remove-test-cases` is called first and `update-test-case` second.
7777
```
7878

7979
### Step 4: render the test cases
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
(ns difference-of-squares-generator)
22

3-
(defn- update-path [path]
4-
(take-last 1 path))
5-
6-
(defn transform [test-cases]
7-
(map #(update % :path update-path) test-cases))
3+
(defn update-test-case [test-case]
4+
(update test-case :path #(take-last 1 %)))
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(ns high-scores-generator)
22

3-
(defn- transform-test-case [test-case]
3+
(defn update-test-case [test-case]
44
(-> test-case
55
(update-in [:input :scores] #(apply list %))
66
(update-in [:expected] #(if (vector? %) (apply list %) %))))
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(ns largest-series-product-generator)
22

3-
(defn transform-test-case [test-case]
3+
(defn update-test-case [test-case]
44
(if-let [error (get-in test-case [:expected :error])]
55
(assoc-in test-case [:expected :error] (str "^" error "$"))
66
test-case))

exercises/practice/saddle-points/.meta/generator.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
(defn- transform-input [input]
99
(update input :matrix #(if (empty? (flatten %)) [] %)))
1010

11-
(defn- transform-test-case [test-case]
11+
(defn update-test-case [test-case]
1212
(-> test-case
1313
(update :input transform-input)
1414
(update :expected transform-expected)))
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
(ns sum-of-multiples-generator)
22

3-
(defn- transform-test-case [test-case]
3+
(defn update-test-case [test-case]
44
(update-in test-case [:input :factors] #(apply list %)))

exercises/practice/wordy/.meta/generator.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"^syntax error$"
66
(str "^" error "$")))
77

8-
(defn transform-test-case [test-case]
8+
(defn update-test-case [test-case]
99
(if-let [error (get-in test-case [:expected :error])]
1010
(assoc-in test-case [:expected :error] (normalize-error test-case error))
1111
test-case))

exercises/practice/zebra-puzzle/.meta/generator.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
(:require [hbs.helper :refer [safe-str]]
33
[clojure.string :as str]))
44

5-
(defn transform-test-case [test-case]
5+
(defn update-test-case [test-case]
66
(update test-case :expected #(safe-str (str/lower-case (keyword %)))))

generators/src/templates.clj

+8-8
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@
6161
:error (get-in node [:expected :error]))
6262
(dissoc :reimplements :comments :scenarios)))
6363

64-
(defn- transform-all-test-cases [generator-ns test-cases]
65-
(if-let [transform-fn (ns-resolve generator-ns (symbol "transform"))]
66-
(transform-fn test-cases)
64+
(defn- add-remove-test-cases [generator-ns test-cases]
65+
(if-let [add-remove-test-cases-fn (ns-resolve generator-ns (symbol "add-remove-test-cases"))]
66+
(add-remove-test-cases-fn test-cases)
6767
test-cases))
6868

69-
(defn- transform-individual-test-cases [generator-ns test-cases]
70-
(if-let [transform-test-case-fn (ns-resolve generator-ns (symbol "transform-test-case"))]
71-
(mapv transform-test-case-fn test-cases)
69+
(defn- update-test-cases [generator-ns test-cases]
70+
(if-let [update-test-case-fn (ns-resolve generator-ns (symbol "update-test-case"))]
71+
(mapv update-test-case-fn test-cases)
7272
test-cases))
7373

7474
(defn- transform [slug test-cases]
@@ -77,8 +77,8 @@
7777
(let [generator-ns (symbol (str slug "-generator"))]
7878
(load-file (str transform-file))
7979
(->> test-cases
80-
(transform-all-test-cases generator-ns)
81-
(transform-individual-test-cases generator-ns)))
80+
(add-remove-test-cases generator-ns)
81+
(update-test-cases generator-ns)))
8282
test-cases)))
8383

8484
(defn- test-cases->data [slug test-cases]

0 commit comments

Comments
 (0)