COPASI API  4.16.103
test_depth_first_iterator.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/compareExpressions/unittests/test_depth_first_iterator.cpp,v $
3 // $Revision: 1.4 $
4 // $Name: $
5 // $Author: bergmann $
6 // $Date: 2012/05/16 06:24:48 $
7 // End CVS Header
8 
9 // Copyright (C) 2012 - 2011 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., University of Heidelberg, and The University
11 // of Manchester.
12 // All rights reserved.
13 
15 
16 #include <limits>
17 #include <cmath>
18 #include <string>
19 
25 
27 
29 {
30  CCopasiRootContainer::init(false, 0, NULL);
31 }
32 
34 {
36 }
37 
39 {
40  std::string infix("7-(3+(4-6))+1*8");
41  CEvaluationTree* pTree = new CEvaluationTree();
42  pTree->setInfix(infix);
43  std::string s = pTree->getInfix();
44  CPPUNIT_ASSERT(pTree->getRoot() != NULL);
46  CPPUNIT_ASSERT(it.isValid());
47  CEvaluationNode* pNode = NULL;
48  CEvaluationNodeNumber* pNumberNode = NULL;
49  CEvaluationNodeOperator* pOperatorNode = NULL;
50  // 7
51  pNode = *it;
52  CPPUNIT_ASSERT(pNode != NULL);
53  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::NUMBER);
54  pNumberNode = dynamic_cast<CEvaluationNodeNumber*>(pNode);
55  CPPUNIT_ASSERT(pNumberNode != NULL);
56  CPPUNIT_ASSERT((fabs(pNumberNode->getValue() - 7) / 7.0) <= std::numeric_limits<double>::min());
57  // 3
58  ++it;
59  CPPUNIT_ASSERT(it.isValid() == true);
60  pNode = *it;
61  CPPUNIT_ASSERT(pNode != NULL);
62  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::NUMBER);
63  pNumberNode = dynamic_cast<CEvaluationNodeNumber*>(pNode);
64  CPPUNIT_ASSERT(pNumberNode != NULL);
65  CPPUNIT_ASSERT((fabs(pNumberNode->getValue() - 3) / 3.0) <= std::numeric_limits<double>::min());
66  // 4
67  ++it;
68  CPPUNIT_ASSERT(it.isValid() == true);
69  pNode = *it;
70  CPPUNIT_ASSERT(pNode != NULL);
71  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::NUMBER);
72  pNumberNode = dynamic_cast<CEvaluationNodeNumber*>(pNode);
73  CPPUNIT_ASSERT(pNumberNode != NULL);
74  CPPUNIT_ASSERT((fabs(pNumberNode->getValue() - 4) / 4.0) <= std::numeric_limits<double>::min());
75  // 6
76  ++it;
77  CPPUNIT_ASSERT(it.isValid() == true);
78  pNode = *it;
79  CPPUNIT_ASSERT(pNode != NULL);
80  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::NUMBER);
81  pNumberNode = dynamic_cast<CEvaluationNodeNumber*>(pNode);
82  CPPUNIT_ASSERT(pNumberNode != NULL);
83  CPPUNIT_ASSERT((fabs(pNumberNode->getValue() - 6) / 6.0) <= std::numeric_limits<double>::min());
84  // -
85  ++it;
86  CPPUNIT_ASSERT(it.isValid() == true);
87  pNode = *it;
88  CPPUNIT_ASSERT(pNode != NULL);
89  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::OPERATOR);
90  pOperatorNode = dynamic_cast<CEvaluationNodeOperator*>(pNode);
91  CPPUNIT_ASSERT(pOperatorNode != NULL);
93  // +
94  ++it;
95  CPPUNIT_ASSERT(it.isValid() == true);
96  pNode = *it;
97  CPPUNIT_ASSERT(pNode != NULL);
98  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::OPERATOR);
99  pOperatorNode = dynamic_cast<CEvaluationNodeOperator*>(pNode);
100  CPPUNIT_ASSERT(pOperatorNode != NULL);
102  // -
103  ++it;
104  CPPUNIT_ASSERT(it.isValid() == true);
105  pNode = *it;
106  CPPUNIT_ASSERT(pNode != NULL);
107  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::OPERATOR);
108  pOperatorNode = dynamic_cast<CEvaluationNodeOperator*>(pNode);
109  CPPUNIT_ASSERT(pOperatorNode != NULL);
111  // 1
112  ++it;
113  CPPUNIT_ASSERT(it.isValid() == true);
114  pNode = *it;
115  CPPUNIT_ASSERT(pNode != NULL);
116  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::NUMBER);
117  pNumberNode = dynamic_cast<CEvaluationNodeNumber*>(pNode);
118  CPPUNIT_ASSERT(pNumberNode != NULL);
119  CPPUNIT_ASSERT((fabs(pNumberNode->getValue() - 1) / 1.0) <= std::numeric_limits<double>::min());
120  // 8
121  ++it;
122  CPPUNIT_ASSERT(it.isValid() == true);
123  pNode = *it;
124  CPPUNIT_ASSERT(pNode != NULL);
125  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::NUMBER);
126  pNumberNode = dynamic_cast<CEvaluationNodeNumber*>(pNode);
127  CPPUNIT_ASSERT(pNumberNode != NULL);
128  CPPUNIT_ASSERT((fabs(pNumberNode->getValue() - 8) / 8.0) <= std::numeric_limits<double>::min());
129  // *
130  ++it;
131  CPPUNIT_ASSERT(it.isValid() == true);
132  pNode = *it;
133  CPPUNIT_ASSERT(pNode != NULL);
134  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::OPERATOR);
135  pOperatorNode = dynamic_cast<CEvaluationNodeOperator*>(pNode);
136  CPPUNIT_ASSERT(pOperatorNode != NULL);
138  // +
139  ++it;
140  CPPUNIT_ASSERT(it.isValid() == true);
141  pNode = *it;
142  CPPUNIT_ASSERT(pNode != NULL);
143  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::OPERATOR);
144  pOperatorNode = dynamic_cast<CEvaluationNodeOperator*>(pNode);
145  CPPUNIT_ASSERT(pOperatorNode != NULL);
147 
148  ++it;
149  CPPUNIT_ASSERT(it.isValid() == false);
150  CPPUNIT_ASSERT(*it == NULL);
151 
152  delete pTree;
153 }
154 
const C_FLOAT64 & getValue() const
const Type & getType() const
static Type type(const Type &type)
static Type subType(const Type &type)
static void init(int argc, char *argv[], const bool &withGui=false)
#define min(a, b)
Definition: f2c.h:175
CEvaluationNode * getRoot()
const std::string & getInfix() const
virtual bool setInfix(const std::string &infix)