std.unittests for (final?) review
Bruno Medeiros
brunodomedeiros+spam at com.gmail
Fri Jan 28 06:58:10 PST 2011
On 06/01/2011 02:54, Ary Borenszweig wrote:
> I prefer assert, assertFalse, assertEqual and assertNotEqual.
>
> Compare this:
> assertPredicate!"a< b"(1 + 1, 3);
>
> To this:
> assert(1 + 1< 3)
>
> Or to this:
>
> assertLess(1 + 1, 3)
>
I agree with Ary here, at least with regard to assertEquals. I'm a very
test and contracts minded programmer so I use asserts a lot, and
specifically assertEquals (possibly assertSame as well) is common enough
that I want a shortcut to type them, I don't want to have to type the
predicate. And it's more readable as well. (The implementation can use
assertPredicate, that's good, but that's not the issue)
And yes, for "a == b" I won't have to type the predicate that it is the
default:
assertPredicate(1 + 1, 2);
However it still suffers from the readability issue, and it won't work
for a similar predicate I also use quite often as well, assertAreEqual,
which accepts nulls(
"(a == b) || (a != null && b != null && a.equals(b))"
In practice it won't be a problem at all because we can define aliases,
like Jonathan said, however it would be nice if the std library would be
mindful of this and provide shortcuts for the very common predicates.
--
Bruno Medeiros - Software Engineer
More information about the Digitalmars-d
mailing list