This exercise requires you to clone the repository from: github.com/arc-bath/rainfall.git. Make sure that the repository is not cloned into a directory or sub-directory of an existing git repository. On notebooks.azure.com, the easiest way to ensure this is to create a new library with Upload GitHub Repo
Once your library has been created Run
the library, navigate to the src
folder and start a new notebook. You can the run the tests in test_rainfall.py
from within a code cell with:
!pytest test_rainfall.py
If you wish to run from the terminal then you can instead clone the repository directly with git
:
git clone https://github.com/arc-bath/rainfall.git
Once you have the repository change into the directory and run the tests in test_rainfall.py
% cd rainfall/src
% pytest test_rainfall.py
You should see a lot of output from pytest since many of the tests failed. The final line should contain a summary:
======================================== 9 failed, 3 passed in 0.16 seconds =========================================
The aim of this exercise is to modify your function so that it passes all these tests. Let's begin by reducing the output produced by pytest
so we can see more clearly what is happening:
% pytest --tb=short test_rainfall.py
You should now see output that looks like:
================================================ test session starts ================================================
platform linux -- Python 3.6.3, pytest-3.2.1, py-1.4.34, pluggy-0.4.0
rootdir: /home/rjg20/training/arc-training/now-code-repos/rainfall, inifile:
collected 12 items
src/test_rainfall.py ...FFFFFFFFF
===================================================== FAILURES ======================================================
________________________________________________ test_rf_negative_1 _________________________________________________
src/test_rainfall.py:48: in test_rf_negative_1
assert_almost_equal( observ, expect )
E AssertionError:
E Arrays are not almost equal to 7 decimals
E ACTUAL: 2.3333333333333335
E DESIRED: 3
________________________________________________ test_rf_negative_2 _________________________________________________
src/test_rainfall.py:59: in test_rf_negative_2
assert_almost_equal( observ, expect )
E AssertionError:
E Arrays are not almost equal to 7 decimals
E ACTUAL: 2.3333333333333335
E DESIRED: 3
________________________________________________ test_rf_negative_3 _________________________________________________
src/test_rainfall.py:70: in test_rf_negative_3
assert_almost_equal( observ, expect )
E AssertionError:
E Arrays are not almost equal to 7 decimals
E ACTUAL: 2.3333333333333335
E DESIRED: 3
________________________________________________ test_rf_negative_4 _________________________________________________
src/test_rainfall.py:81: in test_rf_negative_4
assert_almost_equal( observ, expect )
E AssertionError:
E Arrays are not almost equal to 7 decimals
E ACTUAL: 1.2
E DESIRED: 4
___________________________________________________ test_rf_99_1 ____________________________________________________
src/test_rainfall.py:92: in test_rf_99_1
assert_almost_equal( observ, expect )
E AssertionError:
E Arrays are not almost equal to 7 decimals
E ACTUAL: 27.0
E DESIRED: 3
___________________________________________________ test_rf_99_2 ____________________________________________________
src/test_rainfall.py:103: in test_rf_99_2
assert_almost_equal( observ, expect )
E AssertionError:
E Arrays are not almost equal to 7 decimals
E ACTUAL: 23.0
E DESIRED: 3
___________________________________________________ test_rf_both ____________________________________________________
src/test_rainfall.py:114: in test_rf_both
assert_almost_equal( observ, expect )
E AssertionError:
E Arrays are not almost equal to 7 decimals
E ACTUAL: 20.818181818181817
E DESIRED: 3
___________________________________________________ test_rf_empty ___________________________________________________
src/test_rainfall.py:123: in test_rf_empty
observ = rf.rfmean( test_list )
src/rainfall.py:26: in rfmean
return sum/count
E ZeroDivisionError: division by zero
_________________________________________________ test_rf_99_start __________________________________________________
src/test_rainfall.py:136: in test_rf_99_start
assert_almost_equal( observ, expect )
E TypeError: unsupported operand type(s) for -: 'str' and 'float'
======================================== 9 failed, 3 passed in 0.17 seconds =========================================
The Rainfall problem has a long history, see this review for details. The problem involves combining structural components of programming, e.g. loops and conditionals to calculate the mean of a data set subject to:
STOP
value is met.In this exercise you will modify a provided function to meet these criteria where the STOP
value is 99
. You will also handle exceptions such as empty lists and related problems to improve the robustness of you function and provide informative messages and help to potential users.
Later in the exercise you will introduce the possibility of a user defined STOP
value.
You will be able to monitor your progress by comparing how your functions pass a series of tests provided in the exercise repository. This also includes a prototype function to help you get started.