Beispiel #1
0
 def test_numbers_are_added(self):
     self.assertEqual(
         first=exercise.merge(0, 42),
         second=42,
     )
     self.assertEqual(
         first=exercise.merge(42, 0),
         second=42,
     )
Beispiel #2
0
 def test_complext_dict_update(self):
     self.assertDictEqual(
         d1=exercise.merge(
             {'x': [1, 2, 3],
              'y': 1,
              'z': {1, 2, 3},
              'w': 'foo',
              't': {
                  'a': [1, 2]
              },
              'm': [1]},
             {'x': [4, 5, 6],
              'y': 4,
              'z': {4, 2, 3},
              'w': 'bar',
              't': {
                  'a': [3, 2]
              },
              'm': 'baz',
              'n': 42},
         ),
         d2={'x': [1, 2, 3, 4, 5, 6],
             'y': 5,
             'z': {1, 2, 3, 4},
             'w': 'foobar',
             't': {
                 'a': [1, 2, 3, 2]
             },
             'm': ([1], 'baz'),
             'n': 42},
     )
Beispiel #3
0
 def test_merge_first_longer(self):
     '''Test merge(['a', 'e', 'i', 'o', 'u'], [1, 2, 3])
     '''
     sequence_1 = ['a', 'e', 'i', 'o', 'u']
     sequence_2 = [1, 2, 3]
     expected = ['a', 1, 'e', 2, 'i', 3, 'o', 'u']
     self.assertEqual(list(source.merge(sequence_1, sequence_2)), expected)
Beispiel #4
0
 def test_merge(self):
     '''Test merge([1, 2, 3], ['a', 'b', 'c'])
     '''
     sequence_1 = [1, 2, 3]
     sequence_2 = ['a', 'b', 'c']
     expected = [1, 'a', 2, 'b', 3, 'c']
     self.assertEqual(list(source.merge(sequence_1, sequence_2)), expected)
Beispiel #5
0
 def test_merge_3_sequences(self):
     '''Test merge(['a', 'e', 'i', 'o', 'u'], [None, True, False], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
     '''
     sequence_1 = ['a', 'e', 'i', 'o', 'u']
     sequence_2 = [None, True, False]
     sequence_3 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
     expected = [
         'a', None, 0, 'e', True, 1, 'i', False, 2, 'o', 3, 'u', 4, 5, 6, 7,
         8, 9
     ]
     self.assertEqual(
         list(source.merge(sequence_1, sequence_2, sequence_3)), expected)
Beispiel #6
0
 def test_simple_dict_update(self):
     self.assertDictEqual(
         d1=exercise.merge({'a': 1, 'b': 2, 'c': 3},
                           {'d': 4}),
         d2={'a': 1, 'b': 2, 'c': 3, 'd': 4}
     )
Beispiel #7
0
 def test_set_unionization(self):
     self.assertSetEqual(
         set1=exercise.merge({1, 2}, {3, 4}),
         set2={1, 2, 3, 4}
     )
Beispiel #8
0
 def test_string_concatenation(self):
     self.assertEqual(
         first=exercise.merge('abra', 'cadabra'),
         second='abracadabra'
     )
Beispiel #9
0
 def test_lists_are_concatenated(self):
     self.assertListEqual(
         list1=exercise.merge([1], [2]),
         list2=[1, 2]
     )
Beispiel #10
0
 def test_mismatch(self):
     self.assertTupleEqual(
         tuple1=exercise.merge("foobar", [1, 2, 3]),
         tuple2=("foobar", [1, 2, 3])
     )
Beispiel #11
0
 def test_merge_empty_sequences(self):
     '''Test merge([], [], [])
     '''
     sequence_1 = sequence_2 = sequence_3 = expected = []
     self.assertEqual(
         list(source.merge(sequence_1, sequence_2, sequence_3)), expected)