Ejemplo n.º 1
0
 def test_chained_transducers(self):
     result = transduce(transducer=compose(mapping(lambda x: x * x),
                                           filtering(lambda x: x % 5 != 0),
                                           taking(6),
                                           dropping_while(lambda x: x < 15),
                                           distinct()),
                        reducer=appending(),
                        iterable=range(20))
     self.assertSequenceEqual(result, [16, 36, 49])
Ejemplo n.º 2
0
 def test_chained_transducers(self):
     result = transduce(transducer=compose(
                       mapping(lambda x: x*x),
                       filtering(lambda x: x % 5 != 0),
                       taking(6),
                       dropping_while(lambda x: x < 15),
                       distinct()),
                   reducer=appending(),
                   iterable=range(20))
     self.assertSequenceEqual(result, [16, 36, 49])
Ejemplo n.º 3
0
    def test_chained_transducers(self):
        result = transduce(transducer=compose(
                         mapping(lambda x: x*x),
                         filtering(lambda x: x % 5 != 0),
                         taking(6),
                         dropping_while(lambda x: x < 15),
                         distinct()),
                     iterable=range(20))

        expected = [16, 36, 49]
        for r, e in zip(result, expected):
            self.assertEqual(r, e)
Ejemplo n.º 4
0
    def test_chained_transducers(self):
        result = transduce(
            transducer=compose(
                mapping(lambda x: x * x),
                filtering(lambda x: x % 5 != 0),
                taking(6),
                dropping_while(lambda x: x < 15),
                distinct(),
            ),
            iterable=range(20),
        )

        expected = [16, 36, 49]
        for r, e in zip(result, expected):
            self.assertEqual(r, e)
Ejemplo n.º 5
0
 def test_taking_validation(self):
     with self.assertRaises(ValueError):
         transduce(transducer=taking(-3),
                   reducer=appending(),
                   iterable=[2, 4, 5, 8, 10])
Ejemplo n.º 6
0
 def test_taking(self):
     result = transduce(transducer=taking(3),
                        reducer=appending(),
                        iterable=[2, 4, 5, 8, 10])
     self.assertListEqual(result, [2, 4, 5])
Ejemplo n.º 7
0
 def test_taking_validation(self):
     with self.assertRaises(ValueError):
         transduce(transducer=taking(-3),
                   reducer=appending(),
                   iterable=[2, 4, 5, 8, 10])
Ejemplo n.º 8
0
 def test_taking(self):
     result = transduce(transducer=taking(3),
                        reducer=appending(),
                        iterable=[2, 4, 5, 8, 10])
     self.assertListEqual(result, [2, 4, 5])