June 2015
Beginner
348 pages
8h 44m
English
Let's write a simple example that is supposed to calculate the well-known factorial, but doesn't cover all of the possible boundary conditions. In other words, some tests will fail.
docstring will look like text you would see in a Python shell (including a prompt). Rig one of the tests to fail, just to see what will happen:""" Test for the factorial of 3 that should pass. >>> factorial(3) 6 Test for the factorial of 0 that should fail. >>> factorial(0) 1 """
return np.arange(1, n+1).cumprod()[-1]
We want this code to fail from time to time for demonstration purposes.
doctest by calling the rundocs() function of the numpy.testing module, for instance, in the Python ...Read now
Unlock full access