Skip to content

Instantly share code, notes, and snippets.

@fnielsen
Created January 3, 2014 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fnielsen/8239167 to your computer and use it in GitHub Desktop.
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).
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