Re: Is it normal for exercise-fn to return examples that don't conform?

2017-04-03 Thread Jason Felice
That's a complicated question, but the simplified answer is:

test.check (which clojure.spec uses) generates random test cases.  This is
advantageous when the state space is very large, where tracking previous
examples is hard and gives very little advantage.  When the state space is
small, there will be a lot of repeats.

(There is also a feature where it starts "small" and grows.  This means
that repeated examples are more likely at first.)

I would definitely recommend unit testing if the state space is small
enough to enumerate and fit in your head.

-Jason

On Mon, Apr 3, 2017 at 5:31 AM, Didier  wrote:

> Do you know why they are not unique? Was that on purpose or an accidental
> behaviour of the implementation?
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Is it normal for exercise-fn to return examples that don't conform?

2017-04-03 Thread Didier
Do you know why they are not unique? Was that on purpose or an accidental 
behaviour of the implementation?

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Is it normal for exercise-fn to return examples that don't conform?

2017-04-02 Thread Didier

>
> Generated samples aren't unique.


Is there any reason why samples are not unique? Is this on purpose, or just 
an accidental consequence of the implementation?

Conform like this:
>
> (s/conform (:args (s/get-spec `wtv)) [0])
>
>
If I conform like that, it is not really conforming my function spec, just 
the argument spec. Like, I have the same issue if doing `(s/valid? `wtv 
(wtv 0))`. Basically, I want to understand the semantics of exercise-fn. 
Does it just call my function with input generated from the args spec, and 
does not care about return? I thought it was supposed to show you example 
of input which do make the spec valid.

Nevermind, the doc string answers this:

exercises the fn named by sym (a symbol) by applying it to
> n (default 10) generated samples of its args spec. When fspec is
> supplied its arg spec is used, and sym-or-f can be a fn.  Returns a
> sequence of tuples of [args ret].
>
>
On Sunday, 2 April 2017 03:55:19 UTC-7, Leon Grapenthin wrote:
>
> Generated samples aren't unique.
>
> Conform like this:
>
> (s/conform (:args (s/get-spec `wtv)) [0])
>
>
> On Thursday, March 30, 2017 at 2:55:35 AM UTC+2, Didier wrote:
>>
>> If you look at this example:
>>
>> (defn wtv [in] (if (= 0 in) 0 10))
>> (s/fdef wtv
>> :args (s/cat :in int?)
>> :ret (s/and int? #(not= 0 %)))
>>
>> (s/exercise-fn `wtv)
>> (s/conform `wtv (wtv 0))
>>
>> You'll see that exercise gives you most of the time the following sample:
>>
>> [(0) 0]
>>
>> But this fails to conform:
>>
>> => (s/conform `wtv (wtv 0))
>>
>> => :clojure.spec/invalid
>>
>>
>>  Also, why does exercise give repeated samples? Shouldn't they be unique?
>>
>> ([(0) 0] 
>>  [(-1) 10] 
>>  [(0) 0] 
>>  [(-1) 10] 
>>  [(-2) 10] 
>>  [(2) 10] 
>>  [(0) 0] 
>>  [(-1) 10] 
>>  [(-2) 10] 
>>  [(0) 0]) 
>>
>> Thanks
>>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Is it normal for exercise-fn to return examples that don't conform?

2017-04-02 Thread Leon Grapenthin
Generated samples aren't unique.

Conform like this:

(s/conform (:args (s/get-spec `wtv)) [0])


On Thursday, March 30, 2017 at 2:55:35 AM UTC+2, Didier wrote:
>
> If you look at this example:
>
> (defn wtv [in] (if (= 0 in) 0 10))
> (s/fdef wtv
> :args (s/cat :in int?)
> :ret (s/and int? #(not= 0 %)))
>
> (s/exercise-fn `wtv)
> (s/conform `wtv (wtv 0))
>
> You'll see that exercise gives you most of the time the following sample:
>
> [(0) 0]
>
> But this fails to conform:
>
> => (s/conform `wtv (wtv 0))
>
> => :clojure.spec/invalid
>
>
>  Also, why does exercise give repeated samples? Shouldn't they be unique?
>
> ([(0) 0] 
>  [(-1) 10] 
>  [(0) 0] 
>  [(-1) 10] 
>  [(-2) 10] 
>  [(2) 10] 
>  [(0) 0] 
>  [(-1) 10] 
>  [(-2) 10] 
>  [(0) 0]) 
>
> Thanks
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Is it normal for exercise-fn to return examples that don't conform?

2017-03-29 Thread Didier
If you look at this example:

(defn wtv [in] (if (= 0 in) 0 10))
(s/fdef wtv
:args (s/cat :in int?)
:ret (s/and int? #(not= 0 %)))

(s/exercise-fn `wtv)
(s/conform `wtv (wtv 0))

You'll see that exercise gives you most of the time the following sample:

[(0) 0]

But this fails to conform:

=> (s/conform `wtv (wtv 0))

=> :clojure.spec/invalid


 Also, why does exercise give repeated samples? Shouldn't they be unique?

([(0) 0] 
 [(-1) 10] 
 [(0) 0] 
 [(-1) 10] 
 [(-2) 10] 
 [(2) 10] 
 [(0) 0] 
 [(-1) 10] 
 [(-2) 10] 
 [(0) 0]) 

Thanks

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.