From f2eecc774fc7dd9c3a5ac787ada81c0e21917822 Mon Sep 17 00:00:00 2001 From: Nic McPhee Date: Thu, 17 Dec 2020 18:42:57 -0600 Subject: [PATCH] Add tests for `vector/_first` These turned up an oversight in the implementation in `vector/_first` that is addressed in the next commit. --- .../push/instructions/vector_spec.clj | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/propeller/push/instructions/vector_spec.clj b/test/propeller/push/instructions/vector_spec.clj index bec11b0..33a8009 100644 --- a/test/propeller/push/instructions/vector_spec.clj +++ b/test/propeller/push/instructions/vector_spec.clj @@ -6,6 +6,8 @@ [propeller.push.state :as state] [propeller.push.instructions.vector :as vector])) +;;; vector/_emptyvector + (defn check-empty-vector [generator value-type] (let [stack-type (keyword (str "vector_" value-type))] @@ -28,6 +30,38 @@ (empty-vector-spec gen/boolean "boolean") (empty-vector-spec gen/string "string") +;;; vector/_first + +(defn check-first + [generator value-type] + (let [stack-type (keyword (str "vector_" value-type))] + (prop/for-all [vect (gen/vector generator)] + (let [start-state (state/push-to-stack state/empty-state + stack-type + vect) + end-state (vector/_first stack-type start-state)] + (or + (and (empty? vect) + (= (state/peek-stack end-state stack-type) + vect)) + (and + (= (first vect) + (state/peek-stack end-state (keyword value-type))) + (state/empty-stack? end-state stack-type))))))) + +(defmacro first-spec + [generator value-type] + `(defspec ~(symbol (str "first-spec-" value-type)) + 100 + (check-first ~generator ~value-type))) + +(first-spec gen/small-integer "integer") +(first-spec gen/double "float") +(first-spec gen/boolean "boolean") +(first-spec gen/string "string") + +;;; vector/_indexof + (defn check-expected-index "Creates an otherwise empty Push state with the given vector on the appropriate vector stack (assumed to be :vector_), and @@ -68,6 +102,8 @@ (indexof-spec gen/boolean "boolean") (indexof-spec gen/string "string") +;;; vector/_subvec + (defn clean-subvec-bounds [start stop vect-size] (let [start (max 0 start)