This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-04-12
Channels
- # bangalore-clj (4)
- # beginners (77)
- # boot (71)
- # cider (10)
- # clara (1)
- # cljs-dev (52)
- # cljsjs (28)
- # cljsrn (1)
- # clojure (390)
- # clojure-dev (5)
- # clojure-india (1)
- # clojure-italy (5)
- # clojure-nl (24)
- # clojure-poland (4)
- # clojure-russia (123)
- # clojure-spec (71)
- # clojure-taiwan (2)
- # clojure-uk (8)
- # clojurescript (236)
- # core-matrix (6)
- # cursive (19)
- # datomic (16)
- # defnpodcast (2)
- # editors (1)
- # emacs (36)
- # garden (2)
- # hoplon (5)
- # jobs (1)
- # jobs-discuss (10)
- # juxt (47)
- # luminus (4)
- # lumo (6)
- # off-topic (207)
- # om (1)
- # onyx (20)
- # pedestal (40)
- # perun (2)
- # re-frame (8)
- # reagent (48)
- # ring (2)
- # ring-swagger (2)
- # specter (13)
- # unrepl (89)
- # vim (6)
@waffletower those aren't shrunk, they're small-sized
Background: https://github.com/clojure/test.check/blob/master/doc/growth-and-shrinking.md
Will check that out. Trying to get a uniform distribution. Am tempted to use the private (make-gen) and the random namespace as you do with the generator uuid.
Is there a reason that make-gen is private?
Uniform among longs?
It's private because it's usually not necessary
But we don't have a uniform long generator at the moment
Though choose is close
I'm considering adding one
I know I am young to test.check, and you have been really helpful, but I keep bumping into boundaries.
Are you using it for PBT or some other speccy thing?
In this case I am making a generator for dates
Why do you want a uniform long?
(I.e., why does that help for dates?)
using clj-time and it is convenient to generate a random date from a long rather than its constiuent parts. Want them to be evenly distributed.
(def date-8601
(gen/fmap
(fn [x] (f/unparse (f/formatters :date-time) (c/from-long x)))
gen/large-natural))
You'll get weird dates with >4 digit years that way, won't you?
I could use ints instead, but would be nice if they were uniform and not usually centered around 1970
I guess I'm trying to figure out why uniformity is important for this, especially since the domain will inevitably end up rather arbitrary
E.g., dates in the years -1000000 to 1000000
I think date & time generators end up being weird regardless :/
Its a question of control. For some data I feel a desire to turnoff the growth and shrinking mechanisms and control the output with localized RNG
gen/choose is the classic tool for turning off growth
great lead, I will check it out.
It just has edge cases outside of the 32 bit range
I was thinking of making a variant called uniform-integer that world be more robust
you are supremely helpful. thanks again
I see gen/scale as well…
Yep. gen/sized is a more general (ha!) version of that
A lot of generators that do nontrivial growth things do it by combining choose and sized
I guess I mean that those two things give you the power to completely customize growth
here's a gist of what i try to get to run: https://gist.github.com/FossiFoo/f98f2eaf920c3481d9fdf9bdeb41c420
the ":replace" works, but i thought i could just change the result of (db/select) so that it fits the spec when testing the function calling it
i know that my datomic/adi db/select will return the correct types, but i'm not sure how to put that knowledge into spec
i think an example of ":gen a map from spec names to generator overrides" in clojure.spec/instrument would help
fdef docs says "Once registered, function specs are included in doc, checked by instrument, tested by the runner clojure.spec.test/run-tests," is there such a thing as this runner?
does someone know a larger project (present on github) that uses clojure.spec? I want to see how spec is really being used. All of the small, and simple repl example can't answer the questions i have.
As noted in #clojure, it's kinda hard since most real world Clojure projects have not yet moved to 1.9.0 Alpha builds.
@wottis I like this one (in ClojureScript): https://github.com/jrheard/voke/tree/master/src/voke It's a WIP game that uses spec for its entity system. Not super large, but makes good use of fdef
s and has a few generative tests! 🙂 Maybe @jrheard can tell us a bit more about it?
wottis: Here is a list of all the projects on clojars I've found using spec: systems-toolbox, spex, oops, alia-spec, clj-edocu-users, mistakes-were-made, utangled-client, clj-edocu-help, spec, net, clj-element-type, gadjett, datomic-spec, tappit, tick, deploy-static, tick, spectrum, sails-forth, ring-spec, doh, tongue, diglett, rp-query-clj, pedestal.vase, clj-jumanpp, om-html, crucible, ctim, crucible, wheel, merlion, turbovote-admin-specs, odin, pc-message, active-status, rp-json-clj, curd, rp-util-clj, swagger-spec, invariant, functional-vaadin, untangled-client, flanders, uniontypes, dspec, schpeck, macros, replique, specific
Right, libraries that are so "popular" that they're on http://clojure-toolbox.com are: alia, cljs-oops, closp, core.typed, graphql-clj, java.jdbc, onyx, sablono, spandex, tupelo.
Is it possible to express something like (spec/keys :req-un [(spec/or ::a ::b)])
so that either :a
or :b
is present in the resulting map, but never the two at the same time?
@rovanion Not with s/keys
alone
You gotta s/and
it with a pred of that effect
i also wondered about that and i have some cases where a thing is either a or b or c or d (or ... some more)
@fossifoo "is either a or b or c or d" sounds like s/multi-spec
could be worth a look for you
@fossifoo regarding your question above about the docstring for fdef - that has already been fixed - should be clojure.spec.test/check. Where are you seeing the version pointing to run-test?
oh, probably the online clojure doc - there is actually a known problem preventing those docs from being regenerated and they are a few alphas behind. There aren’t many changes to the API since then but that’s one.
"a map from spec names to generator overrides" i read that as {:some/spec (gen/string)}
or such , but that didn't seem to work for me
i always got the "could'nt generate in 100 tries" error with that. don't have the actual error on hand
(fn [] gen/string)
I think
any advice on spec-ing async functions?
also, is this sort of redef-ing inside of a spec bad form?
(s/fdef ::shopify-api!
:args (s/cat :opts ::shopify-api-opts)
:ret nil?
)
(with-redefs [org.httpkit.client/get (fn [a b c] nil)]
(s/valid? ::shopify-api! shopify-api!))