A Code Coverage Puzzle

A simple comparison is marked as not completely covered, although both branches of the if statement have been covered!?! How is that possible?

This is a small function I’ve created, which is also covered by unit tests. The light blue shade of the return statements indicate that they have been executed. So both branches of the if statement have been covered. But the light pink shade of the comparison indicates that the comparison has not been completely covered.
2014-12-01 16_54_38-BlogCode - Microsoft Visual Studio

Having a logical expression marked as not completely covered is common if it includes any && or || operators that are short circuited. But there are no such operators here. So what is the reason for the partial coverage?

I’ll post the answer and explanation later this week.

  • Jon Skeet on 2014-12-02

    Is MyNumericType a class or a struct? Does it overload “<" and if so, what's the return type?

    (Thoughts: if it's a reference type, what if value or SingleDigitLimit is null? If the return type of < is Nullable, have you covered all three possible options?)

    • Anders Abel on 2014-12-04

      MyNumericType is a struct. To be more specific it is a system struct, with a generic argument that is also a struct. That inner struct overloads the < operator.

  • Leave a Reply

    Your name as it will be displayed on the posted comment.
    Your e-mail address will not be published. It is only used if I want to get in touch during comment moderation.
    Your name will be a link to this address.
Software Development is a Job – Coding is a Passion

I'm Anders Abel, an independent systems architect and developer in Stockholm, Sweden.

profile for Anders Abel at Stack Overflow, Q&A for professional and enthusiast programmers

Code for most posts is available on my GitHub account.

Popular Posts



Powered by WordPress with the Passion for Coding theme.