Skip to content

Commit

Permalink
Python support: some work on edge testing DataStoreVariable (#2178).
Browse files Browse the repository at this point in the history
  • Loading branch information
agarny committed Dec 10, 2019
1 parent 3881439 commit 390a60b
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/plugins/datastoreinterface.cpp
Expand Up @@ -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();
}

//==============================================================================
Expand Down Expand Up @@ -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();
}

//==============================================================================
Expand Down
30 changes: 30 additions & 0 deletions src/plugins/support/PythonSupport/tests/data/edgetests.out
Expand Up @@ -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
51 changes: 51 additions & 0 deletions src/plugins/support/PythonSupport/tests/data/edgetests.py
Expand Up @@ -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

Expand Down Expand Up @@ -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)

0 comments on commit 390a60b

Please sign in to comment.