예제 #1
0
def test():
    """
    Exercise the interface of tuples
    """
    # get the base node from the {calc} package
    from p2.calc.Node import Node as node

    # make some nodes
    nodes = (node.variable(value=n) for n in range(10))

    # make a tuple with these nodes
    s1 = node.tuple(value=nodes)
    # check that
    for op, node in zip(s1.operands, nodes):
        # the operands are the exact nodes we supplied
        assert op is node
    # verify that the value is what we expect
    assert s1.getValue() == tuple(range(10))

    # make some numbers
    ints = tuple(range(10))
    # make a tuple out of them
    s2 = node.tuple(value=ints)
    # check that all the {s2} operands
    for op in s2.operands:
        # are literals
        assert isinstance(op, node.literal)
    # verify that the value is what we expect
    assert s2.getValue() == tuple(range(10))

    # all done
    return
예제 #2
0
def test():
    """
    Exercise the interface of tuples
    """
    # get the base node from the {calc} package
    from p2.calc.Node import Node as node

    # make a tuple
    t = node.tuple(value=[])
    # access the value
    assert t.getValue() == ()

    # make some nodes
    nodes = tuple(node.variable(value=n) for n in range(10))
    # and some numbers
    numbers = (1, 2, 3)
    # set the value
    t.setValue(value=nodes + numbers)
    # verify it happened correctly
    assert t.getValue() == (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3)

    # all done
    return