Skip to content

Commit 2ec7730

Browse files
Change order of operations (#823)
1 parent 5fd3012 commit 2ec7730

File tree

5 files changed

+15
-12
lines changed

5 files changed

+15
-12
lines changed
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
(ns atbash-cipher-generator)
22

33
(defn update-test-case [test-case]
4-
(-> test-case
5-
(update :path #(take-last 1 %))))
4+
(assoc test-case :context (:description test-case)))
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
(ns difference-of-squares-generator)
22

33
(defn update-test-case [test-case]
4-
(update test-case :path #(take-last 1 %)))
4+
(assoc test-case :context (:description test-case)))

exercises/practice/dnd-character/.meta/generator.clj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
(ns dnd-character-generator
2-
(:require [hbs.helper :refer [safe-str]]))
2+
(:require [hbs.helper :refer [safe-str]]
3+
[clojure.string :as str]))
34

45
(def random-abilities [:strength :dexterity :charisma :wisdom :intelligence :constitution])
56

67
(defn- expand-character-test-case [test-case]
78
(map
89
(fn [ability]
910
(-> test-case
10-
(update :path #(conj % (name ability)))
11+
(assoc :context (str/join "" (conj (:path test-case) (name ability))))
1112
(assoc :ability (safe-str (str ability))))) random-abilities))
1213

1314
(defn- expand-test-case [test-case]
1415
(case (:property test-case)
1516
"character" (expand-character-test-case test-case)
16-
"modifier" [(update test-case :path #(take-last 1 %))]
17+
"modifier" [(assoc test-case :context (:description test-case))]
1718
[test-case]))
1819

1920
(defn add-remove-test-cases [test-cases]

exercises/practice/grains/.meta/generator.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
(defn update-test-case [test-case]
99
(-> test-case
1010
(update :expected update-expected)
11-
(update :path #(take-last 1 %))))
11+
(assoc :context (:description test-case))))

generators/src/templates.clj

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@
3636
(map #(-> % (.getParentFile) (.getParentFile) (.getName)))
3737
(into (sorted-set))))
3838

39-
(defn- test-case->data [idx node]
39+
(defn- pre-process-test-case [node]
40+
(assoc node :context (str/join "" (:path node))))
41+
42+
(defn- post-process-test-case [idx node]
4043
(-> node
4144
(assoc :idx (inc idx)
42-
:context (str/join "" (:path node))
4345
:error (get-in node [:expected :error]))
44-
(dissoc :reimplements :comments :scenarios)))
46+
(dissoc :reimplements :comments)))
4547

4648
(defn- add-remove-test-cases [generator-ns test-cases]
4749
(if-let [add-remove-test-cases-fn (ns-resolve generator-ns (symbol "add-remove-test-cases"))]
@@ -64,9 +66,10 @@
6466
test-cases)))
6567

6668
(defn- test-cases->data [slug test-cases]
67-
(let [transformed (transform slug test-cases)
69+
(let [augmented (map pre-process-test-case test-cases)
70+
transformed (transform slug augmented)
6871
grouped (group-by :property transformed)
69-
data (update-vals grouped #(map-indexed test-case->data %))]
72+
data (update-vals grouped #(map-indexed post-process-test-case %))]
7073
{:test_cases data}))
7174

7275
(defn template [slug]

0 commit comments

Comments
 (0)