From 390a60bb725de2f497827190c89ccbfe93d74f30 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Wed, 11 Dec 2019 11:06:56 +1300 Subject: [PATCH] Python support: some work on edge testing DataStoreVariable (#2178). --- src/plugins/datastoreinterface.cpp | 20 +++++--- .../PythonSupport/tests/data/edgetests.out | 30 +++++++++++ .../PythonSupport/tests/data/edgetests.py | 51 +++++++++++++++++++ 3 files changed, 93 insertions(+), 8 deletions(-) diff --git a/src/plugins/datastoreinterface.cpp b/src/plugins/datastoreinterface.cpp index 80f1820403..2bd1a53e63 100644 --- a/src/plugins/datastoreinterface.cpp +++ b/src/plugins/datastoreinterface.cpp @@ -266,9 +266,11 @@ double DataStoreVariableRun::value(quint64 pPosition) const { // Return the value at the given position - Q_ASSERT(pPosition < mSize); + if (pPosition < mSize) { + return mArray->data()[pPosition]; + } - return mArray->data()[pPosition]; + return qQNaN(); } //============================================================================== @@ -505,15 +507,17 @@ double DataStoreVariable::value(quint64 pPosition, int pRun) const { // Return the value at the given position and this for the given run - Q_ASSERT(!mRuns.isEmpty()); + if (!mRuns.isEmpty()) { + if (pRun == -1) { + return mRuns.last()->value(pPosition); + } - if (pRun == -1) { - return mRuns.last()->value(pPosition); + if ((pRun >= 0) && (pRun < mRuns.count())) { + return mRuns[pRun]->value(pPosition); + } } - Q_ASSERT((pRun >= 0) && (pRun < mRuns.count())); - - return mRuns[pRun]->value(pPosition); + return qQNaN(); } //============================================================================== diff --git a/src/plugins/support/PythonSupport/tests/data/edgetests.out b/src/plugins/support/PythonSupport/tests/data/edgetests.out index 3f3a592a20..38c93bf30b 100755 --- a/src/plugins/support/PythonSupport/tests/data/edgetests.out +++ b/src/plugins/support/PythonSupport/tests/data/edgetests.out @@ -62,3 +62,33 @@ - Rates : n/a - Algebraic : n/a - RuntimeError('std::runtime_error: The simulation has an invalid runtime and cannot therefore be run.') + +--------------------------------------- + Various edge cases +--------------------------------------- + - Run simulation: + - Test the SimulationResults class: + - Test SimulationResults.voi(): + - Name: t + - Unit: dimensionless + - URI: main/t + - value(-1): nan + - value(-1, -2): nan + - value(-1, -1): nan + - value(-1, 0): nan + - value(-1, 1): nan + - value(0): 0.000000 + - value(0, -2): nan + - value(0, -1): 0.000000 + - value(0, 0): 0.000000 + - value(0, 1): nan + - value(50000): 50.000000 + - value(50000, -2): nan + - value(50000, -1): 50.000000 + - value(50000, 0): 50.000000 + - value(50000, 1): nan + - value(50001): nan + - value(50001, -2): nan + - value(50001, -1): nan + - value(50001, 0): nan + - value(50001, 1): nan diff --git a/src/plugins/support/PythonSupport/tests/data/edgetests.py b/src/plugins/support/PythonSupport/tests/data/edgetests.py index 00d133d0ac..c2340e8b3b 100755 --- a/src/plugins/support/PythonSupport/tests/data/edgetests.py +++ b/src/plugins/support/PythonSupport/tests/data/edgetests.py @@ -5,6 +5,43 @@ from basictests import * + +def edge_test_data_store_variable(variable): + print(' - Name: %s' % variable.name()) + print(' - Unit: %s' % variable.unit()) + print(' - URI: %s' % variable.uri()) + print(' - value(-1): %f' % variable.value(-1)) + print(' - value(-1, -2): %f' % variable.value(-1, -2)) + print(' - value(-1, -1): %f' % variable.value(-1, -1)) + print(' - value(-1, 0): %f' % variable.value(-1, 0)) + print(' - value(-1, 1): %f' % variable.value(-1, 1)) + print(' - value(0): %f' % variable.value(0)) + print(' - value(0, -2): %f' % variable.value(0, -2)) + print(' - value(0, -1): %f' % variable.value(0, -1)) + print(' - value(0, 0): %f' % variable.value(0, 0)) + print(' - value(0, 1): %f' % variable.value(0, 1)) + print(' - value(50000): %f' % variable.value(50000)) + print(' - value(50000, -2): %f' % variable.value(50000, -2)) + print(' - value(50000, -1): %f' % variable.value(50000, -1)) + print(' - value(50000, 0): %f' % variable.value(50000, 0)) + print(' - value(50000, 1): %f' % variable.value(50000, 1)) + print(' - value(50001): %f' % variable.value(50001)) + print(' - value(50001, -2): %f' % variable.value(50001, -2)) + print(' - value(50001, -1): %f' % variable.value(50001, -1)) + print(' - value(50001, 0): %f' % variable.value(50001, 0)) + print(' - value(50001, 1): %f' % variable.value(50001, 1)) + + +def edge_test_simulation_results(simulation): + print(' - Test the SimulationResults class:') + + results = simulation.results() + + print(' - Test SimulationResults.voi():') + + edge_test_data_store_variable(results.voi()) + + if __name__ == '__main__': # Test for no file name or URL provided @@ -39,3 +76,17 @@ False) except Exception as e: print(' - %s' % repr(e)) + + # Test various edge cases using a valid SED-ML file + + header('Various edge cases', False) + + simulation = open_simulation('sedml/lorenz.sedml') + + print(' - Run simulation:') + + simulation.run() + + edge_test_simulation_results(simulation) + + oc.close_simulation(simulation)