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)))
|
||||
|
||||
|
||||
;; string/iterate
|
||||
|
||||
|
||||
;; string/last
|
||||
|
||||
(defn check-last
|
||||
@ -289,3 +292,21 @@
|
||||
(prop/for-all [str gen/string
|
||||
int gen/small-integer]
|
||||
(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