COPASI API  4.16.103
Public Member Functions | Static Protected Attributes | Private Member Functions | List of all members
test000076 Class Reference

#include <test000076.h>

Inheritance diagram for test000076:
Inheritance graph
[legend]
Collaboration diagram for test000076:
Collaboration graph
[legend]

Public Member Functions

void setUp ()
 
void tearDown ()
 
void test_bug1035_1 ()
 
void test_bug1035_2 ()
 
void test_bug1035_3 ()
 

Static Protected Attributes

static const char * MODEL_STRING1
 
static const char * MODEL_STRING2
 
static const char * MODEL_STRING3
 
static CCopasiDataModelpCOPASIDATAMODEL = NULL
 

Private Member Functions

 CPPUNIT_TEST (test_bug1035_1)
 
 CPPUNIT_TEST (test_bug1035_2)
 
 CPPUNIT_TEST (test_bug1035_3)
 
 CPPUNIT_TEST_SUITE (test000076)
 
 CPPUNIT_TEST_SUITE_END ()
 

Detailed Description

Definition at line 27 of file test000076.h.

Member Function Documentation

test000076::CPPUNIT_TEST ( test_bug1035_1  )
private
test000076::CPPUNIT_TEST ( test_bug1035_2  )
private
test000076::CPPUNIT_TEST ( test_bug1035_3  )
private
test000076::CPPUNIT_TEST_SUITE ( test000076  )
private
test000076::CPPUNIT_TEST_SUITE_END ( )
private
void test000076::setUp ( )

Test the export of models with references to local parameters in expressions.

Definition at line 47 of file test000076.cpp.

References CCopasiRootContainer::addDatamodel(), CCopasiRootContainer::init(), and pCOPASIDATAMODEL.

48 {
49  // Create the root container.
50  CCopasiRootContainer::init(0, NULL, false);
51  // Create the global data model.
53 }
static CCopasiDataModel * addDatamodel()
static CCopasiDataModel * pCOPASIDATAMODEL
Definition: test000076.h:36
static void init(int argc, char *argv[], const bool &withGui=false)
void test000076::tearDown ( )

Definition at line 55 of file test000076.cpp.

References CCopasiRootContainer::destroy().

void test000076::test_bug1035_1 ( )

Definition at line 60 of file test000076.cpp.

References CCopasiDataModel::exportSBMLToString(), CCopasiDataModel::getCurrentSBMLDocument(), CCopasiDataModel::getModel(), load_cps_model_from_stream(), MODEL_STRING1, and pCOPASIDATAMODEL.

61 {
62  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
63  std::istringstream iss(test000076::MODEL_STRING1);
64  CPPUNIT_ASSERT(load_cps_model_from_stream(iss, *pDataModel) == true);
65  CPPUNIT_ASSERT(pDataModel->getModel() != NULL);
66  const SBMLDocument* pDocument = pDataModel->getCurrentSBMLDocument();
67  CPPUNIT_ASSERT(pDocument == NULL);
68  std::string sbmlString;
69 
70  try
71  {
72  sbmlString = pDataModel->exportSBMLToString(NULL, 2, 1);
73  }
74  catch (...)
75  {
76  // fail if an uncaught exception occurs during export
77  CPPUNIT_ASSERT(false);
78  }
79 
80  CPPUNIT_ASSERT(!sbmlString.empty());
81  // check if the exported SBML model has two parameters
82  pDocument = pDataModel->getCurrentSBMLDocument();
83  CPPUNIT_ASSERT(pDocument != NULL);
84  const Model* pModel = pDocument->getModel();
85  CPPUNIT_ASSERT(pModel != NULL);
86  CPPUNIT_ASSERT(pModel->getListOfParameters()->size() == 2);
87  const Parameter *pP1 = NULL, *pP2 = NULL;
88  pP1 = pModel->getParameter(0);
89  CPPUNIT_ASSERT(pP1 != NULL);
90 
91  if (pP1->getName() != std::string("K"))
92  {
93  pP2 = pP1;
94  pP1 = pModel->getParameter(1);
95  }
96  else
97  {
98  pP2 = pModel->getParameter(1);
99  }
100 
101  CPPUNIT_ASSERT(pP2->getName() == std::string("reaction_k1"));
102  CPPUNIT_ASSERT(pP2->getConstant() == true);
103  CPPUNIT_ASSERT(fabs((pP2->getValue() - 0.1) / 0.1) < 1e-6);
104  CPPUNIT_ASSERT(pP1->getName() == std::string("K"));
105  CPPUNIT_ASSERT(pP1->getConstant() == false);
106  CPPUNIT_ASSERT(fabs((pP1->getValue() - 0.1) / 0.1) < 1e-6);
107  // check there is exactly one rule
108  CPPUNIT_ASSERT(pModel->getListOfRules()->size() == 1);
109  const Rule* pRule = pModel->getRule(0);
110  CPPUNIT_ASSERT(pRule != NULL);
111  const AssignmentRule* pAssignmentRule = dynamic_cast<const AssignmentRule*>(pRule);
112  CPPUNIT_ASSERT(pAssignmentRule != NULL);
113  CPPUNIT_ASSERT(pAssignmentRule->getVariable() == pP1->getId());
114  const ASTNode* pMath = pAssignmentRule->getMath();
115  CPPUNIT_ASSERT(pMath != NULL);
116  CPPUNIT_ASSERT(pMath->getType() == AST_NAME);
117  CPPUNIT_ASSERT(pMath->getName() == std::string(pP2->getId()));
118  // now check the reaction
119  CPPUNIT_ASSERT(pModel->getListOfReactions()->size() == 1);
120  const Reaction* pReaction = pModel->getReaction(0);
121  CPPUNIT_ASSERT(pReaction != NULL);
122  CPPUNIT_ASSERT(pReaction->getListOfReactants()->size() == 1);
123  CPPUNIT_ASSERT(pReaction->getListOfProducts()->size() == 1);
124  CPPUNIT_ASSERT(pReaction->getListOfModifiers()->size() == 0);
125  const KineticLaw* pKLaw = pReaction->getKineticLaw();
126  CPPUNIT_ASSERT(pKLaw != NULL);
127  CPPUNIT_ASSERT(pKLaw->getListOfParameters()->size() == 0);
128  const SpeciesReference* pSpeciesReference = pReaction->getReactant(0);
129  CPPUNIT_ASSERT(pSpeciesReference != NULL);
130  CPPUNIT_ASSERT(pModel->getListOfCompartments()->size() == 1);
131  const Compartment* pCompartment = pModel->getCompartment(0);
132  CPPUNIT_ASSERT(pCompartment != NULL);
133  pMath = pKLaw->getMath();
134  CPPUNIT_ASSERT(pMath != NULL);
135  // check that the expression is the compartment times the substrate times the
136  // parameter
137  CPPUNIT_ASSERT(pMath->getType() == AST_TIMES);
138  std::vector<std::string> ids;
139  CPPUNIT_ASSERT(pMath->getNumChildren() == 2 || pMath->getNumChildren() == 3);
140 
141  if (pMath->getNumChildren() == 3)
142  {
143  CPPUNIT_ASSERT(pMath->getChild(0)->getType() == AST_NAME);
144  CPPUNIT_ASSERT(pMath->getChild(1)->getType() == AST_NAME);
145  CPPUNIT_ASSERT(pMath->getChild(2)->getType() == AST_NAME);
146  ids.push_back(pMath->getChild(0)->getName());
147  ids.push_back(pMath->getChild(1)->getName());
148  ids.push_back(pMath->getChild(2)->getName());
149  }
150  else
151  {
152  if (pMath->getChild(0)->getType() == AST_NAME)
153  {
154  ids.push_back(pMath->getChild(0)->getName());
155  pMath = pMath->getChild(1);
156  }
157  else
158  {
159  CPPUNIT_ASSERT(pMath->getChild(1)->getType() == AST_NAME);
160  ids.push_back(pMath->getChild(1)->getName());
161  pMath = pMath->getChild(0);
162  }
163 
164  CPPUNIT_ASSERT(pMath->getType() == AST_TIMES);
165  CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
166  CPPUNIT_ASSERT(pMath->getChild(0)->getType() == AST_NAME);
167  CPPUNIT_ASSERT(pMath->getChild(1)->getType() == AST_NAME);
168  ids.push_back(pMath->getChild(0)->getName());
169  ids.push_back(pMath->getChild(1)->getName());
170  }
171 
172  CPPUNIT_ASSERT(ids.size() == 3);
173  CPPUNIT_ASSERT(std::find(ids.begin(), ids.end(), std::string(pCompartment->getId())) != ids.end());
174  CPPUNIT_ASSERT(std::find(ids.begin(), ids.end(), std::string(pP2->getId())) != ids.end());
175  CPPUNIT_ASSERT(std::find(ids.begin(), ids.end(), std::string(pSpeciesReference->getSpecies())) != ids.end());
176 }
SBMLDocument * getCurrentSBMLDocument()
std::string exportSBMLToString(CProcessReport *pExportHandler, int sbmlLevel, int sbmlVersion)
bool load_cps_model_from_stream(std::istream &is, CCopasiDataModel &dataModel)
Definition: utilities.cpp:21
static const char * MODEL_STRING1
Definition: test000076.h:37
static CCopasiDataModel * pCOPASIDATAMODEL
Definition: test000076.h:36
void test000076::test_bug1035_2 ( )

Definition at line 180 of file test000076.cpp.

References CCopasiDataModel::exportSBMLToString(), CCopasiDataModel::getCurrentSBMLDocument(), CCopasiDataModel::getModel(), load_cps_model_from_stream(), MODEL_STRING2, and pCOPASIDATAMODEL.

181 {
182  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
183  std::istringstream iss(test000076::MODEL_STRING2);
184  CPPUNIT_ASSERT(load_cps_model_from_stream(iss, *pDataModel) == true);
185  CPPUNIT_ASSERT(pDataModel->getModel() != NULL);
186  const SBMLDocument* pDocument = pDataModel->getCurrentSBMLDocument();
187  CPPUNIT_ASSERT(pDocument == NULL);
188  std::string sbmlString;
189 
190  try
191  {
192  // we need to export to Level 2 Version 3 because of the initial assignment
193  sbmlString = pDataModel->exportSBMLToString(NULL, 2, 3);
194  }
195  catch (...)
196  {
197  // fail if any exception occurs during the export
198  CPPUNIT_ASSERT(false);
199  }
200 
201  CPPUNIT_ASSERT(!sbmlString.empty());
202  // check if the exported SBML model has two parameters
203  pDocument = pDataModel->getCurrentSBMLDocument();
204  CPPUNIT_ASSERT(pDocument != NULL);
205  const Model* pModel = pDocument->getModel();
206  CPPUNIT_ASSERT(pModel != NULL);
207  CPPUNIT_ASSERT(pModel->getListOfParameters()->size() == 2);
208  const Parameter *pP1 = NULL, *pP2 = NULL;
209  pP1 = pModel->getParameter(0);
210  CPPUNIT_ASSERT(pP1 != NULL);
211 
212  if (pP1->getName() != std::string("K"))
213  {
214  pP2 = pP1;
215  pP1 = pModel->getParameter(1);
216  }
217  else
218  {
219  pP2 = pModel->getParameter(1);
220  }
221 
222  CPPUNIT_ASSERT(pP2->getName() == std::string("reaction_k1"));
223  CPPUNIT_ASSERT(pP2->getConstant() == true);
224  CPPUNIT_ASSERT(fabs((pP2->getValue() - 0.1) / 0.1) < 1e-6);
225  CPPUNIT_ASSERT(pP1->getName() == std::string("K"));
226  CPPUNIT_ASSERT(pP1->getConstant() == true);
227  CPPUNIT_ASSERT(fabs((pP1->getValue() - 0.1) / 0.1) < 1e-6);
228  // check there is exactly one initial assignment
229  CPPUNIT_ASSERT(pModel->getListOfInitialAssignments()->size() == 1);
230  const InitialAssignment* pAssignment = pModel->getInitialAssignment(0);
231  CPPUNIT_ASSERT(pAssignment != NULL);
232  CPPUNIT_ASSERT(pAssignment->getSymbol() == pP1->getId());
233  const ASTNode* pMath = pAssignment->getMath();
234  CPPUNIT_ASSERT(pMath != NULL);
235  CPPUNIT_ASSERT(pMath->getType() == AST_NAME);
236  CPPUNIT_ASSERT(pMath->getName() == std::string(pP2->getId()));
237  // now check the reaction
238  CPPUNIT_ASSERT(pModel->getListOfReactions()->size() == 1);
239  const Reaction* pReaction = pModel->getReaction(0);
240  CPPUNIT_ASSERT(pReaction != NULL);
241  CPPUNIT_ASSERT(pReaction->getListOfReactants()->size() == 1);
242  CPPUNIT_ASSERT(pReaction->getListOfProducts()->size() == 1);
243  CPPUNIT_ASSERT(pReaction->getListOfModifiers()->size() == 0);
244  const KineticLaw* pKLaw = pReaction->getKineticLaw();
245  CPPUNIT_ASSERT(pKLaw != NULL);
246  CPPUNIT_ASSERT(pKLaw->getListOfParameters()->size() == 0);
247  const SpeciesReference* pSpeciesReference = pReaction->getReactant(0);
248  CPPUNIT_ASSERT(pSpeciesReference != NULL);
249  CPPUNIT_ASSERT(pModel->getListOfCompartments()->size() == 1);
250  const Compartment* pCompartment = pModel->getCompartment(0);
251  CPPUNIT_ASSERT(pCompartment != NULL);
252  pMath = pKLaw->getMath();
253  CPPUNIT_ASSERT(pMath != NULL);
254  // check that the expression is the compartment times the substrate times the
255  // parameter
256  CPPUNIT_ASSERT(pMath->getType() == AST_TIMES);
257  std::vector<std::string> ids;
258  CPPUNIT_ASSERT(pMath->getNumChildren() == 2 || pMath->getNumChildren() == 3);
259 
260  if (pMath->getNumChildren() == 3)
261  {
262  CPPUNIT_ASSERT(pMath->getChild(0)->getType() == AST_NAME);
263  CPPUNIT_ASSERT(pMath->getChild(1)->getType() == AST_NAME);
264  CPPUNIT_ASSERT(pMath->getChild(2)->getType() == AST_NAME);
265  ids.push_back(pMath->getChild(0)->getName());
266  ids.push_back(pMath->getChild(1)->getName());
267  ids.push_back(pMath->getChild(2)->getName());
268  }
269  else
270  {
271  if (pMath->getChild(0)->getType() == AST_NAME)
272  {
273  ids.push_back(pMath->getChild(0)->getName());
274  pMath = pMath->getChild(1);
275  }
276  else
277  {
278  CPPUNIT_ASSERT(pMath->getChild(1)->getType() == AST_NAME);
279  ids.push_back(pMath->getChild(1)->getName());
280  pMath = pMath->getChild(0);
281  }
282 
283  CPPUNIT_ASSERT(pMath->getType() == AST_TIMES);
284  CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
285  CPPUNIT_ASSERT(pMath->getChild(0)->getType() == AST_NAME);
286  CPPUNIT_ASSERT(pMath->getChild(1)->getType() == AST_NAME);
287  ids.push_back(pMath->getChild(0)->getName());
288  ids.push_back(pMath->getChild(1)->getName());
289  }
290 
291  CPPUNIT_ASSERT(ids.size() == 3);
292  CPPUNIT_ASSERT(std::find(ids.begin(), ids.end(), std::string(pCompartment->getId())) != ids.end());
293  CPPUNIT_ASSERT(std::find(ids.begin(), ids.end(), std::string(pP2->getId())) != ids.end());
294  CPPUNIT_ASSERT(std::find(ids.begin(), ids.end(), std::string(pSpeciesReference->getSpecies())) != ids.end());
295 }
SBMLDocument * getCurrentSBMLDocument()
std::string exportSBMLToString(CProcessReport *pExportHandler, int sbmlLevel, int sbmlVersion)
bool load_cps_model_from_stream(std::istream &is, CCopasiDataModel &dataModel)
Definition: utilities.cpp:21
static CCopasiDataModel * pCOPASIDATAMODEL
Definition: test000076.h:36
static const char * MODEL_STRING2
Definition: test000076.h:38
void test000076::test_bug1035_3 ( )

Definition at line 301 of file test000076.cpp.

References CCopasiDataModel::exportSBMLToString(), CCopasiDataModel::getCurrentSBMLDocument(), CCopasiDataModel::getModel(), load_cps_model_from_stream(), MODEL_STRING3, and pCOPASIDATAMODEL.

302 {
303  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
304  std::istringstream iss(test000076::MODEL_STRING3);
305  CPPUNIT_ASSERT(load_cps_model_from_stream(iss, *pDataModel) == true);
306  CPPUNIT_ASSERT(pDataModel->getModel() != NULL);
307  const SBMLDocument* pDocument = pDataModel->getCurrentSBMLDocument();
308  CPPUNIT_ASSERT(pDocument == NULL);
309  std::string sbmlString;
310 
311  try
312  {
313  sbmlString = pDataModel->exportSBMLToString(NULL, 2, 1);
314  }
315  catch (...)
316  {
317  // fail if an uncaught exception occurs during export
318  CPPUNIT_ASSERT(false);
319  }
320 
321  CPPUNIT_ASSERT(!sbmlString.empty());
322  // check if the exported SBML model has two parameters
323  pDocument = pDataModel->getCurrentSBMLDocument();
324  CPPUNIT_ASSERT(pDocument != NULL);
325  const Model* pModel = pDocument->getModel();
326  CPPUNIT_ASSERT(pModel != NULL);
327  CPPUNIT_ASSERT(pModel->getListOfParameters()->size() == 1);
328  const Parameter *pP1 = pModel->getParameter(0);
329  CPPUNIT_ASSERT(pP1 != NULL);
330  CPPUNIT_ASSERT(pP1->getName() == std::string("K"));
331  CPPUNIT_ASSERT(pP1->getConstant() == true);
332  CPPUNIT_ASSERT(fabs((pP1->getValue() - 0.1) / 0.1) < 1e-6);
333  // check there are no rules and no initial assignments
334  CPPUNIT_ASSERT(pModel->getListOfRules()->size() == 0);
335  CPPUNIT_ASSERT(pModel->getListOfInitialAssignments()->size() == 0);
336  // now check the reaction
337  CPPUNIT_ASSERT(pModel->getListOfReactions()->size() == 1);
338  const Reaction* pReaction = pModel->getReaction(0);
339  CPPUNIT_ASSERT(pReaction != NULL);
340  CPPUNIT_ASSERT(pReaction->getListOfReactants()->size() == 1);
341  CPPUNIT_ASSERT(pReaction->getListOfProducts()->size() == 1);
342  CPPUNIT_ASSERT(pReaction->getListOfModifiers()->size() == 0);
343  const KineticLaw* pKLaw = pReaction->getKineticLaw();
344  CPPUNIT_ASSERT(pKLaw != NULL);
345  CPPUNIT_ASSERT(pKLaw->getListOfParameters()->size() == 1);
346  pP1 = pKLaw->getParameter(0);
347  CPPUNIT_ASSERT(pP1 != NULL);
348  CPPUNIT_ASSERT(pP1->getId() == std::string("k1"));
349  const SpeciesReference* pSpeciesReference = pReaction->getReactant(0);
350  CPPUNIT_ASSERT(pSpeciesReference != NULL);
351  CPPUNIT_ASSERT(pModel->getListOfCompartments()->size() == 1);
352  const Compartment* pCompartment = pModel->getCompartment(0);
353  CPPUNIT_ASSERT(pCompartment != NULL);
354  const ASTNode* pMath = pKLaw->getMath();
355  CPPUNIT_ASSERT(pMath != NULL);
356  // check that the expression is the compartment times the substrate times the
357  // local parameter
358  CPPUNIT_ASSERT(pMath->getType() == AST_TIMES);
359  std::vector<std::string> ids;
360  CPPUNIT_ASSERT(pMath->getNumChildren() == 2 || pMath->getNumChildren() == 3);
361 
362  if (pMath->getNumChildren() == 3)
363  {
364  CPPUNIT_ASSERT(pMath->getChild(0)->getType() == AST_NAME);
365  CPPUNIT_ASSERT(pMath->getChild(1)->getType() == AST_NAME);
366  CPPUNIT_ASSERT(pMath->getChild(2)->getType() == AST_NAME);
367  ids.push_back(pMath->getChild(0)->getName());
368  ids.push_back(pMath->getChild(1)->getName());
369  ids.push_back(pMath->getChild(2)->getName());
370  }
371  else
372  {
373  if (pMath->getChild(0)->getType() == AST_NAME)
374  {
375  ids.push_back(pMath->getChild(0)->getName());
376  pMath = pMath->getChild(1);
377  }
378  else
379  {
380  CPPUNIT_ASSERT(pMath->getChild(1)->getType() == AST_NAME);
381  ids.push_back(pMath->getChild(1)->getName());
382  pMath = pMath->getChild(0);
383  }
384 
385  CPPUNIT_ASSERT(pMath->getType() == AST_TIMES);
386  CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
387  CPPUNIT_ASSERT(pMath->getChild(0)->getType() == AST_NAME);
388  CPPUNIT_ASSERT(pMath->getChild(1)->getType() == AST_NAME);
389  ids.push_back(pMath->getChild(0)->getName());
390  ids.push_back(pMath->getChild(1)->getName());
391  }
392 
393  CPPUNIT_ASSERT(ids.size() == 3);
394  CPPUNIT_ASSERT(std::find(ids.begin(), ids.end(), std::string(pCompartment->getId())) != ids.end());
395  // make sure the local parameter is multiplied in
396  CPPUNIT_ASSERT(std::find(ids.begin(), ids.end(), std::string(pP1->getId())) != ids.end());
397  CPPUNIT_ASSERT(std::find(ids.begin(), ids.end(), std::string(pSpeciesReference->getSpecies())) != ids.end());
398 }
SBMLDocument * getCurrentSBMLDocument()
std::string exportSBMLToString(CProcessReport *pExportHandler, int sbmlLevel, int sbmlVersion)
bool load_cps_model_from_stream(std::istream &is, CCopasiDataModel &dataModel)
Definition: utilities.cpp:21
static const char * MODEL_STRING3
Definition: test000076.h:39
static CCopasiDataModel * pCOPASIDATAMODEL
Definition: test000076.h:36

Member Data Documentation

const char * test000076::MODEL_STRING1
staticprotected

Definition at line 37 of file test000076.h.

Referenced by test_bug1035_1().

const char * test000076::MODEL_STRING2
staticprotected

Definition at line 38 of file test000076.h.

Referenced by test_bug1035_2().

const char * test000076::MODEL_STRING3
staticprotected

Definition at line 39 of file test000076.h.

Referenced by test_bug1035_3().

CCopasiDataModel * test000076::pCOPASIDATAMODEL = NULL
staticprotected

Definition at line 36 of file test000076.h.

Referenced by setUp(), test_bug1035_1(), test_bug1035_2(), and test_bug1035_3().


The documentation for this class was generated from the following files: