TDPL: Operator Overloading
Philippe Sigaud
philippe.sigaud at gmail.com
Thu Aug 26 12:19:53 PDT 2010
On Wed, Aug 25, 2010 at 17:27, Andrej Mitrovic <andrej.mitrovich at test.com>wrote:
> What would be really cool is if we had a property that returned a random
> value of any integrated type. And for user-defined types, maybe it would
> call a method with a special name. I guess one could make a template
> function that would do just that.
>
>
It reminds me a bit of Haskell's QuickCheck library, used to test code.
http://hackage.haskell.org/package/QuickCheck-2.1.1.1
There is an Arbitrary typeclass that the user defines to generate an
arbitrary value for a given type.
With a D template, it's easy to do that for all numeric types (or, any
'range' type, like char) and arrays / associative arrays. This way,
generating it for classes and struct is easy. The real difficulty would be
to generate an arbitrary function from int function(int), for example.
And, to test, you don't want a perfectly random value: you need the extrema,
degenerate cases like NaN, null pointers, empty arrays, etc.
Philippe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20100826/28ec2dd5/attachment.html>
More information about the Digitalmars-d-learn
mailing list