From aa2ed597a175744d5f5600d61523e01c4cb20fe4 Mon Sep 17 00:00:00 2001 From: Erik Rauer Date: Wed, 30 Dec 2020 14:23:14 -0600 Subject: [PATCH] Add tests for `vector/_occurrencesof` This adds tests for `vector/_occurrencesof`. --- .../push/instructions/vector_spec.clj | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/propeller/push/instructions/vector_spec.clj b/test/propeller/push/instructions/vector_spec.clj index 26940c4..59c6a57 100644 --- a/test/propeller/push/instructions/vector_spec.clj +++ b/test/propeller/push/instructions/vector_spec.clj @@ -233,6 +233,24 @@ (gen-specs "nth" check-nth :vector :integer) +;;; vector/_occurrencesof + +(defn check-occurrencesof + [value-type vect value] + (let [stack-type (keyword (str "vector_" value-type)) + start-state (state/push-to-stack + (state/push-to-stack state/empty-state + stack-type + vect) + (keyword value-type) + value) + end-state (vector/_occurrencesof stack-type start-state) + expected-result (count (filterv #(= value %) vect))] + (= expected-result + (state/peek-stack end-state :integer)))) + +(gen-specs "occurrencesof" check-occurrencesof :vector :item) + ;;; vector/_subvec (defn clean-subvec-bounds