Fork me on GitHub

>magic 😢

Jakub Holý07: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!!!


What are the specs?

Jakub Holý13: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))


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

Jakub Holý13:08:35

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


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

👍 4

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


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


if so, that predicate is now a spec


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


ah of course--thanks very much


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

➕ 4

ime, you're probably doing too much


don't strangle the code, just check it