Пример #1
0
    def test_it_should_concatenate_iterables(self):
        stream = Stream.concat(Stream.range(10), Stream.range(10))
        self.assertListEqual(list(stream), list(xrange(10)) + list(xrange(10)))

        stream = Stream.concat(xrange(10), xrange(10), xrange(10))
        self.assertListEqual(list(stream.distinct()), list(xrange(10)))

        stream = Stream.concat(xrange(10), xrange(10), xrange(10))
        self.assertEqual(stream.count(), 30)
Пример #2
0
    def test_it_should_concatenate_iterables(self):
        stream = Stream.concat(Stream.range(10), Stream.range(10))
        self.assertListEqual(list(stream), list(xrange(10)) + list(xrange(10)))

        stream = Stream.concat(xrange(10), xrange(10), xrange(10))
        self.assertListEqual(list(stream.distinct()), list(xrange(10)))

        stream = Stream.concat(xrange(10), xrange(10), xrange(10))
        self.assertEqual(stream.count(), 30)
Пример #3
0
 def test_no_cache(self):
     # Make a normal stream.
     stream = Stream.range(10)
     # Iterate once
     self.assertEqual(list(stream), list(range(10)))
     # Iterate twice
     self.assertEqual(list(stream), [])
Пример #4
0
 def test_no_cache(self):
     # Make a normal stream.
     stream = Stream.range(10)
     # Iterate once
     self.assertEqual(list(stream), list(range(10)))
     # Iterate twice
     self.assertEqual(list(stream), [])
Пример #5
0
    def test_for_each(self):
        class Apply:
            def __init__(self):
                self.total = 0

            def apply(self, val):
                self.total += val

        stream = Stream.range(3)
        apply = Apply()
        stream.for_each(apply.apply)
        self.assertEqual(apply.total, 0 + 1 + 2)
Пример #6
0
    def test_cache(self):
        # Make a cached stream.
        stream = Stream.range(10).cache()
        # Iterate once
        self.assertEqual(list(stream), list(range(10)))
        # Iterate twice, this time from the cache.
        self.assertEqual(list(stream), list(range(10)))

        # Now, we make a new, smaller, cached stream fromm our cached stream.
        stream = stream.cache(5)
        # Iterate once
        self.assertEqual(list(stream), list(range(10)))
        # Iterate twice, this time from the cache. We get the last 5 values.
        self.assertEqual(list(stream), list(range(5, 10)))
Пример #7
0
    def test_cache(self):
        # Make a cached stream.
        stream = Stream.range(10).cache()
        # Iterate once
        self.assertEqual(list(stream), list(range(10)))
        # Iterate twice, this time from the cache.
        self.assertEqual(list(stream), list(range(10)))

        # Now, we make a new, smaller, cached stream fromm our cached stream.
        stream = stream.cache(5)
        # Iterate once
        self.assertEqual(list(stream), list(range(10)))
        # Iterate twice, this time from the cache. We get the last 5 values.
        self.assertEqual(list(stream), list(range(5, 10)))
Пример #8
0
 def test_it_should_count_the_number_of_items_in_the_stream(self):
     stream = Stream.range(100)
     self.assertEqual(stream.count(), 100)
Пример #9
0
 def test_it_should_iterate_over_an_iterable_multiple_times(self):
     stream = Stream.range(10)
     self.assertListEqual(list(stream), list(xrange(10)))
     self.assertListEqual(list(stream), [])
Пример #10
0
 def test_it_should_reduce_the_stream(self):
     stream = Stream.range(10)
     reduced = stream.reduce(add)
     self.assertEqual(reduced, sum(range(10)))
Пример #11
0
 def test_it_should_reverse_sort_the_stream(self):
     stream = Stream.range(10)
     sorted = stream.sorted(reverse=True)
     self.assertListEqual(list(sorted), list(reversed(range(10))))
Пример #12
0
 def test_range(self):
     self.assertListEqual(list(Stream.range(100)), list(xrange(100)))
Пример #13
0
 def test_it_should_return_the_first_element_without_consuming_it(self):
     stream = Stream.range(10)
     self.assertEqual(stream.first, 0)
     self.assertEqual(stream.first, 0)
     self.assertEqual(stream.first, 0)
     self.assertListEqual(list(stream), list(xrange(10)))
Пример #14
0
 def test_dict_is_created_correctly(self):
     stream = Stream.range(3).tuplify()
     self.assertDictEqual(stream.to_dict(), {0: 0, 1: 1, 2: 2})
Пример #15
0
 def test_it_should_map_a_predicate_to_values_in_key_value_pairs(self):
     stream = Stream.range(10).tuplify()
     mapped = stream.value_map(lambda v: v**2)
     self.assertListEqual(list(mapped), [(x, x**2) for x in xrange(10)])
Пример #16
0
    def test_it_should_expand_a_stream_to_tuples(self):
        tuples = Stream.range(10).tuplify()
        self.assertListEqual(list(tuples), [(i, i) for i in range(10)])

        tuples = Stream.range(10).tuplify(clones=4)
        self.assertListEqual(list(tuples), [(i, i, i, i) for i in range(10)])
Пример #17
0
 def test_it_should_reverse_sort_the_stream(self):
     stream = Stream.range(10)
     sorted = stream.sorted(reverse=True)
     self.assertListEqual(list(sorted), list(reversed(range(10))))
Пример #18
0
 def test_reversed_should_reverse_the_stream(self):
     stream = Stream.range(10)
     reverse = reversed(stream)
     self.assertListEqual(list(reverse), list(reversed(range(10))))
Пример #19
0
 def test_it_should_exclude_items(self):
     stream = Stream.range(10)
     odds = stream.exclude(lambda x: x % 2)
     self.assertListEqual(list(odds), [1, 3, 5, 7, 9])
Пример #20
0
 def test_set_is_created_correctly(self):
     stream = Stream.range(3)
     self.assertSetEqual(stream.to_set(), {0, 1, 2})
Пример #21
0
 def test_it_should_return_the_first_element_without_consuming_it(self):
     stream = Stream.range(10)
     self.assertEqual(stream.first, 0)
     self.assertEqual(stream.first, 0)
     self.assertEqual(stream.first, 0)
     self.assertListEqual(list(stream), list(xrange(10)))
Пример #22
0
 def test_list_is_created_correctly(self):
     stream = Stream.range(3)
     self.assertListEqual(stream.to_list(), [0, 1, 2])
Пример #23
0
 def test_it_should_apply_a_side_effect_to_the_stream(self):
     side_list = []
     stream = Stream.range(10)
     self.assertEqual(side_list, list(stream.peek(side_list.append)))
Пример #24
0
 def test_it_should_map_a_predicate_to_values_in_key_value_pairs(self):
     stream = Stream.range(10).tuplify()
     mapped = stream.value_map(lambda v: v ** 2)
     self.assertListEqual(list(mapped), [(x, x ** 2) for x in xrange(10)])
Пример #25
0
 def test_it_should_reduce_the_stream(self):
     stream = Stream.range(10)
     reduced = stream.reduce(add)
     self.assertEqual(reduced, sum(range(10)))
Пример #26
0
 def test_it_should_apply_a_side_effect_to_the_stream(self):
     side_list = []
     stream = Stream.range(10)
     self.assertEqual(side_list, list(stream.peek(side_list.append)))
Пример #27
0
 def test_reversed_should_reverse_the_stream(self):
     stream = Stream.range(10)
     reverse = reversed(stream)
     self.assertListEqual(list(reverse), list(reversed(range(10))))
Пример #28
0
 def test_it_should_exclude_items(self):
     stream = Stream.range(10)
     odds = stream.exclude(lambda x: x % 2)
     self.assertListEqual(list(odds), [1, 3, 5, 7, 9])
Пример #29
0
    def test_it_should_expand_a_stream_to_tuples(self):
        tuples = Stream.range(10).tuplify()
        self.assertListEqual(list(tuples), [(i, i) for i in range(10)])

        tuples = Stream.range(10).tuplify(clones=4)
        self.assertListEqual(list(tuples), [(i, i, i, i) for i in range(10)])
Пример #30
0
 def test_range(self):
     self.assertListEqual(list(Stream.range(100)), list(xrange(100)))
Пример #31
0
 def test_it_should_produce_a_range(self):
     stream = Stream.range(10)
     self.assertIsInstance(stream, Stream)
     self.assertEqual(list(stream), list(range(10)))
Пример #32
0
 def test_it_should_produce_a_range(self):
     stream = Stream.range(10)
     self.assertIsInstance(stream, Stream)
     self.assertEqual(list(stream), list(range(10)))
Пример #33
0
 def test_it_should_iterate_over_an_iterable_multiple_times(self):
     stream = Stream.range(10)
     self.assertListEqual(list(stream), list(xrange(10)))
     self.assertListEqual(list(stream), [])
Пример #34
0
 def test_it_should_count_the_number_of_items_in_the_stream(self):
     stream = Stream.range(100)
     self.assertEqual(stream.count(), 100)