Add a test for string/occurencesof_char
This adds a test for the `string/occurencesof_char` instruction.
This commit is contained in:
parent
695e08506e
commit
0655a5748f
@ -234,6 +234,9 @@
|
|||||||
(check-indexof-char str char)))
|
(check-indexof-char str char)))
|
||||||
|
|
||||||
|
|
||||||
|
;; string/iterate
|
||||||
|
|
||||||
|
|
||||||
;; string/last
|
;; string/last
|
||||||
|
|
||||||
(defn check-last
|
(defn check-last
|
||||||
@ -288,4 +291,22 @@
|
|||||||
(defspec nth-spec 100
|
(defspec nth-spec 100
|
||||||
(prop/for-all [str gen/string
|
(prop/for-all [str gen/string
|
||||||
int gen/small-integer]
|
int gen/small-integer]
|
||||||
(check-nth str int)))
|
(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)))
|
Loading…
x
Reference in New Issue
Block a user