From f60fdb944bdea213b305102f29f862116237a324 Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Mon, 10 Jul 2023 08:15:09 +0100 Subject: [PATCH] Executing flows now works. --- src/cljc/mw_engine/flow.clj | 6 +++--- test/mw_engine/flow_test.clj | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cljc/mw_engine/flow.clj b/src/cljc/mw_engine/flow.clj index 2047802..b045cf6 100644 --- a/src/cljc/mw_engine/flow.clj +++ b/src/cljc/mw_engine/flow.clj @@ -93,7 +93,7 @@ "Return a world like this `world`, except with the quantity of the property described in this `flow` object transferred from the source of that flow to its destination." - [flow world] + [world flow] (try (let [source (get-cell world (-> flow :source :x) (-> flow :source :y)) dest (get-cell world (-> flow :destination :x) (-> flow :destination :y)) @@ -103,11 +103,11 @@ d' (assoc dest p (+ (get-num dest p) q))] (merge-cell (merge-cell world s') d')) (catch Exception e - (warn "Failed to execute flow %s: %s" flow (.getMessage e)) + (warn (format "Failed to execute flow %s: %s" flow (.getMessage e))) ;; return the world unmodified. world))) (defn execute-flows "Return a world like this `world`, but with each of these flows executed." - [flows world] + [world flows] (reduce execute world (filter #(flow? % world) flows))) \ No newline at end of file diff --git a/test/mw_engine/flow_test.clj b/test/mw_engine/flow_test.clj index 60ebcea..cfd2198 100644 --- a/test/mw_engine/flow_test.clj +++ b/test/mw_engine/flow_test.clj @@ -37,7 +37,7 @@ :property :q :quantity 2.4}] (is (flow? valid world)) - (let [transferred (execute valid world') + (let [transferred (execute world' valid) source-q (:q (get-cell transferred 0 0)) dest-q (:q (get-cell transferred 1 1))] (is (= source-q 2.9)) @@ -46,7 +46,7 @@ :destination {:x 0 :y 1} :property :q :quantity 1} - transferred (execute-flows (list valid valid2) world') + transferred (execute-flows world' (list valid valid2)) source-q (:q (get-cell transferred 0 0)) inter-q (:q (get-cell transferred 1 1)) dest-q (:q (get-cell transferred 0 1))]