예제 #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])