def read_animals(filename):
"""
- This function will read animal data from a file.
+ This function will read animal data from a file. It returns 4 lists,
+ one for each column in the file.
+
"""
date = []
f.close()
return (date, time, animal, number)
+
+
+def mean(l):
+ """
+ Return the mean of a list of numbers. Returned value
+ should always be a float.
+
+ """
+ if len(l) == 0:
+ return None
+
+ return float(sum(l)) / len(l)
import animals
+
def test_read_animals_date():
- reference_date = ['2011-04-22', '2011-04-23', '2011-04-23', '2011-04-23',
+ reference_date = ['2011-04-22', '2011-04-23', '2011-04-23', '2011-04-23',
'2011-04-23']
date, time, animal, number = animals.read_animals('animals.txt')
assert date == reference_date, 'Date is wrong'
+
def test_read_animals_time():
- reference_time = ['22:06', '14:12', '10:24', '20:08', '18:46']
+ reference_time = ['21:06', '14:12', '10:24', '20:08', '18:46']
date, time, animal, number = animals.read_animals('animals.txt')
assert time == reference_time, 'Time is wrong'
+
+
+def test_mean1():
+ l = [1]
+ assert animals.mean(l) == 1
+
+
+def test_mean2():
+ l = [1, 2, 3]
+ assert animals.mean(l) == 2
+
+
+def test_mean3():
+ l = [4, 2, 3, 5]
+ assert animals.mean(l) == 3.5
+
+
+def test_mean4():
+ l = []
+ assert animals.mean(l) == None