1 #include <cppunit/extensions/HelperMacros.h>
3 #include <boost/assign/std/vector.hpp>
4 #include <boost/assign/list_of.hpp>
6 #include <tst/Verify.h>
7 #include <utl/MathExpressionGrammar.h>
8 #include <utl/ErrorLogger.h>
9 #include <utl/AugerException.h>
10 #include <utl/SymbolTable.h>
11 #include <utl/ExpressionParser.h>
22 using namespace boost::assign;
25 #define ASSERT_CLOSE(x, y) CPPUNIT_ASSERT(Verify<CloseTo>(x, y))
26 #define ASSERT_NOTCLOSE(x, y) CPPUNIT_ASSERT(Verify<Not<CloseTo> >(x, y))
41 CPPUNIT_TEST(testEvaluating);
42 CPPUNIT_TEST(testMath);
43 CPPUNIT_TEST_SUITE_END();
72 const map<string, double> expressionValue =
75 (
"a * b * c", t[
"a"] * t[
"b"] * t[
"c"])
76 (
"b * c", t[
"b"] * t[
"c"])
77 (
"c^2",
pow(t[
"c"], 2))
79 (
"c*d^2", t[
"c"] *
pow(t[
"d"], 2))
80 (
"b/c*d", t[
"b"] / t[
"c"] * t[
"d"])
81 (
"scient1 * scient2 * scient3", t[
"scient1"] * t[
"scient2"] * t[
"scient3"])
82 (
"doub1 / doub2 * scient3", t[
"doub1"] / t[
"doub2"] * t[
"scient3"])
88 for (map<string, double>::const_iterator it = expressionValue.begin(), end = expressionValue.end();
100 const map<string, double> expressionValue2 =
102 (
"c+x*doub1", t[
"c"]+t2[
"x"]*t[
"doub1"])
106 for (map<string, double>::const_iterator it = expressionValue2.begin(), end = expressionValue2.end();
123 (
"scient1", 1.234e-1)
124 (
"scient2", 1.234e-2)
125 (
"scient3", 1.234e-3)
134 const map<string, double> expressionValueOne =
136 (
"x*a", tOne[
"a"]*tOne[
"x"])
137 (
"a+x", tOne[
"a"]+tOne[
"x"])
138 (
"(x*a)", tOne[
"a"]*tOne[
"x"])
139 (
"(a+x)", tOne[
"a"]+tOne[
"x"])
140 (
"(x)+a", tOne[
"a"]+tOne[
"x"])
141 (
"x+(a)", tOne[
"a"]+tOne[
"x"])
142 (
"(x)*a", tOne[
"a"]*tOne[
"x"])
143 (
"x*(a)", tOne[
"a"]*tOne[
"x"])
144 (
"a+b*x+a", tOne[
"a"]+tOne[
"b"]*tOne[
"x"]+tOne[
"a"])
145 (
"scient1+b*doub1+scient1*x^2-b*(-4.)", tOne[
"scient1"]+tOne[
"b"]*tOne[
"doub1"]+tOne[
"scient1"]*
pow(tOne[
"x"],2)-tOne[
"b"]*(-4.))
146 (
"(doub3-scient2)^2/c+(d/a)",
pow(tOne[
"doub3"]-tOne[
"scient2"],2)/tOne[
"c"]+tOne[
"d"]/tOne[
"a"])
147 (
"-(doub3-scient2)^2/c+(d/a)", -
pow(tOne[
"doub3"]-tOne[
"scient2"],2)/tOne[
"c"]+tOne[
"d"]/tOne[
"a"])
148 (
"-(doub3-scient2)^2+c+(d/a)", -
pow(tOne[
"doub3"]-tOne[
"scient2"],2)+tOne[
"c"]+tOne[
"d"]/tOne[
"a"])
149 (
"-(doub3-scient2)^2-c+(d/a)", -
pow(tOne[
"doub3"]-tOne[
"scient2"],2)-tOne[
"c"]+tOne[
"d"]/tOne[
"a"])
150 (
"c-(doub3-scient2)^2-c+(d/a)", tOne[
"c"]-
pow(tOne[
"doub3"]-tOne[
"scient2"],2)-tOne[
"c"]+tOne[
"d"]/tOne[
"a"])
152 (
"b+c*x^2", tOne[
"b"]+tOne[
"c"]*
pow(tOne[
"x"],2))
153 (
"b+c*log10(x)", tOne[
"b"]+tOne[
"c"]*log10(tOne[
"x"]))
154 (
"b+c*exp(x)", tOne[
"b"]+tOne[
"c"]*exp(tOne[
"x"]))
155 (
"b+c*exp(-x)", tOne[
"b"]+tOne[
"c"]*exp(-tOne[
"x"]))
156 (
"b+c*log10(x+a*exp(x)+b*x^(2-a))", tOne[
"b"]+tOne[
"c"]*log10(tOne[
"x"]+tOne[
"a"]*exp(tOne[
"x"])+tOne[
"b"]*
pow(tOne[
"x"],2-tOne[
"a"])))
157 (
"b+log(x+5)", tOne[
"b"]+log(tOne[
"x"]+5))
158 (
"b+sin(x+5)", tOne[
"b"]+sin(tOne[
"x"]+5))
159 (
"b+cos(x+5)", tOne[
"b"]+cos(tOne[
"x"]+5))
160 (
"b+tan(x+5)", tOne[
"b"]+tan(tOne[
"x"]+5))
165 for (map<string, double>::const_iterator it = expressionValueOne.begin(), end = expressionValueOne.end();
173 tTwo[
"Xmax"] = 500*
g/
cm2;
175 const map<string, double> expressionValueTwo =
177 (
"(Xmax-400*g/cm2)+20*g/cm2", (tTwo[
"Xmax"]-400*
g/
cm2)+20*
g/
cm2)
178 (
"Xmax/(100*g/cm2)-0.5", tTwo[
"Xmax"]/(100*
g/
cm2)-0.5)
179 (
"-Xmax/(100*g/cm2)+10.5", -tTwo[
"Xmax"]/(100*
g/
cm2)+10.5)
180 (
"exp(-Xmax/(100*g/cm2)+10.5)", exp(-tTwo[
"Xmax"]/(100*
g/
cm2)+10.5));
184 for (map<string, double>::const_iterator it = expressionValueTwo.begin(), end = expressionValueTwo.end();
void SetVerbosity(const EVerbosity verbosity)
Set the verbosity level.
double pow(const double x, const unsigned int i)
CPPUNIT_TEST_SUITE_REGISTRATION(testAiresShowerFile)
#define ASSERT_CLOSE(x, y)
static utl::SymbolTable fgUnitMap
std::map< std::string, double > SymbolTable
static const utl::SymbolTable & GetSymbolMap()
static ErrorLogger & GetInstance()
static void SetSymbols(const utl::SymbolTable &s)