def test_it_should_count_the_number_of_occurrences_in_the_stream(self): stream = Stream(xrange(100)) stream = stream.limit(50) self.assertEqual(stream.count(), 50) stream = Stream(xrange(100)) stream = stream.limit(1000) self.assertEqual(stream.count(), 100)
def test_it_should_limit_the_size_of_the_stream(self): stream = Stream(xrange(10000000000)) limited = stream.limit(10) self.assertListEqual(list(limited), list(xrange(10))) stream = Stream(xrange(100)) stream = stream.limit(1000) self.assertListEqual(list(stream), list(xrange(100)))
def test_limit(self): stream = Stream(xrange(100)) stream = stream.limit(50) self.assertEqual(stream.count(), 50) stream = Stream(xrange(100)) stream = stream.limit(1000) self.assertEqual(stream.count(), 100)
def test_it_should_filter_items(self): stream = Stream(range(10)) stream = stream.filter(lambda item: item % 2) self.assertEqual(stream.sum(), 25) stream = Stream(dict((v, v) for v in xrange(100))) stream = stream.filter(lambda kv: kv[0] % 2) stream = stream.filter(lambda kv: kv[0] % 10, parallel=6) stream = stream.limit(5).keys() stream = list(stream) self.assertListEqual(list(stream), [1, 3, 5, 7, 9])