Ejemplo n.º 1
0
class TestEvery:
    @pytest.mark.parametrize(
        "predicate, iterable",
        [
            (generic.identical(1), [1, 1, 1]),
            (generic.identical(1), []),
            (numeric.greater(0), [1, 2]),
            (generic.equal("a"), "aa"),
        ],
    )
    def test_returns_true_for_complete_iterable(self,
                                                predicate: Predicate[object],
                                                iterable: Iterable) -> None:
        assert collection.every(predicate)(iterable) is True

    @pytest.mark.parametrize(
        "predicate, iterable",
        [
            (generic.identical(...), [..., "b", "c"]),
            (numeric.greater(1), [-3, 0, 1, 0, 2]),
            (generic.equal("a"), "abc"),
        ],
    )
    def test_returns_false_for_incomplete_iterable(
            self, predicate: Predicate[object], iterable: Iterable) -> None:
        assert collection.every(predicate)(iterable) is False

    def test_repr_contains_bound_parameter(self):
        assert_predicate_name_equals(collection.every(numeric.greater(42)),
                                     "every(greater(42))")
Ejemplo n.º 2
0
class TestExists:
    @pytest.mark.parametrize(
        "predicate, iterable",
        [
            (generic.identical(...), ["a", "b", ...]),
            (numeric.greater(0), [-3, 0, 1, 0]),
            (generic.equal("a"), "cbad"),
        ],
    )
    def test_returns_true_for_iterable_containing_satisfying_item(
            self, predicate: Predicate[object], iterable: Iterable) -> None:
        assert collection.exists(predicate)(iterable) is True

    @pytest.mark.parametrize(
        "predicate, iterable",
        [
            (generic.identical(...), ["a", "b", "c"]),
            (numeric.greater(1), [-3, 0, 1, 0]),
            (generic.equal("a"), "cbed"),
        ],
    )
    def test_returns_false_for_iterable_not_containing_satisfying_item(
            self, predicate: Predicate[object], iterable: Iterable) -> None:
        assert collection.exists(predicate)(iterable) is False

    def test_repr_contains_bound_parameter(self):
        assert_predicate_name_equals(collection.exists(numeric.less(-3)),
                                     "exists(less(-3))")
Ejemplo n.º 3
0
 def test_repr_contains_bound_parameter(self):
     assert_predicate_name_equals(generic.identical("hello"),
                                  "identical('hello')")
Ejemplo n.º 4
0
 def test_returns_false_for_different_values(self, a: object,
                                             b: object) -> None:
     assert generic.identical(a)(b) is False
     assert generic.identical(b)(a) is False
Ejemplo n.º 5
0
 def test_returns_true_for_identical_values(self, a: object,
                                            b: object) -> None:
     assert generic.identical(a)(b) is True
     assert generic.identical(b)(a) is True