Ejemplo n.º 1
0
def test_hash_nun():
    x = Nun()
    y = Nun()

    assert x == y
    assert hash(x) == hash(y)
Ejemplo n.º 2
0
def test_is_nun_with_nun():
    x = Nun()

    assert x.is_nun()
Ejemplo n.º 3
0
def test_get_or_insert_with_with_nun():
    x = Nun()

    assert x.get_or_insert_with(lambda: 5) == 5
    assert isinstance(x, Some)
Ejemplo n.º 4
0
def test_err_with_ok():
    x = Ok(2)

    assert x.err() == Nun()
Ejemplo n.º 5
0
def test_is_some_with_nun():
    x = Nun()

    assert not x.is_some()
Ejemplo n.º 6
0
def test_unwrap_or_else_with_nun(mocker):
    x = Nun()
    func = mocker.MagicMock(return_value = 0)

    assert x.unwrap_or_else(func) == 0
    assert func.call_count == 1
Ejemplo n.º 7
0
def test_map_or_with_nun():
    x = Nun()

    assert x.map_or(lambda y: y ** 2, 0) == 0
Ejemplo n.º 8
0
def test_and_with_nun_nun():
    x = Nun()
    y = Nun()

    assert x.and_(y) == Nun()
Ejemplo n.º 9
0
def test_and_then_with_nun():
    x = Nun()

    assert x.and_then(lambda y: y ** 2) == Nun()
Ejemplo n.º 10
0
def test_and_with_some_nun():
    x = Some(2)
    y = Nun()

    assert x.and_(y) == Nun()
Ejemplo n.º 11
0
def test_and_with_nun_some():
    x = Nun()
    y = Some(2)

    assert x.and_(y) == Nun()
Ejemplo n.º 12
0
def test_iter_with_nun():
    x = Nun()

    assert list(iter(x)) == []
Ejemplo n.º 13
0
def test_ok_or_else_with_nun():
    x = Nun()

    assert x.ok_or_else(lambda: Exception('error message')) == Err(Exception('error message'))
Ejemplo n.º 14
0
def test_ok_or_with_nun():
    x = Nun()

    assert x.ok_or(Exception('error message')) == Err(Exception('error message'))
Ejemplo n.º 15
0
def test_unwrap_with_nun():
    x = Nun()

    with pytest.raises(Panic):
        x.unwrap()
Ejemplo n.º 16
0
def test_or_with_some_nun():
    x = Some(2)
    y = Nun()

    assert x.or_(y) == Some(2)
Ejemplo n.º 17
0
def test_unwrap_or_with_nun():
    x = Nun()

    assert x.unwrap_or(0) == 0
Ejemplo n.º 18
0
def test_or_with_nun_some():
    x = Nun()
    y = Some(2)

    assert x.or_(y) == Some(2)
Ejemplo n.º 19
0
def test_map_with_nun():
    x = Nun()

    assert x.map(lambda y: y ** 2) == Nun()
Ejemplo n.º 20
0
def test_or_with_nun_nun():
    x = Nun()
    y = Nun()

    assert x.or_(y) == Nun()
Ejemplo n.º 21
0
def test_ok_with_err():
    x = Err(Exception("error message"))

    assert x.ok() == Nun()
Ejemplo n.º 22
0
def test_or_else_with_nun():
    x = Nun()

    assert x.or_else(lambda: 5) == Some(5)
Ejemplo n.º 23
0
 def fm(x):
     if x % 2 == 0:
         return Some(x**2)
     else:
         return Nun()
Ejemplo n.º 24
0
def test_map_or_else_with_nun():
    x = Nun()

    assert x.map_or_else(lambda y: y ** 2, lambda: 0) == 0