Esempio n. 1
0
 def test_send_items_then_clear_is_empty(self):
     collection = CollectingSink()
     sink = collection()
     sink.send(64)
     sink.send(128)
     sink.send(256)
     collection.clear()
     self.assertEqual(len(collection), 0)
Esempio n. 2
0
 def test_three_item_iterable_sends_three_items(self):
     items = [4, 7, 2, 1, 4]
     collection = CollectingSink()
     sink = collection()
     poisson_source(1e6, items, sink)
     result = list(collection)
     self.assertListEqual(result, items)
Esempio n. 3
0
 def test_multiple_items_are_retrievable(self):
     collection = CollectingSink()
     sink = collection()
     sink.send(64)
     sink.send(128)
     sink.send(256)
     result = list(collection)
     self.assertListEqual(result, [64, 128, 256])
Esempio n. 4
0
    def test_two_items_returns_two_element_list(self):
        collection = CollectingSink()

        transduce(Transducer,
                  sending(),
                  [23, 78],
                  init=collection())

        self.assertEqual(list(collection), [23, 78])
Esempio n. 5
0
    def test_zero_items_returns_initial_empty_collection(self):
        collection = CollectingSink()

        transduce(Transducer,
                  sending(),
                  empty_iter(),
                  init=collection())

        self.assertEqual(len(collection), 0)
Esempio n. 6
0
 def test_three_items_added_two_dequeued(self):
     collection = CollectingSink()
     sink = collection()
     sink.send(64)
     sink.send(128)
     sink.send(256)
     i = iter(collection)
     next(i)
     next(i)
     self.assertEqual(len(collection), 1)
Esempio n. 7
0
 def test_send_items_to_multiple_sinks(self):
     collection = CollectingSink()
     sink1 = collection()
     sink2 = collection()
     sink1.send(64)
     sink2.send(128)
     sink1.send(256)
     sink2.send(512)
     result = list(collection)
     self.assertListEqual(result, [64, 128, 256, 512])
Esempio n. 8
0
 def test_three_items_added_four_dequeued_raises_stop_iteration(self):
     collection = CollectingSink()
     sink = collection()
     sink.send(64)
     sink.send(128)
     sink.send(256)
     i = iter(collection)
     next(i)
     next(i)
     next(i)
     with self.assertRaises(StopIteration):
         next(i)
Esempio n. 9
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'
        ])
Esempio n. 10
0
 def test_empty_iterable_sends_no_items(self):
     collection = CollectingSink()
     sink = collection()
     iterable_source([], sink)
     self.assertEqual(len(collection), 0)
Esempio n. 11
0
 def test_all_consumed_exits_with_empty_iterator(self):
     items = [4, 7, 2, 1, 4]
     collection = CollectingSink()
     sink = collection()
     remaining = poisson_source(1e6, items, sink)
     self.assertIsNone(iterator_or_none(remaining))
Esempio n. 12
0
 def test_send_single_item_is_retrievable(self):
     collection = CollectingSink()
     sink = collection()
     sink.send(64)
     result = list(collection)
     self.assertListEqual(result, [64])
Esempio n. 13
0
 def test_send_single_item_has_len_one(self):
     collection = CollectingSink()
     sink = collection()
     sink.send(42)
     self.assertEqual(len(collection), 1)
Esempio n. 14
0
 def test_no_items_is_empty(self):
     collection = CollectingSink()
     self.assertEqual(len(collection), 0)
Esempio n. 15
0
 def test_closed_sink_raises_stop_iteration(self):
     collection = CollectingSink()
     sink = collection()
     sink.close()
     with self.assertRaises(StopIteration):
         sink.send(42)