Similarly, write -= 1
using --
.
We'd like the unit-test program to exit with success status only if all tests succeeded. If any fail, we want to know (e.g. to stop the build at that point). I suggest creating the test function with an int
return type to support this, and ending with return tinfo.aborted || tinfo.failed
.
The behaviour when CMC_TEST_ABORT()
is used is strange. It's the only code that's setting tinfo.aborted
, so we could move the if (tinfo.aborted)
block directly into that code. OTOH, we shouldn't be printing the elapsed time in that case, as we've skipped the TIMER_STOP(timer);
and TIMER_CALC(timer);
lines.
Finally, I know it's not really up for review, but I couldn't resist making observations on the gcd()
function used for testing:
There's no need for a specific p==0
test - the flow without the test already does the right thing (but the q==0
test is required, as it's used as divisor in the %
operation).
We can reduce duplication, by moving p % q
into the test:
uintmax_t gcd(uintmax_t p, uintmax_t q)
{
if (q == 0) {
return p;
}
uintmax_t r;
while ((r = p % q) != 0) {
p = q;
q = r;
}
return q;
}