<div class="gmail_quote">On Wed, Aug 25, 2010 at 17:27, Andrej Mitrovic <span dir="ltr"><<a href="mailto:andrej.mitrovich@test.com">andrej.mitrovich@test.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
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.<br>
<div><div></div><br></div></blockquote><div><br>It reminds me a bit of Haskell's QuickCheck library, used to test code. <br><a href="http://hackage.haskell.org/package/QuickCheck-2.1.1.1">http://hackage.haskell.org/package/QuickCheck-2.1.1.1</a><br>
<br>There is an Arbitrary typeclass that the user defines to generate an arbitrary value for a given type.<br>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.<br>
<br>And, to test, you don't want a perfectly random value: you need the extrema, degenerate cases like NaN, null pointers, empty arrays, etc.<br><br>Philippe<br><br><br></div></div>