I'm writing a D port of <a href="http://www.yellosoft.us/articles/2011/10/13/port-all-the-quickchecks">QuickCheck</a>, a unit test framework that works by testing properties. A property is a function that accepts input values and returns a boolean, e.g. isEven(int i).<div>

<br></div><div>The QuickCheck API's most important function is forAll, which should accept a property and a collection of generators. E.g., isEven takes a single integer, so the generators required are { genInt }. (I don't know the syntax for a collection of differently-typed functions.)</div>

<div><br></div><div>The call would look like:</div><div><br></div><div>forAll(isEven, { genInt });</div><div><br></div><div>And the output would be something like:</div><div><br></div><div>*** Failed!</div><div>57</div><div>

<br></div><div>Because 57, a random number returned by genInt(), when passed to isEven(), results in false.</div><div><br></div><div>Writing our own generator, we can test whether all even integers are indeed even.</div>
<div>
<br></div><div>int genEven() {</div><div>   int i = genInt();</div><div><br></div><div>   if (i % 2 != 0) {</div><div>      i++;</div><div>   }</div><div><br></div><div>   return i;</div><div>}</div><div><br></div><div>forAll(isEven, { genEven });</div>

<div><br></div><div>Sample output:</div><div><br></div><div>+++ OK, passed 100 tests.</div><div><br></div><div>Recap:</div><div><br></div><div>forAll() accepts a property of type bool function(void), and a collection of generator functions, of types <i>arbitrary_type</i> function(void). forAll calls the generator functions, storing the values in another collection, and passing the values to the property. If the property returns false, the values are printed to the screen.<br clear="all">

<div><br></div><div>For a working C version of forAll, see <a href="https://github.com/mcandre/qc">qc</a>. It uses a nasty void* trick, but I'd prefer not to resort to hacks in D if possible.</div><div><br></div><div>

The D version will be called <a href="https://github.com/mcandre/dashcheck">dashcheck</a>.</div><div><br></div>Cheers,<div><br></div><div>Andrew Pennebaker</div><div><a href="http://www.yellosoft.us" target="_blank">www.yellosoft.us</a></div>


<br><div class="gmail_quote">On Tue, Oct 18, 2011 at 2:55 PM, Graham Fawcett <span dir="ltr"><<a href="mailto:fawcett@uwindsor.ca">fawcett@uwindsor.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div class="im">On Tue, 18 Oct 2011 14:28:59 -0400, Andrew Pennebaker wrote:<br>
<br>
<br>
> Now I'm curious: How can I pass and accept a collection of lambdas? The<br>
> lambdas will each have different, arbitrary returns types. And how do I<br>
> call a function using a collection of values, something like Lisp's<br>
> (apply f args) ?<br>
<br>
</div>Can you give an example of how such a thing would be used? Collection of<br>
lambdas, I understand; but what would you expect the return type to be?<br>
<font color="#888888"><br>
Graham<br>
</font></blockquote></div><br></div>