Ejemplo n.º 1
0
 def test_with_set(self):
     sequence = {1, 2, 3, 4, 5}
     initial = 5
     self.assertEqual(my_reduce(add, sequence), 15)
     self.assertEqual(my_reduce(add, sequence, initial), 20)
Ejemplo n.º 2
0
    def test_num_args_less_than_2(self):
        with self.assertRaises(TypeError):
            my_reduce()

        with self.assertRaises(TypeError):
            my_reduce(add)
Ejemplo n.º 3
0
 def test_with_one_item_in_the_list(self):
     self.assertEqual(1, my_reduce(add, [1]))
Ejemplo n.º 4
0
 def test_with_list(self):
     sequence = [1, 2, 3]
     initial = 4
     self.assertEqual(my_reduce(add, sequence), 6)
     self.assertEqual(my_reduce(add, sequence, initial), 10)
Ejemplo n.º 5
0
 def test_no_function_provided(self):
     with self.assertRaises(TypeError):
         my_reduce(1, [1,2,3])
Ejemplo n.º 6
0
 def test_empty_sequence_provided(self):
     with self.assertRaises(TypeError):
         my_reduce(add, [])
Ejemplo n.º 7
0
 def test_arg_two_must_support_iteration(self):
     does_not_support_iteration = 4
     with self.assertRaises(TypeError):
         my_reduce(add, does_not_support_iteration)
Ejemplo n.º 8
0
    def test_num_args_greater_than_3(self):
        with self.assertRaises(TypeError):
            my_reduce(add, {1, 2, 3}, 5, 99)

        with self.assertRaises(TypeError):
            my_reduce(add, {1, 2, 3}, 5, 99, 33)
Ejemplo n.º 9
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]))