CMSC 201

Lab 8: Debugging

Debugging

In this lab, you will be working on fixing two programs- one with syntax problems, and one with semantic problems.

Ideally, all code you write should be tested incrementally. Incremental testing means that you write a small amount of code, test it, and once you know it's working you proceed. Another name for this is unit testing.


Example of Unit Testing:

First, we write some code:

def isNumEven(value):
if (value % 2 == 0):
return True
else:
return False

def main():
print("Is 2 even?",isNumEven(2))
print("Is 3 even?",isNumEven(3))
main()

Output:
Is 2 even? True
Is 3 even? False

So now we know at least the most general cases are working, and we can continue to write other code/functions. Before we verify that isNumEven() works, we should never create functions that use isNumEven() and assume they will be working correctly. This may seem simple, but not following these rules makes it a lot more difficult to debug your code if something ends up not working (which it inevitably will).