From ab1f6d4396f9392c118dc2c2265f7beb8f825452 Mon Sep 17 00:00:00 2001 From: Nic McPhee Date: Fri, 18 Dec 2020 17:02:18 -0600 Subject: [PATCH] Add tests for `vector/_last` This adds test.check tests for `vector/_last`. This is _really_ similar to `vector/_first` (and the other vector tests), so I think there are definitely ways to extract common logic from these. --- .../push/instructions/vector_spec.clj | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/propeller/push/instructions/vector_spec.clj b/test/propeller/push/instructions/vector_spec.clj index 33a8009..bbe9b29 100644 --- a/test/propeller/push/instructions/vector_spec.clj +++ b/test/propeller/push/instructions/vector_spec.clj @@ -60,6 +60,36 @@ (first-spec gen/boolean "boolean") (first-spec gen/string "string") +;;; vector/_last + +(defn check-last + [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/_last stack-type start-state)] + (or + (and (empty? vect) + (= (state/peek-stack end-state stack-type) + vect)) + (and + (= (last vect) + (state/peek-stack end-state (keyword value-type))) + (state/empty-stack? end-state stack-type))))))) + +(defmacro last-spec + [generator value-type] + `(defspec ~(symbol (str "last-spec-" value-type)) + 100 + (check-last ~generator ~value-type))) + +(last-spec gen/small-integer "integer") +(last-spec gen/double "float") +(last-spec gen/boolean "boolean") +(last-spec gen/string "string") + ;;; vector/_indexof (defn check-expected-index