Add a test for string/indexof-char
This adds a test for the `string/indexof-char` instruction
This commit is contained in:
parent
b8a011c385
commit
92cdfe9e59
@ -208,4 +208,27 @@
|
|||||||
|
|
||||||
(defspec from-integer-spec 100
|
(defspec from-integer-spec 100
|
||||||
(prop/for-all [int gen/small-integer]
|
(prop/for-all [int gen/small-integer]
|
||||||
(check-from-integer int)))
|
(check-from-integer int)))
|
||||||
|
|
||||||
|
|
||||||
|
;; string/indexof-char
|
||||||
|
|
||||||
|
(defn check-indexof-char
|
||||||
|
[value char]
|
||||||
|
(let [start-state (-> state/empty-state
|
||||||
|
(state/push-to-stack :string value)
|
||||||
|
(state/push-to-stack :char char))
|
||||||
|
end-state ((:string_indexof_char @core/instruction-table) start-state)
|
||||||
|
expected-result (string/index-of value char)]
|
||||||
|
(or
|
||||||
|
(and (not expected-result)
|
||||||
|
(= (state/peek-stack end-state :string) value)
|
||||||
|
(= (state/peek-stack end-state :char) char)
|
||||||
|
(state/empty-stack? end-state :integer))
|
||||||
|
(= expected-result
|
||||||
|
(state/peek-stack end-state :integer)))))
|
||||||
|
|
||||||
|
(defspec indexof-char-spec 100
|
||||||
|
(prop/for-all [str gen/string
|
||||||
|
char gen/char]
|
||||||
|
(check-indexof-char str char)))
|
Loading…
x
Reference in New Issue
Block a user