Re: [ANN] clojure.test.check 0.5.8

2014-05-17 Thread Reid Draper

On May 15, 2014, at 2:08 PM, Steve Miner stevemi...@gmail.com wrote:

 I'm generating generators from schemas [1].  I have generators for all my 
 simple schemas -- int corresponds to gen/int, etc.  The tougher case is 
 when I have to convert a conjunction of schema expressions into a generator. 
 For example, a schema (and int pos) specifies a positive integer, essentially 
 like testing (fn [x] (and (integer? x) (pos? x)).  
 
 My current implementation finds some element of the AND that I can map to a 
 generator and uses such-that to filter against a predicate created from the 
 rest of the AND elements.
 
 A simple example does something like this...
 
 (make-generator '(and int pos odd))
 ---  (gen/such-that (make-predicate '(and pos odd)) (make-generator 'int))
 ---  (gen/such-that (fn [x] (and (pos? x) (odd? x))) gen/int)
 
 Of course, it would be better to use gen/s-pos-int.  I'm thinking that I need 
 to look for a few common combinations of simple schemas, especially if 
 there's already a good generator for those cases.
 
 However, I still need to try to handle the general case, and it looks like 
 the such-that approach will have to be my fallback position.  I'll probably 
 give the user the option of adding custom generators to match more 
 complicated schema expressions.

Yes, I think you're thinking about this correctly. And in some cases, you may 
be better off just wasting some CPU cycles and using such-that, just like you 
are. It really depends on how complex you want your library to be.

 
 Now, if you could provide an efficient AND generator combinator, that would 
 solve all my problems.  :-)

I'll give this some thought :)

 
 It occurs to me that automatically deriving generators is something like 
 running a predicate backwards so maybe there's a way to do it with 
 core.logic, but I haven't tried to do that yet.

Let me know how this goes.

Reid

-- 
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: [ANN] clojure.test.check 0.5.8

2014-05-15 Thread Reid Draper
Sorry you ran into an issue, Steve. I like your idea of including more 
information in the ex-info data. Is there a specific generator you're 
having trouble writing without such-that? In general, I've found that it's 
a code-smell if you need such-that to retry that many times. Happy to help 
explore other ways to write these generators.

Best,
Reid

On Wednesday, May 14, 2014 12:13:14 PM UTC-5, miner wrote:


 On May 14, 2014, at 10:44 AM, Reid Draper reidd...@gmail.comjavascript: 
 wrote: 
  * Limit the number of retries for gen/such-that. A two-arity version 
 is 
provided if you need to retry more than 10 times. This should be a 
code-smell, though. 

 I think the limit is a good idea, but it's an extra wrinkle and maybe too 
 tight. 

 I had a such-that that failed due to the new limit.  Unfortunately, the 
 error message didn't help much in tracking it down.  I ended up changing 
 all my such-that calls to use a unique number of retries so I could figure 
 which one was failing. 

 I suppose my situation is unusual in that I generate generators and tests 
 from schemas and data.  The stack traces aren't very pretty when there are 
 errors. 

 It might help if you added the 'pred' and 'tries' to the ex-info data in 
 such-that-helper.  Might as well put something in the ex-info data. 

 By the way, it turns out 25 was a sufficient number of retries for my 
 test.  Works fine now. 


 Steve Miner 



-- 
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: [ANN] clojure.test.check 0.5.8

2014-05-15 Thread Steve Miner

On May 15, 2014, at 1:03 PM, Reid Draper reiddra...@gmail.com wrote:

 Sorry you ran into an issue, Steve. I like your idea of including more 
 information in the ex-info data. Is there a specific generator you're having 
 trouble writing without such-that? In general, I've found that it's a 
 code-smell if you need such-that to retry that many times. Happy to help 
 explore other ways to write these generators.

I'm generating generators from schemas [1].  I have generators for all my 
simple schemas -- int corresponds to gen/int, etc.  The tougher case is when 
I have to convert a conjunction of schema expressions into a generator.  For 
example, a schema (and int pos) specifies a positive integer, essentially like 
testing (fn [x] (and (integer? x) (pos? x)).  

My current implementation finds some element of the AND that I can map to a 
generator and uses such-that to filter against a predicate created from the 
rest of the AND elements.

A simple example does something like this...

(make-generator '(and int pos odd))
---  (gen/such-that (make-predicate '(and pos odd)) (make-generator 'int))
---  (gen/such-that (fn [x] (and (pos? x) (odd? x))) gen/int)

Of course, it would be better to use gen/s-pos-int.  I'm thinking that I need 
to look for a few common combinations of simple schemas, especially if there's 
already a good generator for those cases.

However, I still need to try to handle the general case, and it looks like the 
such-that approach will have to be my fallback position.  I'll probably give 
the user the option of adding custom generators to match more complicated 
schema expressions.

Now, if you could provide an efficient AND generator combinator, that would 
solve all my problems.  :-)

It occurs to me that automatically deriving generators is something like 
running a predicate backwards so maybe there's a way to do it with core.logic, 
but I haven't tried to do that yet.

I'd be happy to consider any suggestions.

Thanks,
Steve Miner


[1] https://github.com/miner/herbert


-- 
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: [ANN] clojure.test.check 0.5.8

2014-05-14 Thread Steve Miner

On May 14, 2014, at 10:44 AM, Reid Draper reiddra...@gmail.com wrote:
 * Limit the number of retries for gen/such-that. A two-arity version is
   provided if you need to retry more than 10 times. This should be a
   code-smell, though.

I think the limit is a good idea, but it's an extra wrinkle and maybe too tight.

I had a such-that that failed due to the new limit.  Unfortunately, the error 
message didn't help much in tracking it down.  I ended up changing all my 
such-that calls to use a unique number of retries so I could figure which one 
was failing.

I suppose my situation is unusual in that I generate generators and tests from 
schemas and data.  The stack traces aren't very pretty when there are errors.

It might help if you added the 'pred' and 'tries' to the ex-info data in 
such-that-helper.  Might as well put something in the ex-info data.

By the way, it turns out 25 was a sufficient number of retries for my test.  
Works fine now.


Steve Miner

-- 
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.