Example #1
0
def test_callpipe():

    # -- set up some 1-variable functions
    a2 = scope.partial("add", 2)
    a3 = scope.partial("add", 3)

    def s9(a):
        return scope.sub(a, 9)

    # x + 2 + 3 - 9 == x - 4
    r = scope.callpipe1([a2, a3, s9], 5)
    thing = rec_eval(r)
    assert thing == 1
Example #2
0
def test_callpipe():

    # -- set up some 1-variable functions
    a2 = scope.partial('add', 2)
    a3 = scope.partial('add', 3)

    def s9(a):
        return scope.sub(a, 9)

    # x + 2 + 3 - 9 == x - 4
    r = scope.callpipe1([a2, a3, s9], 5)
    thing = rec_eval(r)
    assert thing == 1
Example #3
0
def test_partial():
    add2 = scope.partial("add", 2)
    print(add2)
    assert len(str(add2).split("\n")) == 3

    # add2 evaluates to a scope method
    thing = rec_eval(add2)
    print(thing)
    assert "SymbolTableEntry" in str(thing)

    # add2() evaluates to a failure because it's only a partial application
    assert_raises(NotImplementedError, rec_eval, add2())

    # add2(3) evaluates to 5 because we've filled in all the blanks
    thing = rec_eval(add2(3))
    print(thing)
    assert thing == 5
Example #4
0
def test_partial():
    add2 = scope.partial('add', 2)
    print(add2)
    assert len(str(add2).split('\n')) == 3

    # add2 evaluates to a scope method
    thing = rec_eval(add2)
    print(thing)
    assert 'SymbolTableEntry' in str(thing)

    # add2() evaluates to a failure because it's only a partial application
    assert_raises(NotImplementedError, rec_eval, add2())

    # add2(3) evaluates to 5 because we've filled in all the blanks
    thing = rec_eval(add2(3))
    print(thing)
    assert thing == 5