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

#include <test000055.h>

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

Public Member Functions

void setUp ()
 
void tearDown ()
 
void test_bug1004 ()
 

Static Protected Attributes

static const char * MODEL_STRING
 
static CCopasiDataModelpCOPASIDATAMODEL = NULL
 

Private Member Functions

 CPPUNIT_TEST (test_bug1004)
 
 CPPUNIT_TEST_SUITE (test000055)
 
 CPPUNIT_TEST_SUITE_END ()
 

Detailed Description

Definition at line 24 of file test000055.h.

Member Function Documentation

test000055::CPPUNIT_TEST ( test_bug1004  )
private
test000055::CPPUNIT_TEST_SUITE ( test000055  )
private
test000055::CPPUNIT_TEST_SUITE_END ( )
private
void test000055::setUp ( )

Definition at line 39 of file test000055.cpp.

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

40 {
41  // Create the root container.
42  CCopasiRootContainer::init(0, NULL, false);
43  // Create the global data model.
45 }
static CCopasiDataModel * addDatamodel()
static CCopasiDataModel * pCOPASIDATAMODEL
Definition: test000055.h:32
static void init(int argc, char *argv[], const bool &withGui=false)
void test000055::tearDown ( )

Definition at line 47 of file test000055.cpp.

References CCopasiRootContainer::destroy().

void test000055::test_bug1004 ( )

Definition at line 52 of file test000055.cpp.

References CEvaluationNodeObject::CN, CCopasiDataModel::exportSBMLToString(), CCopasiDataModel::getCurrentSBMLDocument(), CCopasiDataModel::getModel(), CModelEntity::getSBMLId(), CCopasiDataModel::importSBMLFromString(), MODEL_STRING, pCOPASIDATAMODEL, and CEvaluationTree::setRoot().

53 {
54  // load the CPS file
55  // export to SBML
56  // check the resulting SBML model
57  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;
58  CPPUNIT_ASSERT(pDataModel->importSBMLFromString(test000055::MODEL_STRING));
59  CPPUNIT_ASSERT(pDataModel->getModel() != NULL);
60  // check the order of the rules
61  const SBMLDocument* pDocument = pDataModel->getCurrentSBMLDocument();
62  const Model* pSBMLModel = pDocument->getModel();
63  CPPUNIT_ASSERT(pSBMLModel != NULL);
64  CPPUNIT_ASSERT(pSBMLModel->getNumCompartments() == 0);
65  CPPUNIT_ASSERT(pSBMLModel->getNumSpecies() == 0);
66  CPPUNIT_ASSERT(pSBMLModel->getNumReactions() == 0);
67  CPPUNIT_ASSERT(pSBMLModel->getNumInitialAssignments() == 0);
68  CPPUNIT_ASSERT(pSBMLModel->getNumParameters() == 5);
69  const Parameter* pParameter1 = pSBMLModel->getParameter(0);
70  CPPUNIT_ASSERT(pParameter1 != NULL);
71  CPPUNIT_ASSERT(pParameter1->getConstant() == false);
72  const Parameter* pParameter2 = pSBMLModel->getParameter(1);
73  CPPUNIT_ASSERT(pParameter2 != NULL);
74  CPPUNIT_ASSERT(pParameter2->getConstant() == false);
75  const Parameter* pParameter3 = pSBMLModel->getParameter(2);
76  CPPUNIT_ASSERT(pParameter3 != NULL);
77  CPPUNIT_ASSERT(pParameter3->getConstant() == false);
78  const Parameter* pParameter4 = pSBMLModel->getParameter(3);
79  CPPUNIT_ASSERT(pParameter4 != NULL);
80  CPPUNIT_ASSERT(pParameter4->getConstant() == false);
81  const Parameter* pParameter5 = pSBMLModel->getParameter(4);
82  CPPUNIT_ASSERT(pParameter5 != NULL);
83  CPPUNIT_ASSERT(pParameter5->getConstant() == false);
84  CPPUNIT_ASSERT(pSBMLModel->getNumRules() == 5);
85 
86  const Rule* pRule = pSBMLModel->getRule(0);
87  CPPUNIT_ASSERT(pRule != NULL);
88  CPPUNIT_ASSERT(pRule->getTypeCode() == SBML_ASSIGNMENT_RULE);
89  const AssignmentRule* pARule = dynamic_cast<const AssignmentRule*>(pRule);
90  CPPUNIT_ASSERT(pARule != NULL);
91  CPPUNIT_ASSERT(pARule->getVariable() == pParameter1->getId());
92  CPPUNIT_ASSERT(pARule->isSetMath() == true);
93  const ASTNode* pMath = pARule->getMath();
94  CPPUNIT_ASSERT(pMath != NULL);
95  CPPUNIT_ASSERT(pMath->getType() == AST_TIMES);
96  CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
97  const ASTNode* pChild1 = pMath->getChild(0);
98  CPPUNIT_ASSERT(pChild1 != NULL);
99  CPPUNIT_ASSERT(pChild1->getType() == AST_REAL);
100  CPPUNIT_ASSERT(fabs((pChild1->getReal() - 3.0) / 3.0) < 1e-15);
101  const ASTNode* pChild2 = pMath->getChild(1);
102  CPPUNIT_ASSERT(pChild2 != NULL);
103  CPPUNIT_ASSERT(pChild2->getType() == AST_REAL);
104  CPPUNIT_ASSERT(fabs((pChild2->getReal() - 4.0) / 4.0) < 1e-15);
105 
106  pRule = pSBMLModel->getRule(1);
107  CPPUNIT_ASSERT(pRule != NULL);
108  CPPUNIT_ASSERT(pRule->getTypeCode() == SBML_ASSIGNMENT_RULE);
109  pARule = dynamic_cast<const AssignmentRule*>(pRule);
110  CPPUNIT_ASSERT(pARule != NULL);
111  CPPUNIT_ASSERT(pARule->getVariable() == pParameter2->getId());
112  CPPUNIT_ASSERT(pARule->isSetMath() == true);
113  pMath = pARule->getMath();
114  CPPUNIT_ASSERT(pMath != NULL);
115  CPPUNIT_ASSERT(pMath->getType() == AST_PLUS);
116  CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
117  pChild1 = pMath->getChild(0);
118  CPPUNIT_ASSERT(pChild1 != NULL);
119  CPPUNIT_ASSERT(pChild1->getType() == AST_REAL);
120  CPPUNIT_ASSERT(fabs((pChild1->getReal() - 2.0) / 2.0) < 1e-15);
121  pChild2 = pMath->getChild(1);
122  CPPUNIT_ASSERT(pChild2 != NULL);
123  CPPUNIT_ASSERT(pChild2->getType() == AST_REAL);
124  CPPUNIT_ASSERT(fabs((pChild2->getReal() - 9.0) / 9.0) < 1e-15);
125 
126  pRule = pSBMLModel->getRule(2);
127  CPPUNIT_ASSERT(pRule != NULL);
128  CPPUNIT_ASSERT(pRule->getTypeCode() == SBML_ASSIGNMENT_RULE);
129  pARule = dynamic_cast<const AssignmentRule*>(pRule);
130  CPPUNIT_ASSERT(pARule != NULL);
131  CPPUNIT_ASSERT(pARule->getVariable() == pParameter3->getId());
132  CPPUNIT_ASSERT(pARule->isSetMath() == true);
133  pMath = pARule->getMath();
134  CPPUNIT_ASSERT(pMath != NULL);
135  CPPUNIT_ASSERT(pMath->getType() == AST_MINUS);
136  CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
137  pChild1 = pMath->getChild(0);
138  CPPUNIT_ASSERT(pChild1 != NULL);
139  CPPUNIT_ASSERT(pChild1->getType() == AST_REAL);
140  CPPUNIT_ASSERT(fabs((pChild1->getReal() - 8.0) / 8.0) < 1e-15);
141  pChild2 = pMath->getChild(1);
142  CPPUNIT_ASSERT(pChild2 != NULL);
143  CPPUNIT_ASSERT(pChild2->getType() == AST_REAL);
144  CPPUNIT_ASSERT(fabs((pChild2->getReal() - 4.0) / 4.0) < 1e-15);
145 
146  pRule = pSBMLModel->getRule(3);
147  CPPUNIT_ASSERT(pRule != NULL);
148  CPPUNIT_ASSERT(pRule->getTypeCode() == SBML_ASSIGNMENT_RULE);
149  pARule = dynamic_cast<const AssignmentRule*>(pRule);
150  CPPUNIT_ASSERT(pARule != NULL);
151  CPPUNIT_ASSERT(pARule->getVariable() == pParameter4->getId());
152  CPPUNIT_ASSERT(pARule->isSetMath() == true);
153  pMath = pARule->getMath();
154  CPPUNIT_ASSERT(pMath != NULL);
155  CPPUNIT_ASSERT(pMath->getType() == AST_DIVIDE);
156  CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
157  pChild1 = pMath->getChild(0);
158  CPPUNIT_ASSERT(pChild1 != NULL);
159  CPPUNIT_ASSERT(pChild1->getType() == AST_REAL);
160  CPPUNIT_ASSERT(fabs((pChild1->getReal() - 9.0) / 9.0) < 1e-15);
161  pChild2 = pMath->getChild(1);
162  CPPUNIT_ASSERT(pChild2 != NULL);
163  CPPUNIT_ASSERT(pChild2->getType() == AST_REAL);
164  CPPUNIT_ASSERT(fabs((pChild2->getReal() - 3.0) / 3.0) < 1e-15);
165 
166  pRule = pSBMLModel->getRule(4);
167  CPPUNIT_ASSERT(pRule != NULL);
168  CPPUNIT_ASSERT(pRule->getTypeCode() == SBML_ASSIGNMENT_RULE);
169  pARule = dynamic_cast<const AssignmentRule*>(pRule);
170  CPPUNIT_ASSERT(pARule != NULL);
171  CPPUNIT_ASSERT(pARule->getVariable() == pParameter5->getId());
172  CPPUNIT_ASSERT(pARule->isSetMath() == true);
173  pMath = pARule->getMath();
174  CPPUNIT_ASSERT(pMath != NULL);
175  CPPUNIT_ASSERT(pMath->getType() == AST_PLUS);
176  CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
177  pChild1 = pMath->getChild(0);
178  CPPUNIT_ASSERT(pChild1 != NULL);
179  CPPUNIT_ASSERT(pChild1->getType() == AST_REAL);
180  CPPUNIT_ASSERT(fabs((pChild1->getReal() - 6.0) / 6.0) < 1e-15);
181  pChild2 = pMath->getChild(1);
182  CPPUNIT_ASSERT(pChild2 != NULL);
183  CPPUNIT_ASSERT(pChild2->getType() == AST_REAL);
184  CPPUNIT_ASSERT(fabs((pChild2->getReal() - 1.0) / 1.0) < 1e-15);
185  // modify the assignment rules
186  // make rule for parameter1 depend on parameter3
187  // make rule for parameter3 depend on parameter2
188  // make rule for parameter4 depend on parameter5
189  // make rule for parameter2 depend on parameter4
190  CModel* pModel = pDataModel->getModel();
191  CPPUNIT_ASSERT(pModel != NULL);
192  CPPUNIT_ASSERT(pModel->getModelValues().size() == 5);
193  // find model value that corresponds to parameter1
194  CModelValue *pMV1 = NULL, *pMV2 = NULL, *pMV3 = NULL, *pMV4 = NULL, *pMV5 = NULL;
195  unsigned int i, iMax = pModel->getModelValues().size();
196 
197  for (i = 0; i < iMax; ++i)
198  {
199  CModelValue* pTmpMV = pModel->getModelValues()[i];
200 
201  if (pTmpMV->getSBMLId() == pParameter1->getId())
202  {
203  pMV1 = pTmpMV;
204  }
205  else if (pTmpMV->getSBMLId() == pParameter2->getId())
206  {
207  pMV2 = pTmpMV;
208  }
209  else if (pTmpMV->getSBMLId() == pParameter3->getId())
210  {
211  pMV3 = pTmpMV;
212  }
213  else if (pTmpMV->getSBMLId() == pParameter4->getId())
214  {
215  pMV4 = pTmpMV;
216  }
217  else if (pTmpMV->getSBMLId() == pParameter5->getId())
218  {
219  pMV5 = pTmpMV;
220  }
221  }
222 
223  CPPUNIT_ASSERT(pMV1 != NULL);
224  CPPUNIT_ASSERT(pMV2 != NULL);
225  CPPUNIT_ASSERT(pMV3 != NULL);
226  CPPUNIT_ASSERT(pMV4 != NULL);
227  CPPUNIT_ASSERT(pMV5 != NULL);
228  CEvaluationNodeObject* pObjectNode = new CEvaluationNodeObject(CEvaluationNodeObject::CN, "<" + pMV3->getCN() + ",Reference=Value>");
229  CExpression* pExpr = new CExpression;
230  pExpr->setRoot(pObjectNode);
231  pMV1->setExpressionPtr(pExpr);
232  pObjectNode = new CEvaluationNodeObject(CEvaluationNodeObject::CN, "<" + pMV2->getCN() + ",Reference=Value>");
233  pExpr = new CExpression;
234  pExpr->setRoot(pObjectNode);
235  pMV3->setExpressionPtr(pExpr);
236  pObjectNode = new CEvaluationNodeObject(CEvaluationNodeObject::CN, "<" + pMV5->getCN() + ",Reference=Value>");
237  pExpr = new CExpression;
238  pExpr->setRoot(pObjectNode);
239  pMV4->setExpressionPtr(pExpr);
240  pObjectNode = new CEvaluationNodeObject(CEvaluationNodeObject::CN, "<" + pMV4->getCN() + ",Reference=Value>");
241  pExpr = new CExpression;
242  pExpr->setRoot(pObjectNode);
243  pMV2->setExpressionPtr(pExpr);
244  // reexport to SBML L2V1
245  CPPUNIT_ASSERT(pDataModel->exportSBMLToString(NULL, 2, 1).empty() == false);
246  pDocument = pDataModel->getCurrentSBMLDocument();
247  CPPUNIT_ASSERT(pDocument != NULL);
248  pSBMLModel = pDocument->getModel();
249  CPPUNIT_ASSERT(pSBMLModel != NULL);
250  CPPUNIT_ASSERT(pSBMLModel->getNumCompartments() == 0);
251  CPPUNIT_ASSERT(pSBMLModel->getNumSpecies() == 0);
252  CPPUNIT_ASSERT(pSBMLModel->getNumReactions() == 0);
253  CPPUNIT_ASSERT(pSBMLModel->getNumInitialAssignments() == 0);
254  CPPUNIT_ASSERT(pSBMLModel->getNumParameters() == 5);
255  pParameter1 = pSBMLModel->getParameter(0);
256  CPPUNIT_ASSERT(pParameter1 != NULL);
257  CPPUNIT_ASSERT(pParameter1->getConstant() == false);
258  pParameter2 = pSBMLModel->getParameter(1);
259  CPPUNIT_ASSERT(pParameter2 != NULL);
260  CPPUNIT_ASSERT(pParameter2->getConstant() == false);
261  pParameter3 = pSBMLModel->getParameter(2);
262  CPPUNIT_ASSERT(pParameter3 != NULL);
263  CPPUNIT_ASSERT(pParameter3->getConstant() == false);
264  pParameter4 = pSBMLModel->getParameter(3);
265  CPPUNIT_ASSERT(pParameter4 != NULL);
266  CPPUNIT_ASSERT(pParameter4->getConstant() == false);
267  pParameter5 = pSBMLModel->getParameter(4);
268  CPPUNIT_ASSERT(pParameter5 != NULL);
269  CPPUNIT_ASSERT(pParameter5->getConstant() == false);
270  CPPUNIT_ASSERT(pSBMLModel->getNumRules() == 5);
271 
272  pRule = pSBMLModel->getRule(0);
273  CPPUNIT_ASSERT(pRule != NULL);
274  CPPUNIT_ASSERT(pRule->getTypeCode() == SBML_ASSIGNMENT_RULE);
275  pARule = dynamic_cast<const AssignmentRule*>(pRule);
276  CPPUNIT_ASSERT(pARule != NULL);
277  CPPUNIT_ASSERT(pARule->getVariable() == pParameter5->getId());
278  CPPUNIT_ASSERT(pARule->isSetMath() == true);
279  pMath = pARule->getMath();
280  CPPUNIT_ASSERT(pMath != NULL);
281  CPPUNIT_ASSERT(pMath->getType() == AST_PLUS);
282  CPPUNIT_ASSERT(pMath->getNumChildren() == 2);
283  pChild1 = pMath->getChild(0);
284  CPPUNIT_ASSERT(pChild1 != NULL);
285  CPPUNIT_ASSERT(pChild1->getType() == AST_REAL);
286  CPPUNIT_ASSERT(fabs((pChild1->getReal() - 6.0) / 6.0) < 1e-15);
287  pChild2 = pMath->getChild(1);
288  CPPUNIT_ASSERT(pChild2 != NULL);
289  CPPUNIT_ASSERT(pChild2->getType() == AST_REAL);
290  CPPUNIT_ASSERT(fabs((pChild2->getReal() - 1.0) / 1.0) < 1e-15);
291 
292  pRule = pSBMLModel->getRule(1);
293  CPPUNIT_ASSERT(pRule != NULL);
294  CPPUNIT_ASSERT(pRule->getTypeCode() == SBML_ASSIGNMENT_RULE);
295  pARule = dynamic_cast<const AssignmentRule*>(pRule);
296  CPPUNIT_ASSERT(pARule != NULL);
297  CPPUNIT_ASSERT(pARule->getVariable() == pParameter4->getId());
298  CPPUNIT_ASSERT(pARule->isSetMath() == true);
299  pMath = pARule->getMath();
300  CPPUNIT_ASSERT(pMath != NULL);
301  CPPUNIT_ASSERT(pMath->getType() == AST_NAME);
302  CPPUNIT_ASSERT(pMath->getName() == pParameter5->getId());
303  CPPUNIT_ASSERT(pMath->getNumChildren() == 0);
304 
305  pRule = pSBMLModel->getRule(2);
306  CPPUNIT_ASSERT(pRule != NULL);
307  CPPUNIT_ASSERT(pRule->getTypeCode() == SBML_ASSIGNMENT_RULE);
308  pARule = dynamic_cast<const AssignmentRule*>(pRule);
309  CPPUNIT_ASSERT(pARule != NULL);
310  CPPUNIT_ASSERT(pARule->getVariable() == pParameter2->getId());
311  CPPUNIT_ASSERT(pARule->isSetMath() == true);
312  pMath = pARule->getMath();
313  CPPUNIT_ASSERT(pMath != NULL);
314  CPPUNIT_ASSERT(pMath->getType() == AST_NAME);
315  CPPUNIT_ASSERT(pMath->getName() == pParameter4->getId());
316  CPPUNIT_ASSERT(pMath->getNumChildren() == 0);
317 
318  pRule = pSBMLModel->getRule(3);
319  CPPUNIT_ASSERT(pRule != NULL);
320  CPPUNIT_ASSERT(pRule->getTypeCode() == SBML_ASSIGNMENT_RULE);
321  pARule = dynamic_cast<const AssignmentRule*>(pRule);
322  CPPUNIT_ASSERT(pARule != NULL);
323  CPPUNIT_ASSERT(pARule->getVariable() == pParameter3->getId());
324  CPPUNIT_ASSERT(pARule->isSetMath() == true);
325  pMath = pARule->getMath();
326  CPPUNIT_ASSERT(pMath != NULL);
327  CPPUNIT_ASSERT(pMath->getType() == AST_NAME);
328  CPPUNIT_ASSERT(pMath->getName() == pParameter2->getId());
329  CPPUNIT_ASSERT(pMath->getNumChildren() == 0);
330 
331  pRule = pSBMLModel->getRule(4);
332  CPPUNIT_ASSERT(pRule != NULL);
333  CPPUNIT_ASSERT(pRule->getTypeCode() == SBML_ASSIGNMENT_RULE);
334  pARule = dynamic_cast<const AssignmentRule*>(pRule);
335  CPPUNIT_ASSERT(pARule != NULL);
336  CPPUNIT_ASSERT(pARule->getVariable() == pParameter1->getId());
337  CPPUNIT_ASSERT(pARule->isSetMath() == true);
338  pMath = pARule->getMath();
339  CPPUNIT_ASSERT(pMath != NULL);
340  CPPUNIT_ASSERT(pMath->getType() == AST_NAME);
341  CPPUNIT_ASSERT(pMath->getName() == pParameter3->getId());
342  CPPUNIT_ASSERT(pMath->getNumChildren() == 0);
343 }
virtual bool setRoot(CEvaluationNode *pRootNode)
SBMLDocument * getCurrentSBMLDocument()
const std::string & getSBMLId() const
std::string exportSBMLToString(CProcessReport *pExportHandler, int sbmlLevel, int sbmlVersion)
static CCopasiDataModel * pCOPASIDATAMODEL
Definition: test000055.h:32
bool importSBMLFromString(const std::string &sbmlDocumentText, CProcessReport *pImportHandler=NULL, const bool &deleteOldData=true)
Definition: CModel.h:50
static const char * MODEL_STRING
Definition: test000055.h:31

Member Data Documentation

const char * test000055::MODEL_STRING
staticprotected

Definition at line 31 of file test000055.h.

Referenced by test_bug1004().

CCopasiDataModel * test000055::pCOPASIDATAMODEL = NULL
staticprotected

Definition at line 32 of file test000055.h.

Referenced by setUp(), and test_bug1004().


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