Testing if statements

The key thing about having if statements in your program is that your program now has multiple paths of execution. On any one run, it will only go on one of those paths. But ALL the paths need to be tested. You will need lots more test cases!

You are looking for correct behavior of course. You are also looking for dead code, that is code that will Never be executed, usually because of a logical flaw in your code.

You might try drawing a "decision tree" (examples in class). That helps you enumerate all the different paths through a program.

It is also useful to use the debugger in code with if statements. You may need to put more than one breakpoint in the code, one in each branch. If you don't know for sure which branch will be executed, putting 2 breakpoints in will make sure that you do in fact come to one of them.


   if x < 0:
      print ("no")
      print ("yes")
needs two test cases, one with x < 0 and one with x >= 0.


    if x > 0:
       if y < 10:
            print ("green")
will need 3 test cases,

If you are using "and" and "or" operators in your tests, did you use the correct one? it's easy to swap them! If multiple conditions are "anded" together, make sure that you check cases where the individual conditions are all True, all but one are True, none are True, etc. A "truth table" is useful here!