コード例 #1
0
    def test_when_run_where_then_return_correct_values(self):
        enumerable = Enumerable(generate)

        where_enumerable = enumerable.where(lambda x: x > 2)
        self.assertIsInstance(where_enumerable, Enumerable)

        values = where_enumerable.to_list()
        self.assertSequenceEqual(values, [3, 4, 5, 6, 7])
コード例 #2
0
    def test_when_create_several_enumerables_from_same_enumerable_then_return_correct_values(
            self):
        enumerable_1 = Enumerable(generate).where(lambda x: x > 0)

        enumerable_2 = enumerable_1.where(lambda x: x > 4)
        enumerable_3 = enumerable_1.where(lambda x: x < 4)

        self.assertSequenceEqual(enumerable_3.to_list(), [1, 2, 3])
        self.assertSequenceEqual(enumerable_2.to_list(), [5, 6, 7])
コード例 #3
0
    def test_when_run_several_where_in_sequence_then_run_interleaved(self):
        sequence = []

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

        def greater_than_2(x):
            w = x > 2
            sequence.append(2)
            return w

        enumerable = Enumerable(generate)
        values = enumerable.where(greater_than_2).where(less_than_5).to_list()

        self.assertSequenceEqual(values, [3, 4])
        self.assertSequenceEqual(sequence,
                                 [2, 2, 2, 2, 5, 2, 5, 2, 5, 2, 5, 2, 5])