Esempio n. 1
0
# Business as usual
machine = TestMachine()

# Because we might as well
basic_operations(machine, "trees")

# We can always generate leaf nodes. We ignore the Random argument we're given
# because all Leaves are created equal.
machine.generate(lambda _: Leaf(), "trees")


# Given two trees, we can join them together into a new tree
machine.operation(
    argspec=("trees", "trees"),
    target="trees",
    function = lambda x, y: x.join(y),
    pattern="%s.join(%s)"
)

# Assert that our trees are balanced.
machine.check(
    test=lambda x: x.balanced(),
    argspec=("trees",),
    # The pattern argument controls the output formatting when emitting an
    # example. It will be formatted with the name of the variable we are
    # checking.
    pattern="assert %s.balanced()"
)

if __name__ == '__main__':
    machine.run()