It is a Test-driven development (TDD) process based test.
With this the developer can create a calculator function with the following conditions:
- It is a calculator function (with some extra sub function).
- It allows only positive numbers (which represents integers or float), even if the numbers is in string format (in this case the decimal point must be the '.').
- In case of valid input, it returns an integer (rounded down after the addition).
- In case of invalid input, it throws a specific error (Value or Type) with a small comment.
- In case of any valid string message variable given, it writes that to the stdout after a separate "The message is:" header line.
- In case of the message contains only upper case letters, it converts that to lower case.
You can run the tests with:
python -m pytest tests -vv
If you do not have pytest
then you can install it with:
pip install pytest
or python -m pip install pytest
In the beginning all tests are skipped except the first one, you can remove the @unittest.skip(..) decorator one by one.
So first, run only the first test case (which already enabled), which will pass.
Then remove the skip decorator from the second test case and re-run it. That will fail.
Now update the sum_of_positives(..)
method to pass the test.
Repeat it with the next test cases, until the sum_of_positives(..)
method passes through them all.