From: Katy Huff Date: Wed, 30 Jan 2013 00:21:55 +0000 (-0600) Subject: removing header links X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=2019beb70ad2d0202458e5c25ceae7a5bc7ab896;p=swc-testing-nose.git removing header links W. Trevor King: I dropped everything from the original 8fa8f85 except for the python/testing/ modification. Conflicts: debugging/Readme.md --- diff --git a/python/testing/mean.py b/python/testing/mean.py index 887484d..e95841a 100644 --- a/python/testing/mean.py +++ b/python/testing/mean.py @@ -1,10 +1,11 @@ def mean(numlist): - try: + try : total = sum(numlist) length = len(numlist) - except TypeError: - raise TypeError("The number list was not a list of numbers.") - except: - print "There was a problem evaluating the number list." - return total/length - + except TypeError : + raise TypeError("The list was not numbers.") + except ZeroDivisionError : + raise ZeroDivisionError("Does your list have elements in it?") + except : + print "Something unknown happened with the list." + return float(total)/float(length) diff --git a/python/testing/test_mean.py b/python/testing/test_mean.py index 05e2617..b9715f4 100644 --- a/python/testing/test_mean.py +++ b/python/testing/test_mean.py @@ -25,4 +25,21 @@ def test_floating_mean1(): exp = 1.5 assert_equal(obs, exp) +def test_string(): + assert_raises(TypeError, mean, ["one", "two", "fortyeight"]) + +def test_inf() : + obs = mean([1,2,float("inf")]) + exp = float("inf") + assert_equal(obs, exp) + +def test_zero_elems() : + empty_list = [] + assert_raises(ZeroDivisionError, mean, empty_list) + + + + + +