From cfe91b5ced68d4a4c75dffbeb5c0fc84c3fbd34a Mon Sep 17 00:00:00 2001 From: Erik Rauer Date: Sun, 3 Jan 2021 17:50:42 -0600 Subject: [PATCH] Add tests for `vector/_replace' This adds tests for `vector/_replace`. We might want to change `vector/_replace` to return `:ignore-instruction` when the value to be replaced is not present in the vector. Same with `vector/_remove`. --- .../push/instructions/vector_spec.clj | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/propeller/push/instructions/vector_spec.clj b/test/propeller/push/instructions/vector_spec.clj index 46230a2..5f85eec 100644 --- a/test/propeller/push/instructions/vector_spec.clj +++ b/test/propeller/push/instructions/vector_spec.clj @@ -289,6 +289,28 @@ (gen-specs "remove" check-remove :vector :item) +;;; vector/_replace + +(defn check-replace + [value-type vect toreplace replacement] + (let [stack-type (keyword (str "vector_" value-type)) + value-stack (keyword value-type) + start-state (state/push-to-stack + (state/push-to-stack + (state/push-to-stack state/empty-state + stack-type + vect) + value-stack + toreplace) + value-stack + replacement) + end-state (vector/_replace stack-type start-state) + expected-result (replace {toreplace replacement} vect)] + (= expected-result + (state/peek-stack end-state stack-type)))) + +(gen-specs "replace" check-replace :vector :item :item) + ;;; vector/_subvec (defn clean-subvec-bounds