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:
(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?To answer your questions
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.
(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.