"Simplify" the testing for concat and subvec

This introduces some fancy macro action that allows us to skip the four calls to `(concat-spec …)` with the different generators and types.

@ErikRauer and I wrestled with this for a _long_ time today, and it turned out that it was absolutely necessary to quote the generators in `gen-type-pairs on lines 10-13. I'm not 100% sure why, but it seems that without that something (perhaps a level of macro-ness) got unwrapped too early and then it couldn't find the generator because it had lost the namespace it belonged in.

Whether this actually _simplifies_ things is really up for debate. If this is as far as we get, it's probably not worth it. If we can find a reasonable way to reduce the other sources of duplication, however, it might be worth it?
This commit is contained in:
Nic McPhee 2020-12-21 16:59:04 -06:00
parent bd59045767
commit 9028a8e174

View File

@ -6,6 +6,12 @@
[propeller.push.state :as state]
[propeller.push.instructions.vector :as vector]))
(def gen-type-pairs
[['gen/small-integer "integer"]
['gen/double "float"]
['gen/boolean "boolean"]
['gen/string "string"]])
;;; vector/_emptyvector
(defn check-empty-vector
@ -154,17 +160,15 @@
(state/peek-stack end-state stack-type))))
(defmacro concat-spec
[generator value-type]
`(defspec ~(symbol (str "concat-spec-" value-type))
100
[]
`(do ~@(for [[generator value-type] gen-type-pairs
:let [name (symbol (str "concat-spec-" value-type))]]
`(defspec ~name
(prop/for-all [first-vect# (gen/vector ~generator)
second-vect# (gen/vector ~generator)]
(check-concat first-vect# second-vect# ~value-type))))
(check-concat first-vect# second-vect# ~value-type))))))
(concat-spec gen/small-integer "integer")
(concat-spec gen/double "float")
(concat-spec gen/boolean "boolean")
(concat-spec gen/string "string")
(concat-spec)
;;; vector/_subvec
@ -199,14 +203,13 @@
(state/peek-stack end-state stack-type))))
(defmacro subvec-spec
[generator value-type]
`(defspec ~(symbol (str "subvec-spec-" value-type))
[]
`(do ~@(for [[generator value-type] gen-type-pairs
:let [name (symbol (str "subvec-spec-" value-type))]]
`(defspec ~name
(prop/for-all [vect# (gen/vector ~generator)
start# gen/small-integer
stop# gen/small-integer]
(check-subvec vect# start# stop# ~value-type))))
(check-subvec vect# start# stop# ~value-type))))))
(subvec-spec gen/small-integer "integer")
(subvec-spec gen/double "float")
(subvec-spec gen/boolean "boolean")
(subvec-spec gen/string "string")
(subvec-spec)