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])
 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])
Exemple #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)
    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)
 def test_taking_validation(self):
     with self.assertRaises(ValueError):
         transduce(transducer=taking(-3),
                   reducer=appending(),
                   iterable=[2, 4, 5, 8, 10])
 def test_taking(self):
     result = transduce(transducer=taking(3),
                        reducer=appending(),
                        iterable=[2, 4, 5, 8, 10])
     self.assertListEqual(result, [2, 4, 5])
 def test_taking_validation(self):
     with self.assertRaises(ValueError):
         transduce(transducer=taking(-3),
                   reducer=appending(),
                   iterable=[2, 4, 5, 8, 10])
 def test_taking(self):
     result = transduce(transducer=taking(3),
                        reducer=appending(),
                        iterable=[2, 4, 5, 8, 10])
     self.assertListEqual(result, [2, 4, 5])