Exemplo n.º 1
0
    def test_aggregate_3(self):
        expected = {1: [3, 4], 2: [3, 4]}
        lengths = dict(
            aggregate(lambda g: list(map(len, (i[1] for i in g))),
                      groupby(lambda v: v[0], self.data)))

        self.assertDictEqual(expected, lengths)
Exemplo n.º 2
0
    def test_aggregate_2(self):
        expected = {1: 2, 2: 2}
        counts = dict(
            aggregate(functools.partial(reduce, lambda i, v: i + 1, initial=0),
                      groupby(lambda v: v[0], self.data)))

        self.assertDictEqual(expected, counts)
Exemplo n.º 3
0
    def test_aggregate_1(self):
        expected = {1: ['foo', 'spam'], 2: ['bar', 'eggs']}
        grouping = dict(
            aggregate(lambda g: [i for k, i in g],
                      groupby(lambda v: v[0], self.data)))

        self.assertDictEqual(expected, grouping)
Exemplo n.º 4
0
    def test_aggregate_4(self):
        expected = {1: 7, 2: 7}
        sum_of_lengths = dict(
            aggregate(
                functools.partial(reduce, lambda l, s: l + len(s), initial=0),
                aggregate(lambda g: list(i[1] for i in g),
                          groupby(lambda v: v[0], self.data))))

        self.assertDictEqual(expected, sum_of_lengths)
Exemplo n.º 5
0
 def test_aggregate_5(self):
     result = dict(aggregate(None, groupby(lambda v: v[0], self.data)))
     expected = {1: [(1, 'foo'), (1, 'spam')], 2: [(2, 'bar'), (2, 'eggs')]}
     self.assertDictEqual(expected, result)
Exemplo n.º 6
0
    def test_groupby_1(self):
        expected = {1: [(1, 'foo'), (1, 'spam')], 2: [(2, 'bar'), (2, 'eggs')]}

        grouping = dict(groupby(lambda v: v[0], self.data))

        self.assertDictEqual(expected, grouping)