Esempio n. 1
0
 def testGivenKeyFunctionAsPositionalAttributeGroupsByItsResult(self):
     self.assertEqual(
         {
             2: [(0, 2), (1, 1), (1, 1)],
             3: [(1, 2), (2, 1), (3, 0)]
         },
         groupBy([(1, 2), (2, 1), (0, 2), (3, 0), (1, 1), (1, 1)],
                 lambda x: x[0] + x[1]))
Esempio n. 2
0
 def testGivenKeyFunctionAsKeywordAttributeGroupsByItsResult(self):
     self.assertEqual(
         {
             1: [(1, 1), (2, 1, 8)],
             2: [(1, 2), (3, 2)],
             4: [(3, 4)]
         },
         groupBy([(1, 2), (3, 4), (3, 2), (1, 1), (2, 1, 8)],
                 getKey=operator.itemgetter(1)))
Esempio n. 3
0
 def testKeyFunctionDefaultsToIdentity(self):
   self.assertEqual({1: [1],
                     2: [2]},
                    groupBy([1, 2]))
Esempio n. 4
0
 def testGivenTupleOfNamesOfAttributesGroupsByTheirCombination(self):
   self.assertEqual({(1, 1): [(1, 1)],
                     (1, 2): [(1, 2)],
                     (2, 1): [(2, 1)]},
                    groupBy([Pair(1, 2), Pair(1, 1), Pair(2, 1)], ('a', 'b')))
Esempio n. 5
0
 def testGivenNameOfAttributeGroupsByTheAttribute(self):
   self.assertEqual({1: [(1, 2), (1, 1)],
                     2: [(2, 1)]},
                    groupBy([Pair(1, 2), Pair(1, 1), Pair(2, 1)], 'a'))
Esempio n. 6
0
 def testGivenNoObjectsReturnsEmptyDict(self):
   self.assertEqual({},
                    groupBy([], getKey=lambda x: x[0] + x[1]))
Esempio n. 7
0
 def testGivenTypeAsKeyFunctionGroupsByItsResult(self):
   self.assertEqual({'2': [2, 2],
                     '3': [3]},
                    groupBy([2, 3, 2],
                            getKey=str))
Esempio n. 8
0
 def testGivenKeyFunctionAsPositionalAttributeGroupsByItsResult(self):
   self.assertEqual({2: [(0, 2), (1, 1), (1, 1)],
                     3: [(1, 2), (2, 1), (3, 0)]},
                    groupBy([(1, 2), (2, 1), (0, 2), (3, 0), (1, 1), (1, 1)],
                            lambda x: x[0] + x[1]))
Esempio n. 9
0
 def testRequiredKeysDoNotConflictWithKeysDefinedByInput(self):
     self.assertEqual({1: [1]}, groupBy([1], requiredKeys=[1]))
Esempio n. 10
0
 def testOutputAlwaysContainsRequiredKeys(self):
     self.assertEqual({1: [1], 'a': []}, groupBy([1], requiredKeys=['a']))
Esempio n. 11
0
 def testKeyFunctionDefaultsToIdentity(self):
     self.assertEqual({1: [1], 2: [2]}, groupBy([1, 2]))
Esempio n. 12
0
 def testGivenTupleOfNamesOfAttributesGroupsByTheirCombination(self):
     self.assertEqual({
         (1, 1): [(1, 1)],
         (1, 2): [(1, 2)],
         (2, 1): [(2, 1)]
     }, groupBy([Pair(1, 2), Pair(1, 1), Pair(2, 1)], ('a', 'b')))
Esempio n. 13
0
 def testGivenNameOfAttributeGroupsByTheAttribute(self):
     self.assertEqual({
         1: [(1, 2), (1, 1)],
         2: [(2, 1)]
     }, groupBy([Pair(1, 2), Pair(1, 1), Pair(2, 1)], 'a'))
Esempio n. 14
0
 def testGivenNoObjectsReturnsEmptyDict(self):
     self.assertEqual({}, groupBy([], getKey=lambda x: x[0] + x[1]))
Esempio n. 15
0
 def testGivenTypeAsKeyFunctionGroupsByItsResult(self):
     self.assertEqual({
         '2': [2, 2],
         '3': [3]
     }, groupBy([2, 3, 2], getKey=str))
Esempio n. 16
0
 def testOutputAlwaysContainsRequiredKeys(self):
   self.assertEqual({1: [1],
                     'a': []},
                    groupBy([1], requiredKeys=['a']))
Esempio n. 17
0
 def testRequiredKeysDoNotConflictWithKeysDefinedByInput(self):
   self.assertEqual({1: [1]},
                    groupBy([1], requiredKeys=[1]))
Esempio n. 18
0
 def testGivenKeyFunctionAsKeywordAttributeGroupsByItsResult(self):
   self.assertEqual({1: [(1, 1), (2, 1, 8)],
                     2: [(1, 2), (3, 2)],
                     4: [(3, 4)]},
                    groupBy([(1, 2), (3, 4), (3, 2), (1, 1), (2, 1, 8)],
                            getKey=operator.itemgetter(1)))