From e21ca24d9deda942d0f29e63c6cad0b5430722c4 Mon Sep 17 00:00:00 2001 From: Erik Rauer Date: Tue, 16 Mar 2021 21:59:02 -0500 Subject: [PATCH] Add test for `string/butlast` This adds a test for the `string/butlast` instruction --- .../push/instructions/string_spec.clj | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 test/propeller/push/instructions/string_spec.clj diff --git a/test/propeller/push/instructions/string_spec.clj b/test/propeller/push/instructions/string_spec.clj new file mode 100644 index 0000000..7f5b76d --- /dev/null +++ b/test/propeller/push/instructions/string_spec.clj @@ -0,0 +1,27 @@ +(ns propeller.push.instructions.string-spec + (:require + [clojure.test.check.generators :as gen] + [clojure.test.check.properties :as prop] + [clojure.test.check.clojure-test :as ct :refer [defspec]] + [propeller.push.state :as state] + [propeller.push.core :as core] + [propeller.push.instructions.string :as string])) + + +;; string/butlast + +(defn check-butlast + [value] + (let [start-state (state/push-to-stack state/empty-state + :string + value) + end-state ((:string_butlast @core/instruction-table) start-state) + expected-result (apply str (butlast value))] + (= expected-result + (state/peek-stack end-state :string)))) + +(defspec butlast-spec 100 + (prop/for-all [s gen/string] + (check-butlast s))) + +