Пример #1
0
def test():
    """
    Exercise the interface of sets
    """
    # 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 set with these nodes
    s1 = node.set(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() == set(range(10))

    # make some numbers
    ints = set(range(10))
    # make a set out of them
    s2 = node.set(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() == set(range(10))

    # all done
    return
Пример #2
0
def test():
    """
    Exercise the interface of sets
    """
    # get the base node from the {calc} package
    from p2.calc.Node import Node as node

    # make a set
    s = node.set(value=[])
    # access the value
    assert s.getValue() == set()

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

    # all done
    return