Created
January 3, 2014 14:54
-
-
Save fnielsen/8239167 to your computer and use it in GitHub Desktop.
Small example demonstrating the need for testing functions with different types of input arguments. Here an integer division problem (in Python 2).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from numpy import max, min | |
def mean_diff(a): | |
""" | |
Parameters | |
---------- | |
a : array_like | |
""" | |
return float((max(a) - min(a)) / (len(a) - 1)) | |
def test_mean_diff(): | |
assert mean_diff([1., 7., 3., 2., 5.]) == 1.5 | |
assert mean_diff([7, 3, 2, 1, 5]) == 1.5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment