reading-notes

Testing and Modules

TDD with Python

The tests can be considered as your alive documentation. We need to be descriptive about it and to say what is expected and what we are testing.

The test file name should follow the same name of module name. For instance, if our module is gender.py, our test name should be test_gender.py.

AAA: Arrange, Act and Assert.

The cycle is made by three steps:

Takeaways

if name == main

allows you to test whether your script is being run directly or being imported by something else by testing name variable

Advantages :

if name == “main”: is used to execute some code only if the file was run directly, and not imported.

Recursion

def fib(n):
    if n <=1:
        return n
    else:
        return ( fib(n - 1) + fib(n - 2) )
References