Beispiel #1
0
def test_ok_or_else_with_some():
    x = Some(2)

    assert x.ok_or_else(lambda: Exception('error message')) == Ok(2)
Beispiel #2
0
def test_get_or_insert_with_with_some():
    x = Some(2)

    assert x.get_or_insert_with(lambda: 5) == 2
Beispiel #3
0
def test_map_or_else_with_some():
    x = Some(2)

    assert x.map_or_else(lambda y: y ** 2, lambda: 0) == 4
Beispiel #4
0
def test_err_with_err():
    x = Err(Exception("error message"))

    assert x.err() == Some("error message")
Beispiel #5
0
def test_is_some_with_some():
    x = Some(2)

    assert x.is_some()
Beispiel #6
0
def test_map_with_some():
    x = Some(2)

    assert x.map(lambda y: y ** 2) == Some(4)
Beispiel #7
0
def test_and_then_with_some():
    x = Some(2)

    assert x.and_then(lambda y: y ** 2) == Some(4)
Beispiel #8
0
def test_unwrap_with_some():
    x = Some(2)

    assert x.unwrap() == 2
Beispiel #9
0
def test_and_with_nun_some():
    x = Nun()
    y = Some(2)

    assert x.and_(y) == Nun()
Beispiel #10
0
def test_is_nun_with_some():
    x = Some(2)

    assert not x.is_nun()
Beispiel #11
0
def test_and_with_some_nun():
    x = Some(2)
    y = Nun()

    assert x.and_(y) == Nun()
Beispiel #12
0
def test_and_with_some_some():
    x = Some(2)
    y = Some(3)

    assert x.and_(y) == Some(3)
Beispiel #13
0
def test_iter_with_some():
    x = Some(2)

    assert list(iter(x)) == [2]
Beispiel #14
0
def test_hash_some():
    x = Some(2)
    y = Some(2)

    assert x == y
    assert hash(x) == hash(y)
Beispiel #15
0
def test_or_with_some_some():
    x = Some(2)
    y = Some(3)

    assert x.or_(y) == Some(2)
Beispiel #16
0
def test_hash_some_not_eq():
    x = Some(2)
    y = Some(3)

    assert x != y
    assert hash(x) != hash(y)
Beispiel #17
0
def test_or_with_some_nun():
    x = Some(2)
    y = Nun()

    assert x.or_(y) == Some(2)
Beispiel #18
0
def test_unwrap_or_with_some():
    x = Some(2)

    assert x.unwrap_or(0) == 2
Beispiel #19
0
def test_or_with_nun_some():
    x = Nun()
    y = Some(2)

    assert x.or_(y) == Some(2)
Beispiel #20
0
def test_unwrap_or_else_with_some(mocker):
    x = Some(2)
    func = mocker.MagicMock(return_value = 0)

    assert x.unwrap_or_else(func) == 2
    assert func.call_count == 0
Beispiel #21
0
def test_or_else_with_some():
    x = Some(2)

    assert x.or_else(lambda: 5) == Some(2)
Beispiel #22
0
def test_map_or_with_some():
    x = Some(2)

    assert x.map_or(lambda y: y ** 2, 0) == 4
Beispiel #23
0
def test_or_else_with_nun():
    x = Nun()

    assert x.or_else(lambda: 5) == Some(5)
Beispiel #24
0
def test_ok_with_ok():
    x = Ok(2)

    assert x.ok() == Some(2)
Beispiel #25
0
def test_get_or_insert_with_some():
    x = Some(2)

    assert x.get_or_insert(5) == 2
Beispiel #26
0
 def fm(x):
     if x % 2 == 0:
         return Some(x**2)
     else:
         return Nun()
Beispiel #27
0
def test_ok_or_with_some():
    x = Some(2)

    assert x.ok_or(Exception('error message')) == Ok(2)