Fork me on GitHub
#clojure-spec
<
2017-04-12
>
gfredericks00:04:38

@waffletower those aren't shrunk, they're small-sized

waffletower00:04:15

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.

waffletower00:04:36

Is there a reason that make-gen is private?

gfredericks00:04:40

Uniform among longs?

gfredericks00:04:54

It's private because it's usually not necessary

gfredericks00:04:16

But we don't have a uniform long generator at the moment

gfredericks00:04:21

Though choose is close

gfredericks00:04:35

I'm considering adding one

waffletower00:04:47

I know I am young to test.check, and you have been really helpful, but I keep bumping into boundaries.

gfredericks00:04:13

Are you using it for PBT or some other speccy thing?

waffletower00:04:40

In this case I am making a generator for dates

gfredericks00:04:52

Why do you want a uniform long?

gfredericks00:04:11

(I.e., why does that help for dates?)

waffletower00:04:59

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.

waffletower00:04:09

(def date-8601
  (gen/fmap
   (fn [x] (f/unparse (f/formatters :date-time) (c/from-long x)))
   gen/large-natural))

gfredericks00:04:36

You'll get weird dates with >4 digit years that way, won't you?

waffletower00:04:41

I could use ints instead, but would be nice if they were uniform and not usually centered around 1970

gfredericks00:04:43

I guess I'm trying to figure out why uniformity is important for this, especially since the domain will inevitably end up rather arbitrary

gfredericks00:04:05

E.g., dates in the years -1000000 to 1000000

gfredericks00:04:47

I think date & time generators end up being weird regardless :/

waffletower00:04:50

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

gfredericks00:04:35

gen/choose is the classic tool for turning off growth

waffletower00:04:10

great lead, I will check it out.

gfredericks00:04:15

It just has edge cases outside of the 32 bit range

gfredericks00:04:38

I was thinking of making a variant called uniform-integer that world be more robust

waffletower00:04:16

you are supremely helpful. thanks again

waffletower00:04:35

I see gen/scale as well…

gfredericks00:04:01

Yep. gen/sized is a more general (ha!) version of that

gfredericks00:04:40

A lot of generators that do nontrivial growth things do it by combining choose and sized

gfredericks00:04:28

I guess I mean that those two things give you the power to completely customize growth

fossifoo00:04:04

does sb have working examples of instrument with :stub & :gen or :spec?

fossifoo00:04:07

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

fossifoo00:04:57

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

fossifoo01:04:17

i think an example of ":gen a map from spec names to generator overrides" in clojure.spec/instrument would help

fossifoo01:04:56

i got a version to run that uses ":spec", so that's a little nicer

fossifoo01:04:14

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?

wottis02:04:59

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.

seancorfield03:04:44

As noted in #clojure, it's kinda hard since most real world Clojure projects have not yet moved to 1.9.0 Alpha builds.

curlyfry08:04:45

@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 fdefs and has a few generative tests! 🙂 Maybe @jrheard can tell us a bit more about it?

rovanion08:04:13

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

wottis08:04:23

@curlyfry @rovanion Thank you very much!

mpenet08:04:29

spandex also has specs

rovanion08:04:41

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.

rovanion08:04:49

Forgot that I had split them into two.

wottis08:04:35

hrhr that should be enough for now

rovanion09:04:25

So perhaps start with some library from the latter list.

rovanion09:04:10

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?

dergutemoritz10:04:37

@rovanion Not with s/keys alone

dergutemoritz10:04:05

You gotta s/and it with a pred of that effect

fossifoo10:04:52

this seems kinda noisy

fossifoo10:04:25

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)

fossifoo10:04:39

might be bad interface design, but it's exploding fast

dergutemoritz10:04:49

@fossifoo "is either a or b or c or d" sounds like s/multi-spec could be worth a look for you

fossifoo10:04:35

ah, yeah, i glanced over that. might work out in my case

Alex Miller (Clojure team)14:04:09

@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?

Alex Miller (Clojure team)14:04:18

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.

fossifoo14:04:45

do you happen to have an example or clarification for instrument {:gen} ?

fossifoo14:04:25

"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

fossifoo14:04:55

i always got the "could'nt generate in 100 tries" error with that. don't have the actual error on hand

gfredericks14:04:57

(fn [] gen/string)

fossifoo14:04:43

ah, worth a try

fossifoo14:04:59

it's not worded very clearly

fossifoo14:04:10

and the source is not really readable either ;D

micahasmith22:04:07

any advice on spec-ing async functions?

micahasmith22:04:51

also, is this sort of redef-ing inside of a spec bad form?

micahasmith22:04:00

(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!))