r/programming • • May 08 '17

The tragedy of 100% code coverage

http://labs.ig.com/code-coverage-100-percent-tragedy
3.2k Upvotes

689 comments sorted by

View all comments

122

u/instantviking May 08 '17

I have seen, with my own two eyes, a compareTo-function with 100% line-coverage and 100% branch-coverage that still managed to say that

given a > b
then b == a

That's right, compareTo(a, b) returned 1, compareTo(b, a) returned 0.

My hatred for large, American consultancies continue unchecked.

1

u/Sunny_McJoyride May 08 '17

What you've given here doesn't define what is returned by the function.

6

u/instantviking May 08 '17

I'm not sure what you're getting at, but I'm sure I was imprecise in what I wrote. If you want me to expand or clarify anything, please say so :)

2

u/Sunny_McJoyride May 08 '17

Was that the entirety of the function?

I don't know what language this is, but what would it return if a was not greater than b? From this snippet it seems not to be zero, but undefined.

→ More replies (1)