summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2018-04-25 14:42:48 +0200
committerDaniel Friesel <derf@finalrewind.org>2018-04-25 14:42:48 +0200
commit4c220e1b4e029d2130789c16b814143e4dcc00b8 (patch)
treec507893b4dc0e9a6408150d4c06b162405809b84 /bin
parentb363330cd89d4a82124e0c465fd0c3f678fa1bd5 (diff)
PTA: Support unconditional param setters (e.g. initialization functions)
Diffstat (limited to 'bin')
-rwxr-xr-xbin/test_automata.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/bin/test_automata.py b/bin/test_automata.py
index fd3f462..e537076 100755
--- a/bin/test_automata.py
+++ b/bin/test_automata.py
@@ -31,6 +31,9 @@ example_json_1 = {
'duration' : {
'static' : 50000,
},
+ 'set_param' : {
+ 'txpower' : 10
+ },
},
{
'name' : 'setTxPower',
@@ -120,6 +123,7 @@ class TestPTA(unittest.TestCase):
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)
def test_simulation(self):
pta = PTA()
@@ -212,6 +216,25 @@ class TestPTA(unittest.TestCase):
'length' : None
})
+ def test_simulation_set_param(self):
+ pta = PTA(parameters = ['txpower', 'length'])
+ pta.add_state('IDLE', power = 5)
+ pta.add_state('TX', power = 100)
+ pta.add_transition('UNINITIALIZED', 'IDLE', 'init', energy = 500000, duration = 50000, set_param = {'txpower' : 10})
+ trace = [
+ ['init'],
+ ]
+ expected_energy = 500000
+ expected_duration = 50000
+ power, duration, state, parameters = pta.simulate(trace)
+ self.assertEqual(power, expected_energy)
+ self.assertEqual(duration, expected_duration)
+ self.assertEqual(state.name, 'IDLE')
+ self.assertEqual(parameters, {
+ 'txpower' : 10,
+ 'length' : None
+ })
+
def test_simulation_arg_function(self):
pta = PTA(parameters = ['txpower', 'length'])
pta.add_state('IDLE', power = 5)