Repository: exercism/clojure
Pull request #473 (2022-04-21 22:32:20)

remove dev workflow
CI has been failing since features were added to the test runner and I believe it was related to a conditional development workflow in `test.clj` that doesn't belong there anyway. It was remaining from when I developed the CI script and it was actually preventing a proper integration test with the `clojure-test-runner` repo as was intended. This change simply hardcodes the `root` and `test-runner-dir` locations to where they are in prod.


Patch:
diff --git a/exercises/practice/change/.meta/src/example.clj b/exercises/practice/change/.meta/src/example.clj
index 937c606..c1fd1ce 100644
--- a/exercises/practice/change/.meta/src/example.clj
+++ b/exercises/practice/change/.meta/src/example.clj
@@ -1,14 +1,24 @@
 (ns change)
 
-(defn issue [sum coins]
-  (when (or (neg? sum) (and (pos? sum) (every? #(< sum %) coins)))
-    (throw (IllegalArgumentException. "cannot change")))
-  (let [coins (sort coins)
-        all-amounts (reduce (fn [cached-amounts amount]
-                              (->> coins
-                                   (filter #(<= % amount))
-                                   (map #(conj (cached-amounts (- amount %) []) %))
-                                   (apply min-key count)
-                                   (assoc cached-amounts amount)))
-                            {} (range 1 (inc sum)))]
-    (all-amounts sum)))
+(def algo
+  (memoize (fn [amount coins]
+             (let [smaller (filter #(<= % amount) coins)]
+               (if (empty? smaller) [amount]
+                 (apply min-key
+                        count
+                        ; check if valid solution, i.e. the final amount was zero
+                        (filter (comp zero? first)
+                                (map
+                                  (fn [coin]
+                                    (concat
+                                      (algo (rem amount coin) smaller)
+                                      (repeat (quot amount coin) coin)))
+                                  smaller))))))))
+
+(defn issue [amount coins] 
+  (try
+    (let [[x & xs] (algo amount coins)]
+      (if (zero? x) xs
+        (throw (IllegalArgumentException. "cannot change"))))
+    ; thrown by apply min-key if we don't have the right coins to issue change
+    (catch clojure.lang.ArityException e (throw (IllegalArgumentException. "cannot change")))))


Test patch:
diff --git a/exercises/practice/change/test/change_test.clj b/exercises/practice/change/test/change_test.clj
index 7e40112..48c8495 100644
--- a/exercises/practice/change/test/change_test.clj
+++ b/exercises/practice/change/test/change_test.clj
@@ -32,3 +32,7 @@
 (deftest cannot-find-negative-change-values
   (is (thrown-with-msg? IllegalArgumentException #"cannot change"
                         (issue -5 #{1 2 5}))))
+
+(deftest error-testing-for-no-valid-change
+  (is (thrown-with-msg? IllegalArgumentException #"cannot change"
+                        (issue 10 #{20 8 3}))))
diff --git a/test.clj b/test.clj
index a81f960..56960bd 100755
--- a/test.clj
+++ b/test.clj
@@ -6,20 +6,9 @@
  '[clojure.java.shell :as shell]
  '[clojure.java.io :as io])
 
-(defn clean-path [path]
-  (if (str/ends-with? path "/")
-    path
-    (str path "/")))
+(def root "/github/workspace/main/")
 
-(def root 
-  (clean-path (if (.exists (io/file (str (clean-path (first *command-line-args*)) "config.json")))
-                (first *command-line-args*)
-                "/github/workspace/main/")))
-
-(def test-runner-dir 
-  (clean-path (if (.exists (io/file (str (clean-path (first *command-line-args*)) "test-runner.clj")))
-                (first *command-line-args*)
-                  "/github/workspace/clojure-test-runner/")))
+(def test-runner-dir "/github/workspace/clojure-test-runner/")
 
 (defn- ->snake_case [s] (str/replace s \- \_))