Jeff King <> writes:

>> A(ny) sanely defined "compare A with B" function should yield the
>> result of subtracting B from A, i.e. cmp(A,B) should be like (A-B).
>> That is what you feed qsort() and bsearch() (it is not limited to C;
>> you see the same in "sort { $a <=> $b }").  The definition naturally
>> makes "cmp(A,B) < 0" like "A < B" and "cmp(A,B) > 0" like "A > B".
>> ---
> Ah, you mean "if you think that the compare function should behave like
> C *_cmp functions, it should be A-B". Perhaps it is simply that I do not
> think of the function in those terms, but more like "show me the
> differences from B to A".

>> > Otherwise why would so many
>> > existing test frameworks do it the other way?
>> Which many existing frameworks do it the other way?
> John mentioned JUnit, NUnit, and PHPUnit earlier in the thread. I
> believe that Ruby's Test::Unit::Assertions also has
> assert_equal(expected, actual).

Especially the last one can be excused.  "is A and B equal" is a
binary between "yes" and "no".  If A and B are equal, B and A are
equal, and it becomes more like "which endianness is correct?" as
you mentioned earlier.

I think the real cause of confusion is that "cmp(1)" is not a
comparison in that sense but is an equality check; "test_cmp" has a
dual purpose in that its primary use as "did the previous step
produce correct result?" is an equality check and the order does not
really matter, but its secondary purpose, to show how the actual
output deviated from the norm, has to be done by subtracting the
expected result from the actual result.

As I said, I am somewhat sympathetic to those who want to see such
subtraction spelled as cmp(Actual,Expect), but we are so used to the
order "diff(1)" takes expect and actual to do that subtraction in
that order, so using diff(Expect,Actual) order is not that wrong.

Calling the abstraction "test_diff" might have avoided the wasted
brain bandwidth in this thread, but I do not think renaming it in is worth the trouble, either ;-)

To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to
More majordomo info at

Reply via email to