Beispiel #1
0
def test_empty_match(if_some: Callable[[object], _U],
                     if_empty: Callable[[], _U], exp: _U) -> None:
    assert Empty().match(if_some=if_some, if_empty=if_empty) == exp
Beispiel #2
0
def test_empty_map(_: object, fn: Callable[[object], object]) -> None:
    assert Empty().map(fn) == Empty()
Beispiel #3
0
def test_empty_flat_map(_v: object, fn: Callable[[object], Maybe[_U]],
                        _exp: object) -> None:
    assert Empty().flat_map(fn) == Empty()
Beispiel #4
0
def test_empty_unwrap_raises_error() -> None:
    with pytest.raises(ValueError):
        Empty().unwrap()
Beispiel #5
0
def test_empty_is_hashable() -> None:
    {Empty()}
Beispiel #6
0
def test_some_and_empty_are_not_equal(v: object) -> None:
    assert Some(v) != Empty() and Empty() != Some(v)
Beispiel #7
0
def test_empty_eq_is_reflexive_and_symmetric() -> None:
    assert Empty() == Empty()
Beispiel #8
0
                          # todo more test cases
                          ]


@pytest.mark.parametrize('v, fn', _MAP_TEST_CASES)
def test_some_map(v: _T, fn: Callable[[_T], object]) -> None:
    assert Some(v).map(fn) == Some(fn(v))


@pytest.mark.parametrize('_, fn', _MAP_TEST_CASES)
def test_empty_map(_: object, fn: Callable[[object], object]) -> None:
    assert Empty().map(fn) == Empty()


_FLATMAP_TEST_CASES: Final = [(1, lambda x: Some(x + 1), Some(2)),
                              (1, lambda x: Empty(), Empty())
                              # todo more test cases
                              ]


@pytest.mark.parametrize('v, fn, exp', _FLATMAP_TEST_CASES)
def test_some_flat_map(v: _T, fn: Callable[[_T], Maybe[_U]],
                       exp: Maybe[_U]) -> None:
    assert Some(v).flat_map(fn) == exp


@pytest.mark.parametrize('_v, fn, _exp', _FLATMAP_TEST_CASES)
def test_empty_flat_map(_v: object, fn: Callable[[object], Maybe[_U]],
                        _exp: object) -> None:
    assert Empty().flat_map(fn) == Empty()