Reading-Notes

View the Project on GitHub MohammadAl-khatib/Reading-Notes

Testing and Modules

In Tests We Trust - TDD with Python

TDD stands for test driven Development, it is a way of designing software by executing tests and having results during the write of code, the article recommends the so called baby steps for this testing, here are some notes:

  1. Start with a regular input and output.
  2. Choose a descriptive name for the test.
  3. AAA (arrange, act, then assert)

The steps for writing a test:

If name equals main

This piece of code is used to execute the code within it only when the file is running directly, otherwise, it will not be executed. A well know use case is when we are importing some code from one file to another.

Recursion

It is a function that calls itself, and this may become infinit which leads to a stack overflow, there must be a base case to break this loop which defines when the calling of the function will result in no more calling of the function i.e. a value will be returned instead of the function call.

This recursive behavior can be done directly (the function calls itself) or indirectly (the function is called by another function within its body), a well known use cases are Fibonacci series and factorials, you can have detailed codes here