r/programmerchat • u/gxm492lor • 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?
Every IF statement in a program doubles the number of possible states of the program (ignoring time)
Which means every IF statement doubles the number of test conditions
A 1 million line program might, conservatively estimating, have 100k IF statements (conditionals)
That is 2100000 which is more seconds than have elapsed since the beginning of the universe.
No project has 2100000 seconds to test
So complete test coverage of complex programs is impossible
1
Upvotes
1
u/gxm492lor Mar 10 '19
not measuring whether or not the program mutates global state.
measuring coverage of all possible run-time states.
run-time state are entered as the conditionals are encountered. not if it reads or writes state.
For example:
at t0 execute condition1
at t1 execute condition2
run 1 of the program:
at t0 condition1 is true
at t1 condition2 is true
run 2 of the program:
at t0 condition1 is true
at t1 condition2 is false
run 3 of the program:
at t0 condition1 is false
at t1 condition2 is true
run 4 of the program:
at t0 condition1 is false
at t1 condition2 is false
each of these represents a possible runtime state. It doesn't matter how you break the program up - that gets flattened out by the compiler/linker anyway.
these 4 separate runs would cover 2 conditionals completely (ignoring time).
3 conditionals executed during a run requires 8 = 23 possible runtime states.
4 conditionals is 16 24 tests.
which is why it's practically impossible to test every possible execution of a complex program