def test_concat_is_deferred(self): a = TracingGenerator() self.assertEqual(a.trace, []) b = TracingGenerator() self.assertEqual(b.trace, []) c = Queryable(a).concat(b).take().to_list() self.assertEqual(a.trace, [0]) self.assertEqual(b.trace, [])
def test_zip_deferred(self): a = TracingGenerator() self.assertEqual(a.trace, []) b = TracingGenerator() self.assertEqual(b.trace, []) c = Queryable(a).zip(b) self.assertEqual(a.trace, []) self.assertEqual(b.trace, []) d = c.take(4).to_list() self.assertEqual(d, [(0, 0), (1, 1), (2, 2), (3, 3)])
def test_select_with_index_deferred(self): a = TracingGenerator() self.assertEqual(a.trace, []) b = Queryable(a).select_with_index() self.assertEqual(a.trace, []) b.take(3).to_list() self.assertEqual(a.trace, [0, 1, 2])
def test_where_deferred(self): a = TracingGenerator() self.assertEqual(a.trace, []) b = Queryable(a).where(lambda x: x % 3 == 0) self.assertEqual(a.trace, []) c = b.take(2).to_list() self.assertEqual(a.trace, [0, 1, 2, 3])
def test_select_deferred(self): a = TracingGenerator() self.assertEqual(a.trace, []) b = Queryable(a).select(lambda x: x * 2) self.assertEqual(a.trace, []) c = b.take(3).to_list() self.assertEqual(a.trace, [0, 1, 2])
def test_default_if_empty_is_deferred_not_empty(self): a = TracingGenerator() self.assertEqual(a.trace, []) b = Queryable(a).default_if_empty(42) self.assertEqual(a.trace, []) c = b.take(3).to_list() self.assertEqual(a.trace, [0, 1, 2])
def test_select_many_with_correspondence_deferred(self): a = TracingGenerator() self.assertEqual(a.trace, []) b = Queryable(a).select_many_with_correspondence(lambda x: [x] * x) self.assertEqual(a.trace, []) b.take(10).to_list() self.assertEqual(a.trace, [0, 1, 2, 3, 4])
def test_skip_is_deferred(self): a = TracingGenerator() self.assertEqual(a.trace, []) b = Queryable(a).skip(3) self.assertEqual(a.trace, []) c = b.take().to_list() self.assertEqual(a.trace, [0, 1, 2, 3])
def test_take_is_deferred(self): a = TracingGenerator() self.assertEqual(a.trace, []) b = Queryable(a).take() self.assertEqual(a.trace, []) c = b.to_list() self.assertEqual(a.trace, [0])
def test_group_join_is_deferred(self): a = TracingGenerator() self.assertEqual(a.trace, []) b = [2, 3, 4, 5, 6] c = Queryable(a).group_join(b) self.assertEqual(a.trace, []) d = c.take(3).to_list()
def test_select_with_args_deferred(self): a = TracingGenerator() self.assertListEqual(a.trace, []) b = Queryable(a).select_with_args(lambda x: x * 2) self.assertListEqual(a.trace, []) b.take(3).to_list() self.assertListEqual(a.trace, list(range(3)))
def test_select_many_with_index_deferred(self): a = TracingGenerator() self.assertEqual(a.trace, []) b = Queryable(a).select_many_with_index( lambda index, source_element: [source_element] * index) self.assertEqual(a.trace, []) b.take(10).to_list() self.assertEqual(a.trace, [0, 1, 2, 3, 4])
def test_join_is_deferred(self): a = TracingGenerator() self.assertEqual(a.trace, []) b = [2, 3, 4, 5, 6] c = Queryable(a).join(b) self.assertEqual(a.trace, []) d = c.take(3).to_list() e = [(2, 2), (3, 3), (4, 4)] self.assertEqual(d, e)
def test_difference_deferred(self): a = TracingGenerator() self.assertEqual(a.trace, []) b = [3, 7, 2, 9, 10] c = Queryable(a).difference(b) self.assertEqual(a.trace, []) d = c.take(10).to_list() e = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] self.assertEqual(a.trace, e)
def test_skip_while_is_deferred(self): a = TracingGenerator() self.assertEqual(a.trace, []) b = Queryable(a).skip_while(lambda x: x < 3) self.assertEqual(a.trace, []) c = b.take(3).to_list() # 3 is included here in the trace because it must have been consumed in order to test # whether it satisfies the predicate self.assertEqual(a.trace, [0, 1, 2, 3, 4, 5])
def test_union_deferred(self): a = TracingGenerator() self.assertEqual(a.trace, []) b = [3, 7, 2, 9, 10] c = Queryable(a).union(b) self.assertEqual(a.trace, []) d = c.take(5).to_list() e = [0, 1, 2, 3, 4] self.assertEqual(a.trace, e)
def test_intersect_deferred(self): a = TracingGenerator() self.assertEqual(a.trace, []) b = [3, 7, 2, 9, 10] c = Queryable(a).intersect(b) self.assertEqual(a.trace, []) d = c.take(5).to_list() e = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] self.assertEqual(a.trace, e)