From 0655a5748fa26368ccdbcc0a03aef1239b245273 Mon Sep 17 00:00:00 2001 From: Erik Rauer Date: Thu, 1 Apr 2021 10:49:57 -0500 Subject: [PATCH] Add a test for `string/occurencesof_char` This adds a test for the `string/occurencesof_char` instruction. --- .../push/instructions/string_spec.clj | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/test/propeller/push/instructions/string_spec.clj b/test/propeller/push/instructions/string_spec.clj index 4f32de4..10e6343 100644 --- a/test/propeller/push/instructions/string_spec.clj +++ b/test/propeller/push/instructions/string_spec.clj @@ -234,6 +234,9 @@ (check-indexof-char str char))) +;; string/iterate + + ;; string/last (defn check-last @@ -288,4 +291,22 @@ (defspec nth-spec 100 (prop/for-all [str gen/string int gen/small-integer] - (check-nth str int))) \ No newline at end of file + (check-nth str int))) + + +;; string/occurencesof_char + +(defn check-occurencesof-char + [value char] + (let [start-state (-> state/empty-state + (state/push-to-stack :string value) + (state/push-to-stack :char char)) + end-state ((:string_occurencesof_char @core/instruction-table) start-state) + expected-result (count (filter #(= char %) value))] + (= expected-result + (state/peek-stack end-state :integer)))) + +(defspec occurencesof-char-spec 100 + (prop/for-all [str gen/string + char gen/char] + (check-occurencesof-char str char))) \ No newline at end of file