Exemplo n.º 1
0
def test_nth():
    assert F.nth(2, [1,2,3]) == F.right(3)
    assert F.nth(8, [1,2,3]) == F.left(8)
    assert F.head([1,2,3]) == F.right(1)
    assert F.last([1,2,3]) == F.right(3)
    assert F.head([]) == F.left(0)
    assert F.last([]) == F.left(-1)
Exemplo n.º 2
0
def test_liftA2():
    @F.curry
    def add(a,b):
        return a + b

    assert F.liftA2(add, F.right(1), F.right(2)) == F.right(3)
    assert F.liftA2(add, F.left(1), F.right(2)) == F.left(1)
    assert F.liftA2(add, F.right(1), F.left(2)) == F.left(2)
    assert F.liftA2(add, F.left(1), F.left(2)) == F.left(1)
Exemplo n.º 3
0
def test_ap():
    @F.curry
    def add(a,b):
        return a + b

    assert F.ap(F.map(add, F.right(1)), F.right(2)) == F.right(3)
    assert F.ap(F.map(add, F.left(1)), F.right(2)) == F.left(1)
    assert F.ap(F.map(add, F.right(1)), F.left(2)) == F.left(2)
    assert F.ap(F.map(add, F.left(1)), F.left(2)) == F.left(1)
Exemplo n.º 4
0
def test_mut():
    x = F.right(9)
    z = x.data
    z = 33
    assert x == F.right(9)
Exemplo n.º 5
0
def test_or_else():
    assert F.or_else(lambda a: a + 1, F.left(1)) == 2
    assert F.or_else(lambda a: a + 1, F.right(1)) == 1
Exemplo n.º 6
0
def test_either():
    assert F.either(lambda a: a + 1, lambda a: a + 2, F.left(1)) == 2
    assert F.either(lambda a: a + 1, lambda a: a + 2, F.right(1)) == 3
Exemplo n.º 7
0
def test_chain():
    assert F.chain(lambda a: a + 1, F.left(1)) == F.left(1)
    assert F.chain(lambda a: a + 1, F.right(1)) == 2
    assert F.chain(lambda a: F.right(a + 1), F.right(1)) == F.right(2)
Exemplo n.º 8
0
def test_map():
    assert F.map(lambda a: a + 1, [1,2,3]) == [2,3,4]
    assert F.map(lambda a: a + 1, F.left(1)) == F.left(1)
    assert F.map(lambda a: a + 1, F.right(1)) == F.right(2)
Exemplo n.º 9
0
def test_map_result():
    assert F.map_result(lambda a: a + 1, F.left(1)) == F.left(1)
    assert F.map_result(lambda a: a + 1, F.right(1)) == F.right(2)
Exemplo n.º 10
0
def test_right():
    assert F.right(1) == F.Result(True, 1)
Exemplo n.º 11
0
def test_evolve():
    assert F.evolve("a", lambda a: a + 1, {"a": 1}) == F.right({"a": 2})
    assert F.evolve("b", lambda a: a + 1, {"a": 1}) == F.left("b")
Exemplo n.º 12
0
def test_prop():
    assert F.prop("a")({"a": 3}) == F.right(3)
    assert F.prop("b")({"a": 3}) == F.left("b")