Esempio n. 1
0
 def test_mpairs(self):
     # lists, iterators are OK
     xs = iter([2, 4, 7, 9, 10, 11, 21])
     ys = [1, 3, 4, 9, 10, 21, 100]
     result = []
     for a, b in mpairs(xs, ys, lambda x: x):
         result.append(a)
     self.assertEqual(result, [4, 9, 10, 21])
Esempio n. 2
0
    def test_mpairs_with_double_dbs(self):
        with dbopen(':memory:') as c1, dbopen(':memory:') as c2:
            c1.save('iris.csv')
            c2.save('co2.csv')

            seq1 = c1.reel(
                """
                select *, round(petal_length) as key from iris
                order by key
                """, group='key')
            seq2 = c2.reel(
                """
                select *, round(uptake / 10) as key from co2
                order by key
                """, group='key')

            lengths = []

            for a, b in mpairs(seq1, seq2, lambda rs: rs[0].key):
                lengths.append((len(a), len(b)))

            self.assertEqual(lengths, [(24, 18), (26, 17),
                                       (3, 24), (26, 24), (43, 1)])