Skip to content

Commit

Permalink
added another test for removing states (from models with actions)
Browse files Browse the repository at this point in the history
  • Loading branch information
PimLeerkes committed Nov 7, 2024
1 parent 4f141f1 commit 21692a9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion stormvogel/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ def normalize(self):
action
].branch = new_transitions
else:
# TODO: As of now, for the CTMCs and MAs we only add self loops
# for ctmcs and mas we currently only add self loops
self.add_self_loops()

def __free_state_id(self):
Expand Down
2 changes: 2 additions & 0 deletions tests/test_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ def test_stormpy_to_stormvogel_and_back_pomdp():
assert sparse_equal(stormpy_pomdp, new_stormpy_pomdp)


"""
def test_stormvogel_to_stormpy_and_back_ma():
# we create a stormpy representation of an example ma
stormvogel_ma = examples.simple_ma.create_simple_ma()
Expand All @@ -233,3 +234,4 @@ def test_stormpy_to_stormvogel_and_back_ma():
# print(new_stormpy_ma)
assert sparse_equal(stormpy_ma, new_stormpy_ma)
"""
32 changes: 32 additions & 0 deletions tests/test_model_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,38 @@ def test_remove_state():

assert ctmc == new_ctmc

# we also test if it works for a model that has nontrivial actions:
mdp = stormvogel.model.new_mdp()
state1 = mdp.new_state()
state2 = mdp.new_state()
action0 = mdp.new_action("0")
action1 = mdp.new_action("1")
branch0 = stormvogel.model.Branch(
cast(
list[tuple[stormvogel.model.Number, stormvogel.model.State]],
[(1 / 2, state1), (1 / 2, state2)],
)
)
branch1 = stormvogel.model.Branch(
cast(
list[tuple[stormvogel.model.Number, stormvogel.model.State]],
[(1 / 4, state1), (3 / 4, state2)],
)
)
transition = stormvogel.model.Transition({action0: branch0, action1: branch1})
mdp.set_transitions(mdp.get_initial_state(), transition)

# we remove a state
mdp.remove_state(mdp.get_state_by_id(0), True)

# we make the mdp with the state already missing
new_mdp = stormvogel.model.new_mdp(create_initial_state=False)
new_mdp.new_state()
new_mdp.new_state()
new_mdp.add_self_loops()

assert mdp == new_mdp


def test_remove_transitions_between_states():
# we make a model and remove transitions between two states
Expand Down

0 comments on commit 21692a9

Please sign in to comment.