I have a problem with a set of states. To move from a state to another I need to do a set of actions. I'm trying to implement State and Actions classes in a way that the following comparisons returns true:
state1 + actions == state2
state2 - actions == state1
state2 - state1 == actions
I wrote a test case for my implementation that is the following:
class State:
pass
class Actions:
pass
starting_state ={'a':'1',
'b':'2'}
some_actions = {'a': 'remove 1',
'b' : 'remove 2,add #',
'c' : 'add 5'}
inverse_actions = {'a': 'add 1',
'b' : 'remove #,add 2',
'c' : 'remove 5'}
final_state = {'b':'#',
'c':'5'}
state1 = State(starting_state)
actions = Actions(some_actions)
state2= state1 + actions
assert State(final_state)==state2
assert Actions(inverse_actions)== -actions
assert state2 - actions == state1
assert state2 - state1 == actions
My questions are:
- There is nothing pre-built that can help me to implement the State and Actions classes?
- If not, how can I implement the + and - operations between different classes? There is a way to avoid circular dependencies?
Thank you for the help!