Exemple #1
0
def test_run_deep_calls():
    object = A()

    @timewinder.step
    def a(state, m):
        print("in a")
        m.foo = "b"

    @timewinder.step
    def b(state, m):
        m.foo = "c"

    @timewinder.step
    def c(state, m):
        m.foo = "end1"

    @timewinder.step
    def d(state, m):
        m.foo = "end2"

    alg = timewinder.FuncProcess(
        a(object),
        b(object),
        c(object),
        d(object),
    )

    ev = timewinder.Evaluator(
        objects=[object],
        threads=[alg],
    )

    ev.evaluate()
    assert ev.stats.states == 5
    ev._print_state_space()
Exemple #2
0
def test_overdraft_1():
    @timewinder.object
    class Account:
        def __init__(self, name):
            self.name = name
            self.acc = 5

    alice = Account("alice")
    bob = Account("bob")

    @timewinder.step
    def withdraw(state, sender, amount):
        sender.acc = sender.acc - amount

    @timewinder.step
    def deposit(state, reciever, amount):
        reciever.acc = reciever.acc + amount

    alg = timewinder.FuncProcess(
        withdraw(alice, 3),
        deposit(bob, 3),
    )

    no_overdrafts = timewinder.ForAll(Account, lambda a: a.acc >= 0)

    ev = timewinder.Evaluator(
        objects=[alice, bob],
        threads=[alg],
        specs=[no_overdrafts],
    )
    ev.evaluate()
    ev._print_state_space()
    assert ev.stats.states == 3
Exemple #3
0
 def alg():
     return timewinder.FuncProcess(
         check_funds(alice),
         withdraw(alice),
         deposit(bob),
         state={"amt": Set(range(1, 6))},
     )
Exemple #4
0
def test_overdraft_initial_conditions():
    @timewinder.object
    class Account:
        def __init__(self, name):
            self.name = name
            self.acc = 5

    alice = Account("alice")
    bob = Account("bob")

    @timewinder.step
    def withdraw(state, sender):
        sender.acc = sender.acc - state["amt"]

    @timewinder.step
    def deposit(state, reciever):
        reciever.acc = reciever.acc + state["amt"]

    alg = timewinder.FuncProcess(
        withdraw(alice),
        deposit(bob),
        state={
            "amt": Set(range(1, 7)),
        },
    )

    no_overdrafts = timewinder.ForAll(Account, lambda a: a.acc >= 0)

    ev = timewinder.Evaluator(
        objects=[alice, bob],
        threads=[alg],
        specs=[no_overdrafts],
    )

    got_error = False
    try:
        ev.evaluate()
    except ConstraintError as e:
        got_error = True
        print(e.name)
        print(e.thunk)

    assert got_error
    assert ev.stats.states == 12