Testing programs that use lists
- Make sure you consider the possibility that the list is EMPTY. That means
its length is zero. If this happens, it will cause loops that are based on
"for ele in list:" or "for i in range(len(list)):" to not be executed at all.
This may or may not be an error, it depends on your problem specification.
- Test your code with a list of length ONE. This often can cause difficulties
when the code deals with a "next" element and a "previous" element.
If you want to sort a list with a length of one, you stop immediately because
it's already sorted!
- Test your code with a list of length more than one. Two or three elements
will usually exercise the more general cases of your code. Loops based on the
list will execute a few times, which is a good exercise for them.
- Past that, if your list has some special size, like 26 spaces for letters of
the alphabet or 9 spaces for a tic-tac-toe board, then of course test those.
If this is the case, then checking for "off by one" errors (fencepost errors)
is also good - if the size should be 9, check 8 and 10 also.
- There usually is no need to test arbitrarily large sizes unless you think your
program might encounter them more than rarely.