Let's start with a very simple Python function for us to test:
def square(x): return x * x
In order to verify the correctness of this code, we pass a value, and will test if the result of the function is what we expect. For example, we could give it an input of 5, and would expect the result to be 25.
To illustrate the concept, we can manually test this function in the command line using the assert statement. The assert statement in Python simply says that if the conditional statement after the assert keyword returns False, then it will throw an exception as follows:
$ python >>> def square(x): ... return x * x >>> assert square(5) == 25 >>> assert square(7) == 49 >>> assert square(10) == 100 >>> assert square(10) == 0 Traceback (most recent call last): File...