Пример #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]))
Пример #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)))
Пример #3
0
 def testKeyFunctionDefaultsToIdentity(self):
   self.assertEqual({1: [1],
                     2: [2]},
                    groupBy([1, 2]))
Пример #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')))
Пример #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'))
Пример #6
0
 def testGivenNoObjectsReturnsEmptyDict(self):
   self.assertEqual({},
                    groupBy([], getKey=lambda x: x[0] + x[1]))
Пример #7
0
 def testGivenTypeAsKeyFunctionGroupsByItsResult(self):
   self.assertEqual({'2': [2, 2],
                     '3': [3]},
                    groupBy([2, 3, 2],
                            getKey=str))
Пример #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]))
Пример #9
0
 def testRequiredKeysDoNotConflictWithKeysDefinedByInput(self):
     self.assertEqual({1: [1]}, groupBy([1], requiredKeys=[1]))
Пример #10
0
 def testOutputAlwaysContainsRequiredKeys(self):
     self.assertEqual({1: [1], 'a': []}, groupBy([1], requiredKeys=['a']))
Пример #11
0
 def testKeyFunctionDefaultsToIdentity(self):
     self.assertEqual({1: [1], 2: [2]}, groupBy([1, 2]))
Пример #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')))
Пример #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'))
Пример #14
0
 def testGivenNoObjectsReturnsEmptyDict(self):
     self.assertEqual({}, groupBy([], getKey=lambda x: x[0] + x[1]))
Пример #15
0
 def testGivenTypeAsKeyFunctionGroupsByItsResult(self):
     self.assertEqual({
         '2': [2, 2],
         '3': [3]
     }, groupBy([2, 3, 2], getKey=str))
Пример #16
0
 def testOutputAlwaysContainsRequiredKeys(self):
   self.assertEqual({1: [1],
                     'a': []},
                    groupBy([1], requiredKeys=['a']))
Пример #17
0
 def testRequiredKeysDoNotConflictWithKeysDefinedByInput(self):
   self.assertEqual({1: [1]},
                    groupBy([1], requiredKeys=[1]))
Пример #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)))