From bd590457670b563a81d96b8c4a57b6777cefcf94 Mon Sep 17 00:00:00 2001 From: Nic McPhee Date: Mon, 21 Dec 2020 16:40:22 -0600 Subject: [PATCH] Add tests for `vector/_concat` This adds tests for `vector/_concat`. --- .../push/instructions/vector_spec.clj | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/propeller/push/instructions/vector_spec.clj b/test/propeller/push/instructions/vector_spec.clj index bbe9b29..42ee485 100644 --- a/test/propeller/push/instructions/vector_spec.clj +++ b/test/propeller/push/instructions/vector_spec.clj @@ -132,6 +132,40 @@ (indexof-spec gen/boolean "boolean") (indexof-spec gen/string "string") +;;; vector/_concat + +(defn check-concat + "Creates an otherwise empty Push state with the two given vectors on the + appropriate vector stack (assumed to be :vector_). + It then runs the vector/_concat instruction, and confirms that the + result (on the :vector_ stack) is the expected value. + The order of concatenation is that the top of the stack will be + _second_ in the concatenation, i.e., its elements will come _after_ + the elements in the vector one below it in the stack." + [first-vect second-vect value-type] + (let [stack-type (keyword (str "vector_" value-type)) + start-state (state/push-to-stack + (state/push-to-stack state/empty-state + stack-type + first-vect) + stack-type second-vect) + end-state (vector/_concat stack-type start-state)] + (= (concat second-vect first-vect) + (state/peek-stack end-state stack-type)))) + +(defmacro concat-spec + [generator value-type] + `(defspec ~(symbol (str "concat-spec-" value-type)) + 100 + (prop/for-all [first-vect# (gen/vector ~generator) + second-vect# (gen/vector ~generator)] + (check-concat first-vect# second-vect# ~value-type)))) + +(concat-spec gen/small-integer "integer") +(concat-spec gen/double "float") +(concat-spec gen/boolean "boolean") +(concat-spec gen/string "string") + ;;; vector/_subvec (defn clean-subvec-bounds