112 Intermediate C Programming
that have problems, then valgrind will not detect any problems. This is not a limitation in
valgrind, but more an indication of what type of tool it is. This is a limitation in how you
write test cases. You need to think how your program may fail and then test the potential
problems. Good tests can make valgrind invaluable. Note that this is another reason why
passing test cases does not guarantee that the program is correct. If the test cases do not
test the problematic parts, then the problems are undetected.
How could it be possible that some parts of the program are not executed? This is
because most programs have many if conditions. It is extremely difficult—practically
impossible—to design test cases that can check every combination of these conditions. For
each if condition, the condition can be true or false. Hence, there are two possibilities. If
there are n if conditions and they are independent, there are 2
n
possibilities. As a point of
reference, in one weekly homework for my class at Purdue University, the sample solution
has 25 if conditions, about 2
25
= 34 million possibilities. Can you create 34 million test
cases? Obviously a brute-force approach is impossible, but the task is significantly eased by
examining the logic of the program. Even though there are 25 if conditions in the sample
solution mentioned, there are not 34 million paths through the code because some condi-
tions are related. Careful reasoning is required to make this type of analysis. It is certainly
possible that some problems are not detected when this homework assignment is graded.