unit-threaded v0.6.5 - Type-parametrized tests

Atila Neves via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Fri Mar 11 06:26:34 PST 2016


On Friday, 11 March 2016 at 08:06:19 UTC, Jacob Carlborg wrote:
> On 2016-03-10 12:05, Atila Neves wrote:
>
>> No, sorry. I haven't needed it yet. Something like this?
>
> Yes.
>
>> @Types!(int, string)
>> void testArray(T)() {
>>      import std.container;
>>
>>      auto arr = Array!T();
>>      arr.empty.shouldBeTrue;
>>
>>      arr.insertBack(T.init);
>>      arr.empty.shouldBeFalse;
>>      auto l = arr.length;
>>      l.shouldEqual(1);
>> }
>
> I'm trying to think how this would be useful. Would you want to 
> test with different values than T.init? Or is there some 
> library that can generate random values based on a type?
>
> What about user defined types? T.init my not be useful at all.
>
> I don't want to sound negative but I'm trying to see the use 
> cases.

There's this: https://github.com/mcandre/dashcheck

Didn't Robert have a QuickCheck-alike as well?

Like I said, I'm not sure of the use cases, but I thought I'd 
enable it and it was fun to do. I know I've written template unit 
tests in C++ in the past, but I can't remember why.

Atila


More information about the Digitalmars-d-announce mailing list