本文整理汇总了Python中streams.Stream.range方法的典型用法代码示例。如果您正苦于以下问题:Python Stream.range方法的具体用法?Python Stream.range怎么用?Python Stream.range使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类streams.Stream
的用法示例。
在下文中一共展示了Stream.range方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_it_should_concatenate_iterables
# 需要导入模块: from streams import Stream [as 别名]
# 或者: from streams.Stream import range [as 别名]
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: test_no_cache
# 需要导入模块: from streams import Stream [as 别名]
# 或者: from streams.Stream import range [as 别名]
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), [])
示例3: test_cache
# 需要导入模块: from streams import Stream [as 别名]
# 或者: from streams.Stream import range [as 别名]
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)))
示例4: test_it_should_iterate_over_an_iterable_multiple_times
# 需要导入模块: from streams import Stream [as 别名]
# 或者: from streams.Stream import range [as 别名]
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), [])
示例5: test_it_should_produce_a_range
# 需要导入模块: from streams import Stream [as 别名]
# 或者: from streams.Stream import range [as 别名]
def test_it_should_produce_a_range(self):
stream = Stream.range(10)
self.assertIsInstance(stream, Stream)
self.assertEqual(list(stream), list(range(10)))
示例6: test_it_should_map_a_predicate_to_values_in_key_value_pairs
# 需要导入模块: from streams import Stream [as 别名]
# 或者: from streams.Stream import range [as 别名]
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)])
示例7: test_it_should_expand_a_stream_to_tuples
# 需要导入模块: from streams import Stream [as 别名]
# 或者: from streams.Stream import range [as 别名]
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)])
示例8: test_it_should_reverse_sort_the_stream
# 需要导入模块: from streams import Stream [as 别名]
# 或者: from streams.Stream import range [as 别名]
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))))
示例9: test_reversed_should_reverse_the_stream
# 需要导入模块: from streams import Stream [as 别名]
# 或者: from streams.Stream import range [as 别名]
def test_reversed_should_reverse_the_stream(self):
stream = Stream.range(10)
reverse = reversed(stream)
self.assertListEqual(list(reverse), list(reversed(range(10))))
示例10: test_it_should_reduce_the_stream
# 需要导入模块: from streams import Stream [as 别名]
# 或者: from streams.Stream import range [as 别名]
def test_it_should_reduce_the_stream(self):
stream = Stream.range(10)
reduced = stream.reduce(add)
self.assertEqual(reduced, sum(range(10)))
示例11: test_range
# 需要导入模块: from streams import Stream [as 别名]
# 或者: from streams.Stream import range [as 别名]
def test_range(self):
self.assertListEqual(list(Stream.range(100)), list(xrange(100)))
示例12: test_it_should_apply_a_side_effect_to_the_stream
# 需要导入模块: from streams import Stream [as 别名]
# 或者: from streams.Stream import range [as 别名]
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)))
示例13: test_it_should_return_the_first_element_without_consuming_it
# 需要导入模块: from streams import Stream [as 别名]
# 或者: from streams.Stream import range [as 别名]
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: test_it_should_exclude_items
# 需要导入模块: from streams import Stream [as 别名]
# 或者: from streams.Stream import range [as 别名]
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])
示例15: test_it_should_count_the_number_of_items_in_the_stream
# 需要导入模块: from streams import Stream [as 别名]
# 或者: from streams.Stream import range [as 别名]
def test_it_should_count_the_number_of_items_in_the_stream(self):
stream = Stream.range(100)
self.assertEqual(stream.count(), 100)