from clarabot_nano.utility.algorithm import chain_call


def test_chain_call_single():
    def x(a):
        return a+1

    def y(a):
        return a-2

    assert chain_call([x, x, x], 5) == 8
    assert chain_call([y, y, y], 5) == -1
    assert chain_call([x, y, x], 5) == 5
    assert chain_call([y, x, y], 5) == 2


def test_chain_call_multi():
    def x(a, b):
        return a+1, a+b

    def y(a, b):
        return a-2, a+b

    assert chain_call([x, x, x], 5, 10) == (8, 28)
    assert chain_call([y, y, y], 5, 10) == (-1, 19)
    assert chain_call([x, y, x], 5, 10) == (5, 25)
    assert chain_call([y, x, y], 5, 10) == (2, 22)
