Fork me on GitHub
#clojure-spec
<
2019-08-15
>
holyjak07:08:33

Hello, when I run

(require '[clojure.spec.test.alpha :as st])
(alias 'stc 'clojure.spec.test.check)
(st/check `my-awesome-fn
          {::stc/opts {:num-tests 50, :max-size 3}})
I expect the random generated data, whenever there is a collection, to have max three elements (including collections nested in collections, speaking of lists/vectors/maps) but that is not the case. What do I wrong? Thank you!!!

alexmiller12:08:33

What are the specs?

holyjak13:08:19

The problematic argument to the function is ::account-invoices, the core of its specs is:

(s/def ::invoice-row-one (s/keys :req [::serviceType ::totalAmount ::period]))
(s/def ::invoiceRow (s/coll-of ::invoice-row-one :min-count 1 :kind sequential?))
(s/def ::invoice-group-single (s/keys :req [::name ::invoiceRow]))
(s/def ::invoiceGroup (s/coll-of ::invoice-group-single :min-count 1 :kind sequential?))
(s/def ::invoice-subscription-one (s/keys :req [::invoiceGroup ::invoiceSubscriptionUser]))
(s/def ::invoiceSubscription (s/coll-of ::invoice-subscription-one :min-count 1 :kind sequential?))
(s/def ::invoice (s/keys :req [::invoiceNumber ::billingDate ::invoiceSubscription ::period]))
(s/def ::acc+invoice (s/keys :req-un [::account ::invoice]))
(s/def ::account-invoices (s/nilable (s/every-kv string? ::acc+invoice))

alexmiller13:08:06

off the top of my head, not sure. those :min-count's may be causing something with size to be set in the constructed generator, not sure

holyjak13:08:35

Yes, that seems likely based on the docs. The question is why the generated data is larger than that....

alexmiller14:08:35

not something I have time to look at atm, feel free to file a ticket if needed

👍 4
zlrth18:08:17

is it possible to make a spec for map that has two keys, and if the value of one key matches, then the value of the other has to match something else? but if the value of the one key doesn’t match, then the spec is valid, regardless of the second value

alexmiller19:08:23

can you write a function that says yes or no to that?

alexmiller19:08:29

if so, that predicate is now a spec

alexmiller19:08:50

specs are limited only to functions ... which can do anything

zlrth19:08:00

ah of course--thanks very much

alexmiller19:08:24

perhaps a better questions is whether this is a good idea :)

4
alexmiller19:08:49

ime, you're probably doing too much

alexmiller19:08:58

don't strangle the code, just check it