Exemplo n.º 1
0
def test_partial():
    @coppertop
    def myunary_(a, b, c):
        return a + b + c
    t = myunary_ >> typeOf
    assert t == (BTTuple(NO_TYPE, NO_TYPE, NO_TYPE)^NO_TYPE)

    @coppertop
    def myunary(a:pyint, b:pyint, c:pyint) -> pyint:
        return a + b + c

    myunary >> check >> typeOf >> ((pyint*pyint*pyint)^pyint)
    myunary(1,_,3) >> check >> typeOf >> (pyint^pyint)

    fxs = tvseq((N ** pyint)[tvseq], [1, 2, 3]) >> each >> myunary(1,_,3)
    fxs >> check >> typeOf >> (N ** pyint)[tvseq]
Exemplo n.º 2
0
def test_drop():
    tvseq((N**pystr)[tvseq], ['a','b','c']) >> drop >> (2 | count) >> check >> typeOf >> (N**pystr)[tvseq]
Exemplo n.º 3
0
def test_at():
    [1,2,3] >> at(_, 0) >> check >> equal >> 1
    [1,2,3] >> at(_, 0 | offset) >> check >> equal >> 1
    [1,2,3] >> at(_, 1 | index) >> check >> equal >> 1
    tvseq((N**index)[tvseq], [1 | index, 2 | index, 3 | index]) >> at(_, 1 | index) >> check >> typeOf >> index
Exemplo n.º 4
0
def ppFnOfCard(fn, sep='') -> display_table:
    return tvseq(
        display_table, people >> each >> fn >> append >> sep >> join >>
        (weapons >> each >> fn >> append >> sep) >> join >>
        (rooms >> each >> fn))
Exemplo n.º 5
0
def test_anon():
    f = anon(pyint^pyint, lambda x: x + 1)
    fxs = tvseq((N ** pyint)[tvseq], [1, 2, 3]) >> each >> f
    fxs >> check >> typeOf >> (N ** pyint)[tvseq]
    with assertRaises(TypeError):
        fxs = tvseq((N ** pyint)[tvseq], [1, 2, 3]) >> each >> anon(pystr ^ pystr, lambda x: x + 1)
Exemplo n.º 6
0
def join(a:display_table, b:display_table, options={}) -> display_table:
    return tvseq(display_table, a.data + b.data) >> ljust
Exemplo n.º 7
0
def hjoin(a:display_table, b:display_table, options={}) -> display_table:
    assert (a >> count) == (b >> count)
    answer = tvseq(display_table, [])
    for i in range(len(a)):
        answer.append(a[i] + options.get('sep', '') + b[i])
    return answer