def test_three_iterables_with_same_length(self):
     list_1 = [1, 2, 3]  # an iterable
     list_2 = [5, 2, 4]  # an iterable
     list_3 = [7, 7, 7]  # an iterable
     generator = my_map(get_total, list_1, list_2, list_3)
     expected_list = [13, 11, 14]
     self.assertEqual(expected_list, list(generator))
 def test_passed_non_iterable(self):
     """
     map(func, *iterables) –> map object
     test that when iterables contain a non-iterable (i.e. int), my_map raises TypeError
     """
     with self.assertRaises(TypeError):
         non_iterable = 1  # int is non-iterable
         iterator = my_map(lambda x: x**2, non_iterable)
         next(iterator)
 def test_first_argument_is_not_callable(self):
     """
     map(func, *iterables) –> map object
     test that when func is not callable, my_map raises TypeError
     """
     with self.assertRaises(TypeError):
         lst = [1, 2, 3]  # not callable
         iterator = my_map(lst, lst)
         next(iterator)
 def test_three_iterables_with_different_lengths(self):
     """
     to test that my_map raises StopIteration when the shortest iterable (i.e. list_2) is consumed
     """
     list_1 = [1, 2, 3, 4, 5]  # an iterable
     list_2 = [5, 2, 4]  # the shortest iterable
     list_3 = [7, 7, 7, 7, 7, 7]  # an iterable
     generator = my_map(get_total, list_1, list_2, list_3)
     expected_list = [13, 11, 14]
     self.assertEqual(expected_list, list(generator))
Exemplo n.º 5
0
import sys
import my_map
import my_reduce

key_value = dict()
for filename in ['data_2010.txt', 'data_2011.txt', 'data_2012.txt', 'data_2013.txt', 'data_2014.txt', 'data_2015.txt']:
    in_file = open(filename, 'r')
    key_value_per_file = my_map.my_map(in_file)
    for key in key_value_per_file:
        if(key in key_value):
            key_value[key].append(key_value_per_file[key])
        else:
            key_value[key]=[key_value_per_file[key]]
reduced = dict()
for key in key_value:
    reduced[key] = my_reduce.my_reduce(key_value[key])
for key in reduced:
    print(key + ": " + str(reduced[key]))
 def test_no_arguments(self):
     with self.assertRaises(TypeError):
         iterator = my_map()
         next(iterator)
 def test_one_argument(self):
     with self.assertRaises(TypeError):
         iterator = my_map(lambda x: x**2)
         next(iterator)