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

#include <test_compare_utilities.h>

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

Public Member Functions

void setUp ()
 
void tearDown ()
 
void test_copasi_function_expansion ()
 

Static Protected Attributes

static const char * MODEL_STRING1
 
static CCopasiDataModelpCOPASIDATAMODEL = NULL
 

Private Member Functions

 CPPUNIT_TEST (test_copasi_function_expansion)
 
 CPPUNIT_TEST_SUITE (test_compare_utilities)
 
 CPPUNIT_TEST_SUITE_END ()
 

Detailed Description

Definition at line 24 of file test_compare_utilities.h.

Member Function Documentation

test_compare_utilities::CPPUNIT_TEST ( test_copasi_function_expansion  )
private
test_compare_utilities::CPPUNIT_TEST_SUITE ( test_compare_utilities  )
private
test_compare_utilities::CPPUNIT_TEST_SUITE_END ( )
private
void test_compare_utilities::setUp ( )

Definition at line 25 of file test_compare_utilities.cpp.

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

26 {
27  // Create the root container.
28  CCopasiRootContainer::init(false, 0, NULL);
29 
30  // Create the global data model.
32 }
static CCopasiDataModel * pCOPASIDATAMODEL
static CCopasiDataModel * addDatamodel()
static void init(int argc, char *argv[], const bool &withGui=false)
void test_compare_utilities::tearDown ( )

Definition at line 34 of file test_compare_utilities.cpp.

References CCopasiRootContainer::destroy().

void test_compare_utilities::test_copasi_function_expansion ( )

Definition at line 39 of file test_compare_utilities.cpp.

References CEvaluationNodeCall::addChild(), CEvaluationNodeVariable::ANY, CEvaluationNodeOperator::DIVIDE, CEvaluationNodeNumber::DOUBLE, expand_function_calls(), CFunctionDB::findFunction(), CEvaluationNodeCall::FUNCTION, CCopasiNode< _Data >::getChild(), CCopasiNode< _Data >::getData(), CCopasiRootContainer::getFunctionList(), CCopasiObject::getObjectName(), CEvaluationNode::getType(), CFunction::getVariables(), load_cps_model_from_stream(), CEvaluationNodeOperator::MINUS, MODEL_STRING1, CEvaluationNodeOperator::MULTIPLY, CEvaluationNode::NUMBER, CEvaluationNode::OPERATOR, pCOPASIDATAMODEL, CEvaluationNodeOperator::PLUS, CFunctionParameters::size(), CEvaluationNode::subType(), CEvaluationNode::type(), and CEvaluationNode::VARIABLE.

40 {
41  CCopasiDataModel* pDataModel = pCOPASIDATAMODEL;;
42  std::istringstream iss(test_compare_utilities::MODEL_STRING1);
43  CPPUNIT_ASSERT(load_cps_model_from_stream(iss, *pDataModel) == true);
45  // function_5
46  CEvaluationTree* pTree = pFunctionDB->findFunction("function_4");
47  CPPUNIT_ASSERT(pTree != NULL);
48  // generate a call node
49  CFunction* pFunction = dynamic_cast<CFunction*>(pTree);
50  CPPUNIT_ASSERT(pFunction != NULL);
52  CPPUNIT_ASSERT(pCallNode != NULL);
53  CFunctionParameters* pFunctionParameters = &pFunction->getVariables();
54  unsigned int i = 0, iMax = pFunctionParameters->size();
55 
56  while (i < iMax)
57  {
58  CFunctionParameter* pParameter = (*pFunctionParameters)[i];
59  CPPUNIT_ASSERT(pParameter != NULL);
61  pCallNode->addChild(pVariableNode);
62  ++i;
63  }
64 
65  CEvaluationNode* pExpanded = expand_function_calls(pCallNode, pFunctionDB);
66  delete pCallNode;
67  CPPUNIT_ASSERT(pExpanded != NULL);
68  CPPUNIT_ASSERT(CEvaluationNode::type(pExpanded->getType()) == CEvaluationNode::OPERATOR);
70  CEvaluationNode* pChild = dynamic_cast<CEvaluationNode*>(pExpanded->getChild());
71  CPPUNIT_ASSERT(pChild != NULL);
72  CPPUNIT_ASSERT(CEvaluationNode::type(pChild->getType()) == CEvaluationNode::OPERATOR);
74  pChild = dynamic_cast<CEvaluationNode*>(pChild->getChild());
75  CPPUNIT_ASSERT(pChild != NULL);
76  CPPUNIT_ASSERT(CEvaluationNode::type(pChild->getType()) == CEvaluationNode::VARIABLE);
77  CPPUNIT_ASSERT(pChild->getData() == std::string("y"));
78  pChild = dynamic_cast<CEvaluationNode*>(pChild->getSibling());
79  CPPUNIT_ASSERT(pChild != NULL);
80  CPPUNIT_ASSERT(CEvaluationNode::type(pChild->getType()) == CEvaluationNode::VARIABLE);
81  CPPUNIT_ASSERT(pChild->getData() == std::string("x"));
82  CPPUNIT_ASSERT(pChild->getSibling() == NULL);
83  pChild = dynamic_cast<CEvaluationNode*>(pExpanded->getChild()->getSibling());
84  CPPUNIT_ASSERT(pChild != NULL);
85  CPPUNIT_ASSERT(CEvaluationNode::type(pChild->getType()) == CEvaluationNode::NUMBER);
87  CPPUNIT_ASSERT((fabs(pChild->getValue() - 2.0) / 2.0) < 1e-6);
88  CPPUNIT_ASSERT(pChild->getSibling() == NULL);
89  delete pExpanded;
90 
91  // function_5
92  pTree = pFunctionDB->findFunction("function_5");
93  CPPUNIT_ASSERT(pTree != NULL);
94  // generate a call node
95  pFunction = dynamic_cast<CFunction*>(pTree);
96  CPPUNIT_ASSERT(pFunction != NULL);
98  CPPUNIT_ASSERT(pCallNode != NULL);
99  pFunctionParameters = &pFunction->getVariables();
100  i = 0, iMax = pFunctionParameters->size();
101 
102  while (i < iMax)
103  {
104  CFunctionParameter* pParameter = (*pFunctionParameters)[i];
105  CPPUNIT_ASSERT(pParameter != NULL);
107  pCallNode->addChild(pVariableNode);
108  ++i;
109  }
110 
111  pExpanded = expand_function_calls(pCallNode, pFunctionDB);
112  delete pCallNode;
113  CPPUNIT_ASSERT(pExpanded != NULL);
114  CPPUNIT_ASSERT(CEvaluationNode::type(pExpanded->getType()) == CEvaluationNode::OPERATOR);
116  pChild = dynamic_cast<CEvaluationNode*>(pExpanded->getChild());
117  CPPUNIT_ASSERT(pChild != NULL);
118  CPPUNIT_ASSERT(CEvaluationNode::type(pChild->getType()) == CEvaluationNode::OPERATOR);
120  pChild = dynamic_cast<CEvaluationNode*>(pChild->getChild());
121  CPPUNIT_ASSERT(pChild != NULL);
122  CPPUNIT_ASSERT(CEvaluationNode::type(pChild->getType()) == CEvaluationNode::VARIABLE);
123  CPPUNIT_ASSERT(pChild->getData() == std::string("a"));
124  pChild = dynamic_cast<CEvaluationNode*>(pChild->getSibling());
125  CPPUNIT_ASSERT(pChild != NULL);
126  CPPUNIT_ASSERT(CEvaluationNode::type(pChild->getType()) == CEvaluationNode::OPERATOR);
128  CPPUNIT_ASSERT(pChild->getSibling() == NULL);
129  pChild = dynamic_cast<CEvaluationNode*>(pChild->getChild());
130  CPPUNIT_ASSERT(pChild != NULL);
131  CPPUNIT_ASSERT(CEvaluationNode::type(pChild->getType()) == CEvaluationNode::VARIABLE);
132  CPPUNIT_ASSERT(pChild->getData() == std::string("c"));
133  pChild = dynamic_cast<CEvaluationNode*>(pChild->getSibling());
134  CPPUNIT_ASSERT(pChild != NULL);
135  CPPUNIT_ASSERT(CEvaluationNode::type(pChild->getType()) == CEvaluationNode::NUMBER);
137  CPPUNIT_ASSERT((fabs(pChild->getValue() - 1.3) / 1.3) < 1e-6);
138  CPPUNIT_ASSERT(pChild->getSibling() == NULL);
139 
140  // (3*b)-5.23
141  pChild = dynamic_cast<CEvaluationNode*>(pExpanded->getChild()->getSibling());
142  CPPUNIT_ASSERT(pChild != NULL);
143  CPPUNIT_ASSERT(CEvaluationNode::type(pChild->getType()) == CEvaluationNode::OPERATOR);
145  // 3*b
146  pChild = dynamic_cast<CEvaluationNode*>(pChild->getChild());
147  CPPUNIT_ASSERT(pChild != NULL);
148  CPPUNIT_ASSERT(CEvaluationNode::type(pChild->getType()) == CEvaluationNode::OPERATOR);
150  pChild = dynamic_cast<CEvaluationNode*>(pChild->getChild());
151  CPPUNIT_ASSERT(pChild != NULL);
152  CPPUNIT_ASSERT(CEvaluationNode::type(pChild->getType()) == CEvaluationNode::NUMBER);
154  CPPUNIT_ASSERT((fabs(pChild->getValue() - 3.0) / 3.0) < 1e-6);
155  pChild = dynamic_cast<CEvaluationNode*>(pChild->getSibling());
156  CPPUNIT_ASSERT(CEvaluationNode::type(pChild->getType()) == CEvaluationNode::VARIABLE);
157  CPPUNIT_ASSERT(pChild->getData() == std::string("b"));
158  CPPUNIT_ASSERT(pChild->getSibling() == NULL);
159  // 5.23
160  pChild = dynamic_cast<CEvaluationNode*>(pExpanded->getChild()->getSibling()->getChild()->getSibling());
161  CPPUNIT_ASSERT(pChild != NULL);
162  CPPUNIT_ASSERT(CEvaluationNode::type(pChild->getType()) == CEvaluationNode::NUMBER);
164  CPPUNIT_ASSERT((fabs(pChild->getValue() - 5.23) / 5.23) < 1e-6);
165  CPPUNIT_ASSERT(pChild->getSibling() == NULL);
166 
167  delete pExpanded;
168 
169  // function_6
170  pTree = pFunctionDB->findFunction("function_6");
171  CPPUNIT_ASSERT(pTree != NULL);
172  // generate a call node
173  pFunction = dynamic_cast<CFunction*>(pTree);
174  CPPUNIT_ASSERT(pFunction != NULL);
175  pCallNode = new CEvaluationNodeCall(CEvaluationNodeCall::FUNCTION, pFunction->getObjectName());
176  CPPUNIT_ASSERT(pCallNode != NULL);
177  pFunctionParameters = &pFunction->getVariables();
178  i = 0, iMax = pFunctionParameters->size();
179 
180  while (i < iMax)
181  {
182  CFunctionParameter* pParameter = (*pFunctionParameters)[i];
183  CPPUNIT_ASSERT(pParameter != NULL);
185  pCallNode->addChild(pVariableNode);
186  ++i;
187  }
188 
189  pExpanded = expand_function_calls(pCallNode, pFunctionDB);
190  delete pCallNode;
191  CPPUNIT_ASSERT(pExpanded != NULL);
192  // (k1-k3*1.3)+((3*k2)-5.23)
193  CPPUNIT_ASSERT(CEvaluationNode::type(pExpanded->getType()) == CEvaluationNode::OPERATOR);
195  pChild = dynamic_cast<CEvaluationNode*>(pExpanded->getChild());
196  CPPUNIT_ASSERT(pChild != NULL);
197  CPPUNIT_ASSERT(CEvaluationNode::type(pChild->getType()) == CEvaluationNode::OPERATOR);
199  pChild = dynamic_cast<CEvaluationNode*>(pChild->getChild());
200  CPPUNIT_ASSERT(pChild != NULL);
201  CPPUNIT_ASSERT(CEvaluationNode::type(pChild->getType()) == CEvaluationNode::VARIABLE);
202  CPPUNIT_ASSERT(pChild->getData() == std::string("k1"));
203  pChild = dynamic_cast<CEvaluationNode*>(pChild->getSibling());
204  CPPUNIT_ASSERT(pChild != NULL);
205  CPPUNIT_ASSERT(CEvaluationNode::type(pChild->getType()) == CEvaluationNode::OPERATOR);
207  CPPUNIT_ASSERT(pChild->getSibling() == NULL);
208  pChild = dynamic_cast<CEvaluationNode*>(pChild->getChild());
209  CPPUNIT_ASSERT(pChild != NULL);
210  CPPUNIT_ASSERT(CEvaluationNode::type(pChild->getType()) == CEvaluationNode::VARIABLE);
211  CPPUNIT_ASSERT(pChild->getData() == std::string("k3"));
212  pChild = dynamic_cast<CEvaluationNode*>(pChild->getSibling());
213  CPPUNIT_ASSERT(pChild != NULL);
214  CPPUNIT_ASSERT(CEvaluationNode::type(pChild->getType()) == CEvaluationNode::NUMBER);
216  CPPUNIT_ASSERT((fabs(pChild->getValue() - 1.3) / 1.3) < 1e-6);
217  CPPUNIT_ASSERT(pChild->getSibling() == NULL);
218 
219  // (3*b)-5.23
220  pChild = dynamic_cast<CEvaluationNode*>(pExpanded->getChild()->getSibling());
221  CPPUNIT_ASSERT(pChild != NULL);
222  CPPUNIT_ASSERT(CEvaluationNode::type(pChild->getType()) == CEvaluationNode::OPERATOR);
224  // 3*b
225  pChild = dynamic_cast<CEvaluationNode*>(pChild->getChild());
226  CPPUNIT_ASSERT(pChild != NULL);
227  CPPUNIT_ASSERT(CEvaluationNode::type(pChild->getType()) == CEvaluationNode::OPERATOR);
229  pChild = dynamic_cast<CEvaluationNode*>(pChild->getChild());
230  CPPUNIT_ASSERT(pChild != NULL);
231  CPPUNIT_ASSERT(CEvaluationNode::type(pChild->getType()) == CEvaluationNode::NUMBER);
233  CPPUNIT_ASSERT((fabs(pChild->getValue() - 3.0) / 3.0) < 1e-6);
234  pChild = dynamic_cast<CEvaluationNode*>(pChild->getSibling());
235  CPPUNIT_ASSERT(CEvaluationNode::type(pChild->getType()) == CEvaluationNode::VARIABLE);
236  CPPUNIT_ASSERT(pChild->getData() == std::string("k2"));
237  CPPUNIT_ASSERT(pChild->getSibling() == NULL);
238  // 5.23
239  pChild = dynamic_cast<CEvaluationNode*>(pExpanded->getChild()->getSibling()->getChild()->getSibling());
240  CPPUNIT_ASSERT(pChild != NULL);
241  CPPUNIT_ASSERT(CEvaluationNode::type(pChild->getType()) == CEvaluationNode::NUMBER);
243  CPPUNIT_ASSERT((fabs(pChild->getValue() - 5.23) / 5.23) < 1e-6);
244  CPPUNIT_ASSERT(pChild->getSibling() == NULL);
245 
246  delete pExpanded;
247 }
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
const std::string & getObjectName() const
const Type & getType() const
bool load_cps_model_from_stream(std::istream &is, CCopasiDataModel &dataModel)
Definition: utilities.cpp:21
static Type type(const Type &type)
static CCopasiDataModel * pCOPASIDATAMODEL
static const char * MODEL_STRING1
static CFunctionDB * getFunctionList()
static Type subType(const Type &type)
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
virtual const Data & getData() const
Definition: CCopasiNode.h:118
ASTNode * expand_function_calls(const ASTNode *pNode, const ListOfFunctionDefinitions *pFunctions)
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210
CFunction * findFunction(const std::string &functionName)
CFunctionParameters & getVariables()
Definition: CFunction.cpp:148

Member Data Documentation

const char * test_compare_utilities::MODEL_STRING1
staticprotected

Definition at line 31 of file test_compare_utilities.h.

Referenced by test_copasi_function_expansion().

CCopasiDataModel * test_compare_utilities::pCOPASIDATAMODEL = NULL
staticprotected

Definition at line 32 of file test_compare_utilities.h.

Referenced by setUp(), and test_copasi_function_expansion().


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