From bef5a398eb206b9d0d6cb092ccc874bd93317922 Mon Sep 17 00:00:00 2001 From: Erik Rauer Date: Tue, 29 Dec 2020 16:18:45 -0600 Subject: [PATCH] Add tests for `vector/_nth` This adds tests for `vector/_nth`. --- .../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 d970071..26940c4 100644 --- a/test/propeller/push/instructions/vector_spec.clj +++ b/test/propeller/push/instructions/vector_spec.clj @@ -211,6 +211,28 @@ (gen-specs "length" check-length :vector) +;;; vector/_nth + +(defn check-nth + [value-type vect n] + (let [stack-type (keyword (str "vector_" value-type)) + start-state (state/push-to-stack + (state/push-to-stack state/empty-state + stack-type + vect) + :integer + n) + end-state (vector/_nth stack-type start-state)] + (or + (and (empty? vect) + (= (state/peek-stack end-state stack-type) + vect)) + (and + (= (get vect (mod n (count vect))) + (state/peek-stack end-state (keyword value-type))))))) + +(gen-specs "nth" check-nth :vector :integer) + ;;; vector/_subvec (defn clean-subvec-bounds