diff --git a/docs/GENERATORS.md b/docs/GENERATORS.md index 385251a4a..b22a8a658 100644 --- a/docs/GENERATORS.md +++ b/docs/GENERATORS.md @@ -7,7 +7,7 @@ It uses the fact that most exercises defined in the [problem-specifications repo To generate a practice exercise's tests, the test generator: -1. Reads the exercise's test cases from its [`canonical-data.json` file] +1. Reads the exercise's test cases from its `canonical-data.json` file 2. Uses `tests.toml` file to omit and excluded test cases 3. Transforms the test cases (optional) 4. Renders the test cases using the exercise's generator template @@ -42,7 +42,7 @@ There are two ways in which you can transform test cases: To update individual test cases, define the following function: ```clojure -(defn- transform-test-case +(defn update-test-case "Update a test case" [test-case] ;; function body @@ -56,16 +56,16 @@ This example removes all but the last element of the `:path` value (shortening t ```clojure (ns difference-of-squares-generator) -(defn- transform-test-case [test-case] +(defn update-test-case [test-case] (update test-case :path #(take-last 1 %))) ``` #### Add or remove test case(s) -To update individual test cases, define the following function: +To add or remove test cases, define the following function: ```clojure -(defn- transform-test-cases +(defn add-remove-test-cases "Add/remove test case(s)" [test-cases] ;; function body @@ -73,7 +73,7 @@ To update individual test cases, define the following function: ``` ```exercism/note -If you define _both_ functions, `transform-test-cases` is called first and `transform-test-case` second. +If you define _both_ functions, `add-remove-test-cases` is called first and `update-test-case` second. ``` ### Step 4: render the test cases diff --git a/exercises/practice/difference-of-squares/.meta/generator.clj b/exercises/practice/difference-of-squares/.meta/generator.clj index 7facb501a..232f5850f 100644 --- a/exercises/practice/difference-of-squares/.meta/generator.clj +++ b/exercises/practice/difference-of-squares/.meta/generator.clj @@ -1,7 +1,4 @@ (ns difference-of-squares-generator) -(defn- update-path [path] - (take-last 1 path)) - -(defn transform [test-cases] - (map #(update % :path update-path) test-cases)) +(defn update-test-case [test-case] + (update test-case :path #(take-last 1 %))) diff --git a/exercises/practice/high-scores/.meta/generator.clj b/exercises/practice/high-scores/.meta/generator.clj index 0e4009cd9..ea7c28863 100644 --- a/exercises/practice/high-scores/.meta/generator.clj +++ b/exercises/practice/high-scores/.meta/generator.clj @@ -1,6 +1,6 @@ (ns high-scores-generator) -(defn- transform-test-case [test-case] +(defn update-test-case [test-case] (-> test-case (update-in [:input :scores] #(apply list %)) (update-in [:expected] #(if (vector? %) (apply list %) %)))) diff --git a/exercises/practice/largest-series-product/.meta/generator.clj b/exercises/practice/largest-series-product/.meta/generator.clj index 8654d9a58..8273aec76 100644 --- a/exercises/practice/largest-series-product/.meta/generator.clj +++ b/exercises/practice/largest-series-product/.meta/generator.clj @@ -1,6 +1,6 @@ (ns largest-series-product-generator) -(defn transform-test-case [test-case] +(defn update-test-case [test-case] (if-let [error (get-in test-case [:expected :error])] (assoc-in test-case [:expected :error] (str "^" error "$")) test-case)) diff --git a/exercises/practice/saddle-points/.meta/generator.clj b/exercises/practice/saddle-points/.meta/generator.clj index 9d009bddb..5d18a8d53 100644 --- a/exercises/practice/saddle-points/.meta/generator.clj +++ b/exercises/practice/saddle-points/.meta/generator.clj @@ -8,7 +8,7 @@ (defn- transform-input [input] (update input :matrix #(if (empty? (flatten %)) [] %))) -(defn- transform-test-case [test-case] +(defn update-test-case [test-case] (-> test-case (update :input transform-input) (update :expected transform-expected))) diff --git a/exercises/practice/sum-of-multiples/.meta/generator.clj b/exercises/practice/sum-of-multiples/.meta/generator.clj index d6e81c9b9..3252a9278 100644 --- a/exercises/practice/sum-of-multiples/.meta/generator.clj +++ b/exercises/practice/sum-of-multiples/.meta/generator.clj @@ -1,4 +1,4 @@ (ns sum-of-multiples-generator) -(defn- transform-test-case [test-case] +(defn update-test-case [test-case] (update-in test-case [:input :factors] #(apply list %))) diff --git a/exercises/practice/wordy/.meta/generator.clj b/exercises/practice/wordy/.meta/generator.clj index af53699bb..d24d1970b 100644 --- a/exercises/practice/wordy/.meta/generator.clj +++ b/exercises/practice/wordy/.meta/generator.clj @@ -5,7 +5,7 @@ "^syntax error$" (str "^" error "$"))) -(defn transform-test-case [test-case] +(defn update-test-case [test-case] (if-let [error (get-in test-case [:expected :error])] (assoc-in test-case [:expected :error] (normalize-error test-case error)) test-case)) diff --git a/exercises/practice/zebra-puzzle/.meta/generator.clj b/exercises/practice/zebra-puzzle/.meta/generator.clj index 733dd7675..f7a36db62 100644 --- a/exercises/practice/zebra-puzzle/.meta/generator.clj +++ b/exercises/practice/zebra-puzzle/.meta/generator.clj @@ -2,5 +2,5 @@ (:require [hbs.helper :refer [safe-str]] [clojure.string :as str])) -(defn transform-test-case [test-case] +(defn update-test-case [test-case] (update test-case :expected #(safe-str (str/lower-case (keyword %))))) diff --git a/generators/src/templates.clj b/generators/src/templates.clj index 384aeaf32..990e7aefc 100644 --- a/generators/src/templates.clj +++ b/generators/src/templates.clj @@ -61,14 +61,14 @@ :error (get-in node [:expected :error])) (dissoc :reimplements :comments :scenarios))) -(defn- transform-all-test-cases [generator-ns test-cases] - (if-let [transform-fn (ns-resolve generator-ns (symbol "transform"))] - (transform-fn test-cases) +(defn- add-remove-test-cases [generator-ns test-cases] + (if-let [add-remove-test-cases-fn (ns-resolve generator-ns (symbol "add-remove-test-cases"))] + (add-remove-test-cases-fn test-cases) test-cases)) -(defn- transform-individual-test-cases [generator-ns test-cases] - (if-let [transform-test-case-fn (ns-resolve generator-ns (symbol "transform-test-case"))] - (mapv transform-test-case-fn test-cases) +(defn- update-test-cases [generator-ns test-cases] + (if-let [update-test-case-fn (ns-resolve generator-ns (symbol "update-test-case"))] + (mapv update-test-case-fn test-cases) test-cases)) (defn- transform [slug test-cases] @@ -77,8 +77,8 @@ (let [generator-ns (symbol (str slug "-generator"))] (load-file (str transform-file)) (->> test-cases - (transform-all-test-cases generator-ns) - (transform-individual-test-cases generator-ns))) + (add-remove-test-cases generator-ns) + (update-test-cases generator-ns))) test-cases))) (defn- test-cases->data [slug test-cases]