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)

  2. Which means every IF statement doubles the number of test conditions

  3. A 1 million line program might, conservatively estimating, have 100k IF statements (conditionals)

  4. That is 2100000 which is more seconds than have elapsed since the beginning of the universe.

  5. No project has 2100000 seconds to test

  6. So complete test coverage of complex programs is impossible

1 Upvotes

46 comments sorted by

View all comments

Show parent comments

2

u/wordsnerd Mar 10 '19

This is true if the three functions are potentially interacting via "ambient" state (be it globals, private fields, etc). Functions that don't read or write any ambient state can be safely tested in isolation, although you'd need a way to guarantee that the functions will remain pure to preserve that assumption.

1

u/gxm492lor Mar 10 '19

Not sure that global state makes a difference - what we're white box testing is runtime behavior. Execution when condition1 is true is one test. condition1 = false is another test.

1

u/wordsnerd Mar 10 '19

Global state does matter (I prefer "ambient" because it's not restricted to globals). For example, the number of if-statements in your sqrt() function has no bearing on anything else in the program, and nothing else in the program can change the result of sqrt(2) unless there is some hidden channel of communication to change its behavior.

1

u/gxm492lor Mar 10 '19

we said complex program. that is, a million lines of code or more. that is, the code will execute a million lines of more. During that execution, every conditional executed would need to be tested with a run for when it is true and a run for when it is false.

→ More replies (0)