Beispiel #1
0
 def test_groupbu(self):
     expected = {0: [0, 2, 4, 6], 1: [1, 3, 5, 7]}
     self.assertEqual(expected,\
             solution.groupby(lambda x: x % 2, [0,1,2,3,4,5,6,7]))
     expected = {'even': [2, 8, 10, 12], 'odd': [1, 3, 5, 9]}
     self.assertEqual(expected,\
             solution.groupby(lambda x: 'odd' if x % 2 else 'even',\
             [1, 2, 3, 5, 8, 9, 10, 12]))
    def test_groupby(self):
        res1 = {0: [0, 2, 4, 6], 1: [1, 3, 5, 7]}
        res2 = {'even': [2, 8, 10, 12], 'odd': [1, 3, 5, 9]}
        res3 = {0: [0, 3, 6], 1: [1, 4, 7], 2: [2, 5]}

        self.assertEqual(res1, groupby(lambda x: x % 2, [0, 1, 2, 3, 4, 5, 6, 7]))
        self.assertEqual(res2, groupby(lambda x: 'odd' if x % 2 else 'even', [1, 2, 3, 5, 8, 9, 10, 12]))
        self.assertEqual(res3, groupby(lambda x: x % 3, [0, 1, 2, 3, 4, 5, 6, 7]))
Beispiel #3
0
 def test_groupbu(self):
     expected = {0: [0, 2, 4, 6], 1: [1, 3, 5, 7]}
     self.assertEqual(expected,\
             solution.groupby(lambda x: x % 2, [0,1,2,3,4,5,6,7]))
     expected = {'even': [2, 8, 10, 12], 'odd': [1, 3, 5, 9]}
     self.assertEqual(expected,\
             solution.groupby(lambda x: 'odd' if x % 2 else 'even',\
             [1, 2, 3, 5, 8, 9, 10, 12]))
 def test_groupby(self):
     self.assertEqual(groupby(lambda x: x % 2, [0,1,2,3,4,5,6,7]), 
         {0: [0, 2, 4, 6], 1: [1, 3, 5, 7]})
     self.assertEqual(groupby(lambda x: 'odd' if x % 2 else 'even', [1, 2, 3, 5, 8, 9, 10, 12]), 
         {'even': [2, 8, 10, 12], 'odd': [1, 3, 5, 9]})
     self.assertEqual(groupby(lambda x: x % 3, [0, 1, 2, 3, 4, 5, 6, 7]),
         {0: [0, 3, 6], 1: [1, 4, 7], 2: [2, 5]})
     self.assertEqual(groupby(lambda x: 'bigger' if x >= 8 else 'smaller', [1,2,3,4,5,6,7,8,9,10,11,12,13]), 
         {'smaller': [1,2,3,4,5,6,7], 'bigger': [8,9,10,11,12,13]})
Beispiel #5
0
    def test_groupby(self):


        self.assertEqual({0: [0, 2, 4, 6], 1: [1, 3, 5, 7]}, groupby(lambda x: x % 2, [0, 1, 2, 3, 4, 5, 6, 7]))
        # {0: [0, 2, 4, 6], 1: [1, 3, 5, 7]}
        self.assertEqual({'even': [2, 8, 10, 12], 'odd': [1, 3, 5, 9]}, groupby(lambda x: 'odd' if x %
              2 else 'even', [1, 2, 3, 5, 8, 9, 10, 12]))
        # {'even': [2, 8, 10, 12], 'odd': [1, 3, 5, 9]}
        self.assertEqual({0: [0, 3, 6], 1: [1, 4, 7], 2: [2, 5]}, groupby(lambda x: x % 3, [0, 1, 2, 3, 4, 5, 6, 7]))
Beispiel #6
0
 def test_groupby(self):
     expected1 = {0: [0, 2, 4, 6], 1: [1, 3, 5, 7]}
     self.assertEqual(expected1, solution.groupby(lambda x: x % 2, \
         [0,1,2,3,4,5,6,7]))
     expected2 ={'even': [2, 8, 10, 12], 'odd': [1, 3, 5, 9]}
     self.assertEqual(expected2, solution.groupby(lambda x: 'odd' if x % 2 \
         else 'even', [1, 2, 3, 5, 8, 9, 10, 12]))
     expected3 = {0: [0, 3, 6], 1: [1, 4, 7], 2: [2, 5]}
     self.assertEqual(expected3, solution.groupby(lambda x: x % 3, \
         [0, 1, 2, 3, 4, 5, 6, 7]))
Beispiel #7
0
 def test_problem_statement_cases(self):
     self.assertEqual({
         0: [0, 2, 4, 6],
         1: [1, 3, 5, 7]
     }, groupby(lambda x: x % 2, [0, 1, 2, 3, 4, 5, 6, 7]))
     self.assertEqual({
         'even': [2, 8, 10, 12],
         'odd': [1, 3, 5, 9]
     },
                      groupby(lambda x: 'odd' if x % 2 else 'even',
                              [1, 2, 3, 5, 8, 9, 10, 12]))
     self.assertEqual({
         0: [0, 3, 6],
         1: [1, 4, 7],
         2: [2, 5]
     }, groupby(lambda x: x % 3, [0, 1, 2, 3, 4, 5, 6, 7]))
 def test_groupby5(self):
     self.assertEqual({
         "odd": [1, 3, 5, 9],
         "even": [2, 8, 10, 12]
     },
                      solution.groupby(lambda x: 'odd' if x % 2 else 'even',
                                       [1, 2, 3, 5, 8, 9, 10, 12]))
 def test_unique_groupby(self):
     self.assertEqual({
         0: [0, 2, 4, 6],
         1: [1, 3, 5, 7]
     }, solution.groupby(lambda x: x % 2, [0, 1, 2, 3, 4, 5, 6, 7]))
     self.assertEqual({
         'even': [2, 8, 10, 12],
         'odd': [1, 3, 5, 9]
     },
                      solution.groupby(lambda x: 'odd' if x % 2 else 'even',
                                       [1, 2, 3, 5, 8, 9, 10, 12]))
     self.assertEqual({
         0: [0, 3, 6],
         1: [1, 4, 7],
         2: [2, 5]
     }, solution.groupby(lambda x: x % 3, [0, 1, 2, 3, 4, 5, 6, 7]))
 def test_groupby1(self):
     self.assertEqual(
         {
             "big": [35, 40, 45],
             "small": [0, 5, 10, 15, 20, 25, 30]
         },
         solution.groupby(lambda x: 'big' if x > 30 else 'small',
                          range(0, 50, 5)))
Beispiel #11
0
 def test_groupby(self):
     self.assertEqual(groupby(lambda x: x % 2, [0, 1, 2, 3, 4, 5, 6, 7]), {
         0: [0, 2, 4, 6],
         1: [1, 3, 5, 7]
     })
     self.assertEqual(
         groupby(lambda x: 'odd'
                 if x % 2 else 'even', [1, 2, 3, 5, 8, 9, 10, 12]), {
                     'even': [2, 8, 10, 12],
                     'odd': [1, 3, 5, 9]
                 })
     self.assertEqual(groupby(lambda x: x % 3, [0, 1, 2, 3, 4, 5, 6, 7]), {
         0: [0, 3, 6],
         1: [1, 4, 7],
         2: [2, 5]
     })
     self.assertEqual(
         groupby(lambda x: 'bigger' if x >= 8 else 'smaller',
                 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]), {
                     'smaller': [1, 2, 3, 4, 5, 6, 7],
                     'bigger': [8, 9, 10, 11, 12, 13]
                 })
 def test_groupby3(self):
     self.assertEqual({}, solution.groupby(lambda x: x, []))
 def test_groupby_simple_types(self):
     expected = {'even': [2, 8, 10, 12], 'odd': [1, 3, 5, 9]}
     actual = solution.groupby(lambda x: 'odd' if x % 2 else 'even',
                               [1, 2, 3, 5, 8, 9, 10, 12])
     self.assertEqual(expected, actual)
 def test_two(self):
     self.assertEqual({'even': [2, 8, 10, 12], 'odd': [1, 3, 5, 9]}, groupby(lambda x: 'odd' if x % 2 else 'even', [1, 2, 3, 5, 8, 9, 10, 12]))
 def test_groupby(self):
     odd_even = groupby(lambda x: x % 2, [0, 1, 2, 3, 4, 5, 6, 7])
     self.assertEqual(odd_even, {0: [0, 2, 4, 6], 1: [1, 3, 5, 7]})
 def test_groupby5(self):
     self.assertEqual({"odd": [1, 3, 5, 9], "even": [2, 8, 10, 12]}, solution.groupby(lambda x: 'odd' if x % 2 else 'even', [1, 2, 3, 5, 8, 9, 10, 12]))
 def test_three(self):
     self.assertEqual({0: [0, 3, 6], 1: [1, 4, 7], 2: [2, 5]}, groupby(lambda x: x % 3, [0, 1, 2, 3, 4, 5, 6, 7]))
Beispiel #18
0
 def test_groupby_empty(self):
     expected = {}
     actual = solution.groupby(lambda x: x, [])
     self.assertEqual(expected, actual)
Beispiel #19
0
 def test_two(self):
     self.assertEquals(groupby(lambda x: 'odd' if x % 2 else 'even', [1, 2, 3, 5, 8, 9, 10, 12]), {'even': [2, 8, 10, 12], 'odd': [1, 3, 5, 9]})
 def test_groupby1(self):
     self.assertEqual({"big": [35, 40, 45], "small": [0, 5, 10, 15, 20, 25, 30]}, solution.groupby(lambda x: 'big' if x > 30 else 'small', range(0, 50, 5)))
Beispiel #21
0
 def test_groupby_nonequalty(self):
     actual = solution.groupby(lambda x: 'odd' if x%2 else 'even', [1, 2, 3, 4])
     self.assertNotEquals({'even': 42}, actual)
Beispiel #22
0
 def test_group_by_2(self):
     self.assertEqual({'even': [2, 8, 10, 12], 'odd': [1, 3, 5, 9]}, solution.groupby(lambda x: 'odd' if x % 2 else 'even', [1, 2, 3, 5, 8, 9, 10, 12]))
Beispiel #23
0
 def test_group_by_3(self):
     self.assertEqual({0: [0, 3, 6], 1: [1, 4, 7], 2: [2, 5]}, solution.groupby(lambda x: x % 3, [0, 1, 2, 3, 4, 5, 6, 7]))
Beispiel #24
0
 def test_three(self):
     self.assertEquals(groupby(lambda x: x % 3, [0, 1, 2, 3, 4, 5, 6, 7]), {0: [0, 3, 6], 1: [1, 4, 7], 2: [2, 5]})
Beispiel #25
0
 def test_groupby_0(self):
     self.assertEqual({0: [0, 2, 4, 6], 1: [1, 3, 5, 7]}, groupby(lambda x: x % 2, [0, 1, 2, 3, 4, 5, 6, 7]))
Beispiel #26
0
 def test_groupby_simple_types(self):
     expected = {'even': [2, 8, 10, 12], 'odd': [1, 3, 5, 9]}
     actual = solution.groupby(lambda x: 'odd' if x % 2 else 'even',
                               [1, 2, 3, 5, 8, 9, 10, 12])
     self.assertEqual(expected, actual)
Beispiel #27
0
 def test_groupby_1(self):
     self.assertEqual(
         {"even": [2, 8, 10, 12], "odd": [1, 3, 5, 9]},
         groupby(lambda x: "odd" if x % 2 else "even", [1, 2, 3, 5, 8, 9, 10, 12]),
     )
Beispiel #28
0
 def test_one(self):
     self.assertEquals(groupby(lambda x: x % 2, [0,1,2,3,4,5,6,7]), {0: [0, 2, 4, 6], 1: [1, 3, 5, 7]})
Beispiel #29
0
 def test_group_by_1(self):
     self.assertEqual({0: [0, 2, 4, 6], 1: [1, 3, 5, 7]}, solution.groupby(lambda x: x % 2, [0,1,2,3,4,5,6,7]))
Beispiel #30
0
 def test_groupby_no_repetitions(self):
     expected = {1:[1], 2:[2], 3:[3], 5:[5], 'se7en':['se7en']}
     actual = solution.groupby(lambda x: x, [1, 2, 3, 5,'se7en'], )
     self.assertEqual(expected, actual)
Beispiel #31
0
 def test_groupby_with_generator(self):
     expected = {'big': [35, 40, 45], 'small': [0, 5, 10, 15, 20, 25, 30]}
     actual = solution.groupby(lambda x: 'big' if x > 30 else 'small', range(0, 50, 5))
     self.assertEqual(expected, actual)
 def test_groupby3(self):
     self.assertEqual({}, solution.groupby(lambda x: x, []))