Fork me on GitHub
#clojure-spec
<
2017-12-14
>
lopalghost15:12:26

@johanatan seems to work fine

> (s/exercise-fn `subtract)
> ([[2 1] 1] [[7 1] 6] [[3 1] 2] [[4 3] 1] [[13 4] 9] [[5 4] 1] [[7 3] 4] [[17 1] 16] [[96 3] 93] [[14 3] 11])
> (stest/check `subtract)
> ({:spec #object[clojure.spec.alpha$fspec_impl$reify__2451 0x2bfc33f4 "clojure.spec.alpha$fspec_impl$reify__2451@2bfc33f4"], :clojure.spec.test.check/ret {:result true, :num-tests 1000, :seed 1513263691452}, :sym practice.specs/subtract})

lopalghost15:12:02

is there a reason you need the args vector to conform to a map?

lopalghost15:12:12

if you supply a generator for ::args-tup, you shouldn't have to worry about failure during generative testing

gfredericks15:12:47

easy generator for a strictly descending pair of numbers: (gen/let [[a b] (gen/tuple gen/large-integer gen/large-integer)] (let [[a b] (sort [a b])] [(inc a) b]))

andy.fingerhut15:12:05

I was looking at updating the Clojure cheat sheet for v1.9, now that it is out. I was wondering -- is there a list somewhere of all Clojure predicates for which test.check has generators included, vs. those it does not have generators for?

gfredericks15:12:06

I expect there's a data structure in the spec code mapping specs to generators

andy.fingerhut15:12:06

If someone beats me to finding a link to that, let me know. I may want to link to it.

gfredericks15:12:46

if you have a list of predicates, then programmatically figuring out which have generators should be easy

andy.fingerhut15:12:08

Is there some small expression you can evaluate in a REPL to determine if a predicate has a generator already?

gfredericks15:12:11

I thought there was a function in the spec API that takes a spec and returns a generator

Alex Miller (Clojure team)17:12:40

There are some things in gen namespace too

Alex Miller (Clojure team)17:12:11

And that’s where the built in mapping is set

lopalghost17:12:00

gen/gen-for-pred

andy.fingerhut17:12:04

Thanks, s/gen is very helpful. And dang, I could have really added a lot of value by helping with the generator for zero? 🙂

andy.fingerhut17:12:35

I couldn't have been very helpful, of course. Simply my way of expressing surprise that there was such a generator.

gfredericks20:12:59

(gen/one-of (gen/elements [(float 0) (int 0) 0.0 0 0N (biginteger 0) -0.0]) (gen/let [scale (gen/large-integer* {:min Integer/MIN_VALUE :max Integer/MAX_VALUE})] (.setScale 0M scale))) I assume?

andy.fingerhut20:12:33

Yes, the most complex part about it is if you want to generate every value that can satisfy zero?

andy.fingerhut20:12:10

I probably should have made my snide remark about the predicate nil? instead, since it would be more obvious.

andy.fingerhut20:12:51

I am probably having a senior moment here on my memory -- is there any reasonably common term for any type that isn't a collection?

taylor20:12:34

it’s not scalar is it

andy.fingerhut20:12:58

It is, and I am understanding more every day what memory lapses feel like 🙂

taylor20:12:46

I increasingly find myself forgetting what I’m about to do as I walk across my tiny apartment to do it

gfredericks21:12:07

tattoos are the answer put "things that aren't collections are scalars" on your left arm

cgore21:12:46

And “there are no scalars” on your right arm 😄

andy.fingerhut22:12:09

On a related note, I watched the movie "Memento" for the first time recently. Sound advice.

taylor22:12:23

are you sure it was the first time??

gfredericks22:12:48

more likely he will soon watch it for the last time

andy.fingerhut22:12:15

It felt like the first time, anyway

andy.fingerhut22:12:59

If only I can keep forgetting my favorite movies and books, I can get full enjoyment from them multiple times -- if I can remember which ones they are.

taylor22:12:41

if ignorance is bliss then forgetfulness is… personal growth?

andy.fingerhut22:12:47

(Laugh Out Loud And Had To Explain My Laughter To My Wife)