This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-06-25
Channels
- # announcements (1)
- # beginners (338)
- # calva (41)
- # cider (19)
- # cljdoc (10)
- # cljsrn (6)
- # clojure (116)
- # clojure-europe (15)
- # clojure-italy (25)
- # clojure-nl (5)
- # clojure-spec (19)
- # clojure-uk (52)
- # clojurescript (99)
- # clojurex (14)
- # cursive (47)
- # data-science (1)
- # datomic (5)
- # duct (1)
- # figwheel (13)
- # fulcro (58)
- # graalvm (93)
- # jobs (3)
- # joker (9)
- # luminus (4)
- # nrepl (21)
- # off-topic (41)
- # pathom (25)
- # re-frame (7)
- # reitit (8)
- # ring-swagger (13)
- # tools-deps (13)
Hi everyone, I’m trying to to write a spect that has “relationships” to other specs. (apologies for the language, I’m still new to spec). For example, a group has a total number of people, number of active people and number of inactive people. active-people + inactive-people = total num of people
. I can write a spec for the total number of people but how do I use that spec for in the spec for both inactive and active. Also how does that work with generators? Ultimately I would like to generate a group where total
, active
and inactive
are set.
@miguelb Are these specs all used together in a map?
not sure if this is the right way to go about it, define each part and then compose together
(s/and (s/keys :req [::active-people ::inactive-people ::total-people]) #(= (::total-people %) (+ (::active-people %) (::inactive-people %))))
You can only apply relationship predicates to something that contains all the various related keys.
However, I would question the model design: since that's an invariant that should always hold, you don't need all three values (and probably should not try to have all three). Any two gives you all the information you need.
the default spec generators will not find something that satisfies the invariant within 100 tries
Yes, that's another reason that I think it would be easier without the constrained total-people
number
If you just have active and inactive, then regular generators will work
(since there's no need for an additional constraint)