www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Randomized unittests

reply Gorge Jingale <Frifj mail.com> writes:
Is there any leverage in the D library for doing randomized unit 
testing? Testing things with a range of possibilities instead of 
fixed. Each time the test is ran a different version is executed. 
This provides more coverage.

How does one create a random number at compile time? Is this the 
only way:

http://dpaste.dzfl.pl/668646ce6d71?
Jul 24 2016
parent reply Chris Wright <dhasenan gmail.com> writes:
On Mon, 25 Jul 2016 01:49:25 +0000, Gorge Jingale wrote:

 Is there any leverage in the D library for doing randomized unit
 testing? Testing things with a range of possibilities instead of fixed.
 Each time the test is ran a different version is executed.
 This provides more coverage.
 
 How does one create a random number at compile time? Is this the only
 way:
 
 http://dpaste.dzfl.pl/668646ce6d71?
http://code.dlang.org/packages/unit-threaded Values() annotation on a unittest takes a range. Base that on a range that yields random values and Bob's your uncle. That range may need to be a compile-time constant. If so, it will be a little awkward to create, and you can ping Atila about possibly creating a ValuesFrom annotation that will take a method or lambda that yields a range of values.
Jul 24 2016
parent Gorge Jingale <Frifj mail.com> writes:
On Monday, 25 July 2016 at 02:36:04 UTC, Chris Wright wrote:
 On Mon, 25 Jul 2016 01:49:25 +0000, Gorge Jingale wrote:

 [...]
http://code.dlang.org/packages/unit-threaded Values() annotation on a unittest takes a range. Base that on a range that yields random values and Bob's your uncle. That range may need to be a compile-time constant. If so, it will be a little awkward to create, and you can ping Atila about possibly creating a ValuesFrom annotation that will take a method or lambda that yields a range of values.
Thanks, looks nice, a bit confusing but seems pretty useful. But why is Bob my uncle? ;)
Jul 24 2016