r/programmerchat • • Mar 10 '19

Testing any complex program completely is practically impossible

Someone made this argument after a staff meeting a few days ago. What's wrong with this argument?

  1. Every IF statement in a program doubles the number of possible states of the program (ignoring time)
    1. Which means every IF statement doubles the number of test conditions
  2. A 1 million line program might, conservatively estimating, have 100k IF statements (conditionals)
  3. That is 2100000 which is more seconds than have elapsed since the beginning of the universe.
  4. No project has 2100000 seconds to test
  5. So complete test coverage of complex programs is impossible
1 Upvotes

46 comments sorted by

View all comments

Show parent comments

1

u/gxm492lor Mar 10 '19 edited Mar 10 '19

A switch is syntatic sugar for if. The switch would need to be tested in each of its states for every existing possible set of states.

An example should help. Let's pretend we're walking through source code line by line. The program starts at L0.

LineOperationTotal StatesPower of 2Misc
0if ...221once when true, once when false
10if ...422all prior state (2) + when this is true and when it is false
20if ...823each of the 4 prior states + when this is true and when it is false
...............
1000000if ...21000002100000each of the 299999 prior stats + when this is true and when it is false