engineer14 engineer14 - 1 month ago 18
C Question

Code Coverage for C

I've been doing a little bit of reviewing the different code coverage testing used on embedded systems. In particular, I'm looking at the MC/DC. From what I understand, one of the objectives is to make sure that each logical clause in a statement should affect the outcome of the statement.

Two questions:


  1. What is gained by independently verifying that each clause has an effect on the outcome?

  2. Why would
    (A||B) && (A||!C)
    not be able to achieve 100% MC/DC, while
    A||(B&&!C)
    will achieve 100% MC/DC even if they have the exact same functionality?


Answer

To answer your questions

  1. You want as little of code as possible and as less complex code as possible. Having unreachable conditions lengthens your code and makes your code unnecessarily complex.

  2. (A||B) && (A||!C) won't achieve 100% because it requires A to be checked twice for no reason. In the condition where A is false and B is true, A's truthiness will be checked for a second time in the (A||!C) expression for no reason in this formulation whereas in the formula A||(B&&!C) has A's truthiness being checked only once.

Comments