bearophile: Aw shucks, every single link to the old D ports is broken. Even Fawzi took down his RTest project. I'll message him to ask that he reupload it.
bearophile, Awesome! I'll take a look at the old D ports to see how they did it.Çehreli, thanks much! Another D user suggested the same fixes at StackOverflow, so my project is making progress.Fawcett, you've got the right idea :) The difference between your example code and QuickCheck is that your example looks more like assert statements, and QuickCheck's forAll() generates the assertions dynamically, by the hundreds. The API has you specifying only the property to be tested, and the generators for its input types. You're definitely on the right track.Cheers,Andrew PennebakerOn Tue, Oct 18, 2011 at 3:48 PM, Graham Fawcett <fawcett@uwindsor.ca> wrote:On Tue, 18 Oct 2011 15:06:21 -0400, Andrew Pennebaker wrote:> collection of generator functions, of types *arbitrary_type*
> Recap:
>
> forAll() accepts a property of type bool function(void), and a
> function(void). forAll calls the generator functions, storing the valuesA variadic forAll seems doable, e.g.
> in another collection, and passing the values to the property. If the
> property returns false, the values are printed to the screen.
forAll!isEven(&my_ints, &my_floats, &my_ulongs);
The types are not *entirely* arbitrary, right? Each has a return type Tn,
constrained such that "isEven!Tn" must be a valid instance of the isEven
template. so "forAll!isEven(&ints, &floats, &bananas)" would be invalid,
assuming there's no legal "isEven!Banana" instance.
It would look something like this (here with arrays, instead of lambdas):
import std.stdio;
bool isEven(T)(T v) {
return v % 2 == 0;
}
bool forAll(alias Pred, T...)(T seqs) {
bool result = true;
foreach(sequence; seqs) {
foreach(elem; sequence)
result &= Pred(elem);
}
return result;
}
void main() {
writeln(forAll!isEven([22, 22], [23L, 22L]));
writeln(forAll!isEven([2,4], [6.0,8.0], [10L,12L]));
}
Graham