summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/test_automata.py15
-rwxr-xr-xlib/automata.py31
2 files changed, 22 insertions, 24 deletions
diff --git a/bin/test_automata.py b/bin/test_automata.py
index e537076..3b64783 100755
--- a/bin/test_automata.py
+++ b/bin/test_automata.py
@@ -26,7 +26,7 @@ example_json_1 = {
'transitions' : [
{
'name' : 'init',
- 'origin' : 'UNINITIALIZED',
+ 'origin' : ['UNINITIALIZED', 'IDLE'],
'destination' : 'IDLE',
'duration' : {
'static' : 50000,
@@ -110,20 +110,21 @@ class TestPTA(unittest.TestCase):
self.assertEqual(pta.states['UNINITIALIZED'].name, 'UNINITIALIZED')
self.assertEqual(pta.states['IDLE'].name, 'IDLE')
self.assertEqual(pta.states['TX'].name, 'TX')
- self.assertEqual(len(pta.transitions), 4)
+ self.assertEqual(len(pta.transitions), 5)
self.assertEqual(pta.transitions[0].name, 'init')
- self.assertEqual(pta.transitions[1].name, 'setTxPower')
- self.assertEqual(pta.transitions[2].name, 'send')
- self.assertEqual(pta.transitions[3].name, 'txComplete')
+ self.assertEqual(pta.transitions[1].name, 'init')
+ self.assertEqual(pta.transitions[2].name, 'setTxPower')
+ self.assertEqual(pta.transitions[3].name, 'send')
+ self.assertEqual(pta.transitions[4].name, 'txComplete')
def test_from_json_dfs(self):
pta = PTA.from_json(example_json_1)
- self.assertEqual(sorted(pta.dfs(1)), [['init', 'send'], ['init', 'setTxPower']])
+ self.assertEqual(sorted(pta.dfs(1)), [['init', 'init'], ['init', 'send'], ['init', 'setTxPower']])
def test_from_json_function(self):
pta = PTA.from_json(example_json_1)
self.assertEqual(pta.states['TX'].get_energy(1000, {'datarate' : 10, 'txbytes' : 6, 'txpower' : 10 }), 1000 * (100 + 2 * 10))
- self.assertEqual(pta.transitions[3].get_timeout({'datarate' : 10, 'txbytes' : 6, 'txpower' : 10 }), 500 + 16 * 6)
+ self.assertEqual(pta.transitions[4].get_timeout({'datarate' : 10, 'txbytes' : 6, 'txpower' : 10 }), 500 + 16 * 6)
def test_simulation(self):
pta = PTA()
diff --git a/lib/automata.py b/lib/automata.py
index e59c1ed..5779fe1 100755
--- a/lib/automata.py
+++ b/lib/automata.py
@@ -67,13 +67,6 @@ class State:
self.power_function = power_function
self.outgoing_transitions = {}
- """@classmethod
- def from_json(cls, serialized_state):
- if 'power' in serialized_state:
- cls.power = serialized_state['power']['static']
- if 'function' in serialized_state:
- cls.power_function = """
-
def add_outgoing_transition(self, new_transition):
self.outgoing_transitions[new_transition.name] = new_transition
@@ -148,16 +141,20 @@ class PTA:
arg_to_param_map = None
if 'arg_to_param_map' in transition:
arg_to_param_map = transition['arg_to_param_map']
- pta.add_transition(transition['origin'], transition['destination'],
- transition['name'],
- duration = _json_get_static(transition, 'duration'),
- duration_function = duration_function,
- energy = _json_get_static(transition, 'energy'),
- energy_function = energy_function,
- timeout = _json_get_static(transition, 'timeout'),
- timeout_function = timeout_function,
- arg_to_param_map = arg_to_param_map
- )
+ origins = transition['origin']
+ if type(origins) != list:
+ origins = [origins]
+ for origin in origins:
+ pta.add_transition(origin, transition['destination'],
+ transition['name'],
+ duration = _json_get_static(transition, 'duration'),
+ duration_function = duration_function,
+ energy = _json_get_static(transition, 'energy'),
+ energy_function = energy_function,
+ timeout = _json_get_static(transition, 'timeout'),
+ timeout_function = timeout_function,
+ arg_to_param_map = arg_to_param_map
+ )
return pta