unittesting generic functions

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Thu Aug 14 15:46:45 PDT 2014


On Thu, Aug 14, 2014 at 10:37:22PM +0000, Jonathan M Davis via Digitalmars-d wrote:
[...]
> Also, you still have to specifically instantiate functions like this
> outside of the unittest block that you're proposing - particularly if
> this is in a library, because in that case, the function may not
> actually be used outside of its tests, and the unit tests aren't going
> to run when someone links in the library. And if that's the case, you
> arguably might as well just write tests for each of the individual
> types.
> 
> So, ultimately, while these sort of tests can be good, I really don't
> think that they're effective very often.
[...]

Yeah, when I first read Andrei's proposal, I actually quite liked it...
until I started thinking about use cases where it would be handy, and
then I suddenly realized that I can't think of any! All *useful*
unittests I can think of involve the use of concrete values of concrete
types. Having only .init guaranteed to exist for a generic type T (and
sometimes not even that if you have a Voldemort) greatly cripples the
utility of the unittest.

So I'd love to see an actual, non-trivial, motivating example of where
this kind of per-instantiation unittest is actually useful. That may yet
change my mind about this issue.  ;-)


T

-- 
The richest man is not he who has the most, but he who needs the least.


More information about the Digitalmars-d mailing list