Exemplo n.º 1
0
    def test_when_run_where_then_enumerate_only_after_to_list(self):
        sequence = []

        def less_than_5(x):
            w = x < 5
            sequence.append(5)
            return w

        enumerable = Enumerable(generate).where(less_than_5).where(less_than_5)
        self.assertTrue(len(sequence) == 0)

        enumerable.to_list()
        self.assertTrue(len(sequence) > 0)
Exemplo n.º 2
0
    def test_when_run_to_list_several_times_then_enumerate_only_once(self):
        sequence = []

        def less_than_5(x):
            w = x < 5
            sequence.append(5)
            return w

        enumerable = Enumerable(generate).where(less_than_5)

        enumerable.to_list()
        counter = len(sequence)

        enumerable.to_list()
        self.assertEqual(counter, len(sequence))
Exemplo n.º 3
0
 def test_when_sort_descending_then_return_values_sorted_descending(self):
     a = Dummy(1, 8)
     b = Dummy(2, 6)
     c = Dummy(3, 4)
     d = Dummy(4, 2)
     dummies = [a, b, c, d]
     values = Enumerable(dummies).sort(lambda x: x.B, descending=True)
     self.assertSequenceEqual(values.to_list(), [a, b, c, d])