This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-06-09
Channels
- # aleph (4)
- # arachne (3)
- # beginners (41)
- # boot (300)
- # cider (17)
- # cljs-dev (37)
- # cljsjs (4)
- # cljsrn (5)
- # clojure (249)
- # clojure-boston (3)
- # clojure-czech (4)
- # clojure-dev (14)
- # clojure-greece (183)
- # clojure-nl (2)
- # clojure-russia (11)
- # clojure-spec (135)
- # clojure-uk (37)
- # clojurescript (56)
- # community-development (8)
- # cursive (22)
- # data-science (4)
- # datomic (150)
- # devcards (6)
- # emacs (5)
- # euroclojure (8)
- # funcool (18)
- # hoplon (29)
- # immutant (1)
- # jobs (1)
- # lambdaisland (3)
- # lein-figwheel (7)
- # leiningen (18)
- # mount (1)
- # om (81)
- # onyx (95)
- # planck (50)
- # proton (6)
- # re-frame (62)
- # reagent (2)
- # ring (1)
- # robots (1)
- # spacemacs (2)
- # specter (88)
- # test-check (32)
- # untangled (23)
- # yada (1)
if I have something like this:
(defn uuid-gen []
(g/return (-> g/uuid g/generate str)))
{:table "my-table"
:key (uuid-gen)
:rows (-> (g/hash-map
:id (uuid-gen)
:external-reference-id g/string-alphanumeric)
(g/vector 1000) g/not-empty g/generate)}
how can I ensure that uuids generated for :key
and :id
are always unique?@ag in cases where I wanted my uuids to be unique, and … thus uuid’y, I’ve just cheated by doing something like this: (gen/no-shrink (gen/fmap (fn [_] (java.util.UUID/randomUUID)) gen/int))
the gen/int bit is especially more cheaty. There may be a nicer way to do it
@lucasbradstreet: trying that, thanks
test.check will shrink down your test cases so that it can find the smallest failing case e.g. integers might shrink from 232323976 to 0, a vector might shrink from a many element vector to a small one
since all we’re doing is generating a UUID, and not using the int generated by gen/int, there’s no point in shrinking this case
Oh, I can see what your problem is in that example
Hmm, maybe not
what you’re doing wrong is actually generating a uuid sample via g/generate
and then using gen/return
try (gen/fmap str gen/uuid)
That’ll give you a uuid str generator
Your problem was that you were essentially going (gen/return "5813d2ec-c486-4428-833d-e8373910ae14”)
which will, of course, always return the same value
happy to help spread the love and the word of the church of property test
ag: lucasbradstreet: this might not be in the docstring but gen/uuid generates unique uuids
it's sort of in the docstring. It could be more clear.
@gfredericks: yeah I think I’m doing something totally wacky here… no one to blame but myself.
Yeah. I realised this which is why I investigated why the original solution didn't work. Thanks for saying that
I should also add things to the docstring for generate saying it's just a dev tool
ag: ⇑
I bet people use it for real generators more often than I was expecting
The improved suggestion will be more reproducible than the one that I suggested. The original one will give different results when you use the same seed
It's easy enough to do starting out. Try some stuff out, and then you need a generator again so you go and stick it into return or elements without realising
yeah :/
gen/sample does sound more devvy than gen/generate. I could see how people could get confused there
A docstring note would be good anyway
yeah, probably on both of them