From 2019beb70ad2d0202458e5c25ceae7a5bc7ab896 Mon Sep 17 00:00:00 2001 From: Katy Huff Date: Tue, 29 Jan 2013 18:21:55 -0600 Subject: [PATCH] removing header links W. Trevor King: I dropped everything from the original 8fa8f85 except for the python/testing/ modification. Conflicts: debugging/Readme.md --- python/testing/mean.py | 15 ++++++++------- python/testing/test_mean.py | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 7 deletions(-) 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) + + + + + + -- 2.26.2