Example #1
0
    def test_group_by_type(self):
        self.assertEqual({str: {"b": 1, "a": 12}, int: {1: "foo"}}, group_by_type({"a": 12, "b": 1, 1: "foo"}))

        self.assertEqual(
            {str: {"c": 15}, int: {1: "b"}, tuple: {(1, 2): 12, ("a", 1): 1}},
            group_by_type({(1, 2): 12, ("a", 1): 1, 1: "b", "c": 15}),
        )
Example #2
0
    def test_group_by_type(self):
        self.assertEqual({
            str: {
                'b': 1,
                'a': 12
            },
            int: {
                1: 'foo'
            }
        }, group_by_type({
            'a': 12,
            'b': 1,
            1: 'foo'
        }))

        self.assertEqual(
            {
                str: {
                    'c': 15
                },
                int: {
                    1: 'b'
                },
                tuple: {
                    (1, 2): 12,
                    ('a', 1): 1
                }
            }, group_by_type({
                (1, 2): 12,
                ('a', 1): 1,
                1: 'b',
                'c': 15
            }))
Example #3
0
 def test_group_by_type(self):
     self.assertEqual({
         str: {
             'b': 1,
             'a': 12
         },
         int: {
             1: 'foo'
         }
     }, solution.group_by_type({
         'a': 12,
         'b': 1,
         1: 'foo'
     }))
Example #4
0
 def test_group_by_type_with_functions(self):
     double_lambda = lambda x: 2 * x
     self.assertEqual(
         {
             types.LambdaType: {double_lambda: 'double'},
             str: {'three': 3},
             tuple: {('list', 'of', 'numbers'): [42, 73]}
         },
         solution.group_by_type({
             double_lambda: 'double',
             'three': 3,
             ('list', 'of', 'numbers'): [42, 73]
         })
     )
Example #5
0
 def test_group_by_type_with_frozen_set_key(self):
     test_set = frozenset([1, 2, 3])
     self.assertEqual(
         {
             frozenset: {
                 test_set: 15
             },
             tuple: {
                 (1, 2): 12,
                 ('a', 1): 1
             }
         }, solution.group_by_type({
             (1, 2): 12,
             ('a', 1): 1,
             test_set: 15
         }))
Example #6
0
 def test_group_by_type_with_functions(self):
     double_lambda = lambda x: 2 * x
     self.assertEqual(
         {
             types.LambdaType: {
                 double_lambda: 'double'
             },
             str: {
                 'three': 3
             },
             tuple: {
                 ('list', 'of', 'numbers'): [42, 73]
             }
         },
         solution.group_by_type({
             double_lambda: 'double',
             'three': 3,
             ('list', 'of', 'numbers'): [42, 73]
         }))
Example #7
0
 def test_another_group_by_type(self):
     self.assertEqual(
         {
             str: {
                 'c': 15
             },
             int: {
                 1: 'b'
             },
             tuple: {
                 (1, 2): 12,
                 ('a', 1): 1
             }
         },
         solution.group_by_type({
             (1, 2): 12,
             ('a', 1): 1,
             1: 'b',
             'c': 15
         }))
Example #8
0
 def test_group_by_type_empty(self):
     self.assertEqual({}, solution.group_by_type({}))
Example #9
0
 def test_group_by_type_with_frozen_set_key(self):
     test_set = frozenset([1, 2, 3])
     self.assertEqual(
         {frozenset: {test_set: 15}, tuple: {(1, 2): 12, ('a', 1): 1}},
         solution.group_by_type({(1, 2): 12, ('a', 1): 1, test_set: 15}))
Example #10
0
 def test_another_group_by_type(self):
     self.assertEqual(
         {str: {'c': 15}, int: {1: 'b'},
          tuple: {(1, 2): 12, ('a', 1): 1}},
         solution.group_by_type({(1, 2): 12, ('a', 1): 1, 1: 'b', 'c': 15}))
Example #11
0
 def test_group_by_type(self):
     self.assertEqual(
         {str: {'b': 1, 'a': 12}, int: {1: 'foo'}},
         solution.group_by_type({'a': 12, 'b': 1, 1: 'foo'}))
Example #12
0
 def test_group_by_type_empty(self):
         self.assertEqual({}, solution.group_by_type({}))