diff --git a/test/propeller/push/instructions/string_spec.clj b/test/propeller/push/instructions/string_spec.clj index 622f530..4f32de4 100644 --- a/test/propeller/push/instructions/string_spec.clj +++ b/test/propeller/push/instructions/string_spec.clj @@ -266,4 +266,26 @@ (defspec length-spec 100 (prop/for-all [str gen/string] - (check-length str))) \ No newline at end of file + (check-length str))) + + +;; string/nth + +(defn check-nth + [value n] + (let [start-state (-> state/empty-state + (state/push-to-stack :string value) + (state/push-to-stack :integer n)) + end-state ((:string_nth @core/instruction-table) start-state)] + (or + (and (empty? value) + (state/empty-stack? end-state :char) + (= value (state/peek-stack end-state :string)) + (= n (state/peek-stack end-state :integer))) + (= (nth value (mod n (count value))) + (state/peek-stack end-state :char))))) + +(defspec nth-spec 100 + (prop/for-all [str gen/string + int gen/small-integer] + (check-nth str int))) \ No newline at end of file