コード例 #1
0
 def test_three_item_iterable_sends_three_items(self):
     items = [4, 7, 2, 1, 4]
     collection = CollectingSink()
     sink = collection()
     iterable_source(items, sink)
     result = list(collection)
     self.assertListEqual(result, items)
コード例 #2
0
 def test_three_item_iterable_sends_three_items(self):
     items = [4, 7, 2, 1, 4]
     collection = CollectingSink()
     sink = collection()
     iterable_source(items, sink)
     result = list(collection)
     self.assertListEqual(result, items)
コード例 #3
0
    def test_early_terminating_transducer(self):
        input = [0.0, 0.2, 0.8, 0.9, 1.1, 2.3, 2.6, 3.0, 4.1]
        output = SingularSink()

        iterable_source(iterable=input,
                        target=transduce(first(lambda x: x > 1.0),
                                         target=output()))
        self.assertEqual(output.value, 1.1)
コード例 #4
0
    def test_early_terminating_transducer(self):
        input = [0.0, 0.2, 0.8, 0.9, 1.1, 2.3, 2.6, 3.0, 4.1]
        output = SingularSink()

        iterable_source(iterable=input,
                        target=transduce(first(lambda x: x > 1.0),
                                         target=output()))
        self.assertEqual(output.value, 1.1)
コード例 #5
0
    def test_chained_transducers(self):
        input = [0.0, 0.2, 0.8, 0.9, 1.1, 2.3, 2.6, 3.0, 4.1]
        output = CollectingSink()

        iterable_source(iterable=input,
                        target=transduce(
                            compose(pairwise(),
                                    mapping(lambda p: p[1] - p[0]),
                                    filtering(lambda d: d < 0.5),
                                    mapping(lambda _: "double-click")),
                            target=output()))

        result = list(output)
        self.assertListEqual(result, ['double-click', 'double-click', 'double-click', 'double-click', 'double-click'])
コード例 #6
0
    def test_chained_transducers(self):
        input = [0.0, 0.2, 0.8, 0.9, 1.1, 2.3, 2.6, 3.0, 4.1]
        output = CollectingSink()

        iterable_source(iterable=input,
                        target=transduce(compose(
                            pairwise(), mapping(lambda p: p[1] - p[0]),
                            filtering(lambda d: d < 0.5),
                            mapping(lambda _: "double-click")),
                                         target=output()))

        result = list(output)
        self.assertListEqual(result, [
            'double-click', 'double-click', 'double-click', 'double-click',
            'double-click'
        ])
コード例 #7
0
 def test_empty_iterable_sends_no_items(self):
     collection = CollectingSink()
     sink = collection()
     iterable_source([], sink)
     self.assertEqual(len(collection), 0)
コード例 #8
0
 def test_all_consumed_exits_with_empty_iterator(self):
     items = [4, 7, 2, 1, 4]
     collection = CollectingSink()
     sink = collection()
     remaining = iterable_source(items, sink)
     self.assertIsNone(iterator_or_none(remaining))
コード例 #9
0
 def test_closed_target_exits_with_remaining_items(self):
     items = [4, 7, 2, 1, 4]
     collection = SingularSink()
     sink = collection()
     remaining = iterable_source(items, sink)
     self.assertListEqual(list(remaining), [7, 2, 1, 4])
コード例 #10
0
 def test_empty_iterable_sends_no_items(self):
     collection = CollectingSink()
     sink = collection()
     iterable_source([], sink)
     self.assertEqual(len(collection), 0)
コード例 #11
0
 def test_all_consumed_exits_with_empty_iterator(self):
     items = [4, 7, 2, 1, 4]
     collection = CollectingSink()
     sink = collection()
     remaining = iterable_source(items, sink)
     self.assertIsNone(iterator_or_none(remaining))
コード例 #12
0
 def test_closed_target_exits_with_remaining_items(self):
     items = [4, 7, 2, 1, 4]
     collection = SingularSink()
     sink = collection()
     remaining = iterable_source(items, sink)
     self.assertListEqual(list(remaining), [7, 2, 1, 4])