Hello,

Is there a way to make a spec that describes a map where

   - i. a key can be from a set of values and
   - ii. the value chose is used as the key for another entry
   - iii. an additional map entry is added


For example, if we had the maps in *A.*, we could generate them with the
test.check generator(s) in *B.*

I think I've just been looking at this too long and can't seem to move that
to a function argument spec. Any tips?

*A.*

{:input-key :foo
 :foo 4.5
 :b 36865}


{:input-key :bar
 :bar 9.8
 :b 47895}



*B.*

(require [clojure.spec.alpha :as s]
         [clojure.spec.gen.alpha :as g]
         [clojure.test.check.generators :as gen])

(s/def ::input-key #{:foo :bar})

(def a-tuple (g/bind (s/gen ::input-key)
                     (fn [x]
                       (g/tuple (g/return x)
                                (g/double* {:min 1.0 :infinite? false,
:NaN? false})))))

(def b-tuple (g/tuple (g/return :b)
                      (g/large-integer)))

(def my-map (gen/let [at a-tuple
                      tt b-tuple]

              (->> [:input-key (first at)]
                   (concat at tt)
                   (apply array-map))))

(g/generate my-map)



Tim Washington
Interruptsoftware.com <http://interruptsoftware.com>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to