W. Trevor King: I dropped everything from the original
8fa8f85 except
for the python/testing/ modification.
Conflicts:
debugging/Readme.md
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)
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)
+
+
+
+
+
+