33#define PARSER_CONST_PI 3.141592653589793238462643
34#define PARSER_CONST_E 2.718281828459045235360287
71 if (a_szExpr[1]==0 || (a_szExpr[0]!=
'0' || a_szExpr[1]!=
'x') )
77 stringstream_type::pos_type nPos(0);
82 if (nPos==(stringstream_type::pos_type)0)
85 *a_iPos += (int)(2 + nPos);
128 mu::console() <<
_nrT(
"\n -> Funktionsfaehigkeit fehlgeschlagen mit ") << iStat <<
_nrT(
" Fehlern.") << endl;
140 iStat +=
EqnTest(
_nrT(
"valueof(\"\")"), 123,
true);
141 iStat +=
EqnTest(
_nrT(
"valueof(\"aaa\")+valueof(\"bbb\") "), 246,
true);
142 iStat +=
EqnTest(
_nrT(
"2*(valueof(\"aaa\")-23)+valueof(\"bbb\")"), 323,
true);
144 iStat +=
EqnTest(
_nrT(
"a*(atof(\"10\")-b)"), 8,
true);
145 iStat +=
EqnTest(
_nrT(
"a-(atof(\"10\")*b)"), -19,
true);
147 iStat +=
EqnTest(
_nrT(
"strfun1(\"100\")"), 100,
true);
148 iStat +=
EqnTest(
_nrT(
"strfun2(\"100\",1)"), 101,
true);
149 iStat +=
EqnTest(
_nrT(
"strfun3(\"99\",1,2)"), 102,
true);
154 mu::console() <<
_nrT(
"\n -> Zeichenkettenargumente fehlgeschlagen mit ") << iStat <<
_nrT(
" Fehlern.") << endl;
211 iStat +=
EqnTest(
_nrT(
"a = sin(b)"), 0.909297,
true);
212 iStat +=
EqnTest(
_nrT(
"a = 1+sin(b)"), 1.909297,
true);
221 iStat +=
EqnTest(
_nrT(
"3+4*2/(1-5)^2^3"), 3.0001220703125,
true);
295 mu::console() <<
_nrT(
"\n -> Binaere Operatoren fehlgeschlagen mit ") << iStat <<
_nrT(
" Fehlern.") << endl;
308 mu::console() <<
" -> Teste Namensbeschraenkungen ... ";
312 #define PARSER_THROWCHECK(DOMAIN, FAIL, EXPR, ARG) \
314 ParserTester::c_iCount++; \
317 p.Define##DOMAIN(EXPR, ARG); \
319 catch(Parser::exception_type&) \
321 iErr = (FAIL==false) ? 0 : 1; \
400 #undef PARSER_THROWCHECK
405 mu::console() <<
_nrT(
"\n -> Namensbeschraenkung fehlgeschlagen mit ") << iStat <<
_nrT(
" Fehlern.") << endl;
457 mu::console() <<
_nrT(
"\n -> Syntaxerkennung fehlgeschlagen mit ") << iStat <<
_nrT(
" Fehlern.") << endl;
467 mu::console() <<
_nrT(
" -> Teste Variablen-/Konstantenerkennung ... ");
515 int iCount = (int)UsedVar.size();
524 mu::varmap_type::const_iterator item = UsedVar.begin();
525 for (idx=0; item!=UsedVar.end(); ++item)
527 if (&vVarVal[idx++]!=item->second)
534 iCount = (int)UsedVar.size();
543 for (item = UsedVar.begin(); item!=UsedVar.end(); ++item)
552 iCount = (int)UsedVar.size();
553 if (iCount!=2)
throw false;
554 item = UsedVar.begin();
555 for (idx=0; item!=UsedVar.end(); ++item)
556 if (&vVarVal[idx++]!=item->second)
throw false;
567 mu::console() <<
_nrT(
"\n -> Variablen-/Konstantenerkennung fehlgeschlagen mit ") << iStat <<
_nrT(
" Fehlern.") << endl;
582 iStat +=
EqnTest(
_nrT(
"a=10,b=20,c=a*b"), 200,
true);
585 iStat +=
EqnTest(
_nrT(
"a=10,\nb=20,\nc=a*b"), 200,
true);
588 iStat +=
EqnTest(
_nrT(
"a=10,\r\nb=20,\r\nc=a*b"), 200,
true);
594 iStat +=
EqnTest(
_nrT(
"f1of3(1, 2, 3)"), 1,
true);
595 iStat +=
EqnTest(
_nrT(
"f2of3(1, 2, 3)"), 2,
true);
596 iStat +=
EqnTest(
_nrT(
"f3of3(1, 2, 3)"), 3,
true);
597 iStat +=
EqnTest(
_nrT(
"f1of4(1, 2, 3, 4)"), 1,
true);
598 iStat +=
EqnTest(
_nrT(
"f2of4(1, 2, 3, 4)"), 2,
true);
599 iStat +=
EqnTest(
_nrT(
"f3of4(1, 2, 3, 4)"), 3,
true);
600 iStat +=
EqnTest(
_nrT(
"f4of4(1, 2, 3, 4)"), 4,
true);
601 iStat +=
EqnTest(
_nrT(
"f1of5(1, 2, 3, 4, 5)"), 1,
true);
602 iStat +=
EqnTest(
_nrT(
"f2of5(1, 2, 3, 4, 5)"), 2,
true);
603 iStat +=
EqnTest(
_nrT(
"f3of5(1, 2, 3, 4, 5)"), 3,
true);
604 iStat +=
EqnTest(
_nrT(
"f4of5(1, 2, 3, 4, 5)"), 4,
true);
605 iStat +=
EqnTest(
_nrT(
"f5of5(1, 2, 3, 4, 5)"), 5,
true);
616 iStat +=
EqnTest(
_nrT(
"f1of2(1, 2, 3)"), 0,
false);
618 iStat +=
EqnTest(
_nrT(
"f1of3(1, 2, 3, 4)"), 0,
false);
620 iStat +=
EqnTest(
_nrT(
"f1of4(1, 2, 3, 4, 5)"), 0,
false);
631 iStat +=
EqnTest(
_nrT(
"firstArg(2,3,4)"), 2,
true);
632 iStat +=
EqnTest(
_nrT(
"lastArg(2,3,4)"), 4,
true);
635 iStat +=
EqnTest(
_nrT(
"max(3*a+1, 1)*2"), 8,
true);
636 iStat +=
EqnTest(
_nrT(
"2*max(3*a+1, 1)+2"), 10,
true);
642 iStat +=
EqnTest(
_nrT(
"sum(1,-max(1,2),3)*2"), 4,
true);
644 iStat +=
EqnTest(
_nrT(
"2*sum(1,2,3)+2"), 14,
true);
645 iStat +=
EqnTest(
_nrT(
"2*sum(-1,2,3)+2"), 10,
true);
646 iStat +=
EqnTest(
_nrT(
"2*sum(-1,2,-(-a))+2"), 6,
true);
647 iStat +=
EqnTest(
_nrT(
"2*sum(-1,10,-a)+2"), 18,
true);
648 iStat +=
EqnTest(
_nrT(
"2*sum(1,2,3)*2"), 24,
true);
649 iStat +=
EqnTest(
_nrT(
"sum(1,-max(1,2),3)*2"), 4,
true);
650 iStat +=
EqnTest(
_nrT(
"sum(1*3, 4, a+2)"), 10,
true);
651 iStat +=
EqnTest(
_nrT(
"sum(1*3, 2*sum(1,2,2), a+2)"), 16,
true);
652 iStat +=
EqnTest(
_nrT(
"sum(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2)"), 24,
true);
663 mu::console() <<
_nrT(
"\n -> Mehrfachausdruecke fehlgeschlagen mit ") << iStat <<
_nrT(
" Fehlern.") << endl;
674 mu::console() <<
" -> Teste Infix Operatoren ... ";
688 iStat +=
EqnTest(
_nrT(
"-(f1of1(1+2*3)+1*2)"), -9,
true);
689 iStat +=
EqnTest(
_nrT(
"-(-f1of1(1+2*3)+1*2)"), 5,
true);
690 iStat +=
EqnTest(
_nrT(
"-sin(8)"), -0.989358,
true);
729 mu::console() <<
_nrT(
"\n -> Infix-Operatoren fehlgeschlagen mit ") << iStat <<
_nrT(
" Fehlern.") << endl;
753 iStat +=
EqnTest(
_nrT(
"-f1of1(1000)m"), -1,
true);
754 iStat +=
EqnTest(
_nrT(
"-f1of1(-1000)m"), 1,
true);
755 iStat +=
EqnTest(
_nrT(
"f4of4(0,0,0,1000)m"), 1,
true);
759 iStat +=
EqnTest(
_nrT(
"2*3000meg+2"), 2*3e9+2,
true);
782 mu::console() <<
_nrT(
"\n -> Postfix-Operatoren fehlgeschlagen mit ") << iStat <<
_nrT(
" Fehlern.") << endl;
814 iStat +=
EqnTest(
_nrT(
"(2*b+1)*4"), (2*b+1)*4,
true);
815 iStat +=
EqnTest(
_nrT(
"4*(2*b+1)"), (2*b+1)*4,
true);
818 iStat +=
EqnTest(
_nrT(
"1+2-3*4/5^6"), 2.99923,
true);
819 iStat +=
EqnTest(
_nrT(
"1^2/3*4-5+6"), 2.33333333,
true);
830 iStat +=
EqnTest(
_nrT(
"1-(e^(ln(7)))"), -6,
true);
831 iStat +=
EqnTest(
_nrT(
"2*(e^(ln(7)))"), 14,
true);
836 iStat +=
EqnTest(
_nrT(
"-(2^1.1)"), -2.14354692,
true);
838 iStat +=
EqnTest(
_nrT(
"(cos(2.41)/b)"), -0.372056,
true);
839 iStat +=
EqnTest(
_nrT(
"(1*(2*(3*(4*(5*(6*(a+b)))))))"), 2160,
true);
840 iStat +=
EqnTest(
_nrT(
"(1*(2*(3*(4*(5*(6*(7*(a+b))))))))"), 15120,
true);
841 iStat +=
EqnTest(
_nrT(
"(a/((((b+(((e*(((((pi*((((3.45*((pi+a)+pi))+b)+b)*a))+0.68)+e)+a)/a))+a)+b))+b)*a)-pi))"), 0.00377999,
true);
845 _nrT(
"(((-9))-e/(((((((pi-(((-7)+(-3)/4/e))))/(((-5))-2)-((pi+(-0))*(sqrt((e+e))*(-8))*(((-pi)+(-pi)-(-9)*(6*5))")
846 _nrT(
"/(-e)-e))/2)/((((sqrt(2/(-e)+6)-(4-2))+((5/(-2))/(1*(-pi)+3))/8)*pi*((pi/((-2)/(-6)*1*(-1))*(-6)+(-e)))))/")
847 _nrT(
"((e+(-2)+(-e)*((((-3)*9+(-e)))+(-9)))))))-((((e-7+(((5/pi-(3/1+pi)))))/e)/(-5))/(sqrt((((((1+(-7))))+((((-")
848 _nrT(
"e)*(-e)))-8))*(-5)/((-e)))*(-6)-((((((-2)-(-9)-(-e)-1)/3))))/(sqrt((8+(e-((-6))+(9*(-9))))*(((3+2-8))*(7+6")
849 _nrT(
"+(-5))+((0/(-e)*(-pi))+7)))+(((((-e)/e/e)+((-6)*5)*e+(3+(-5)/pi))))+pi))/sqrt((((9))+((((pi))-8+2))+pi))/e")
850 _nrT(
"*4)*((-5)/(((-pi))*(sqrt(e)))))-(((((((-e)*(e)-pi))/4+(pi)*(-9)))))))+(-pi)"), -12.23016549,
true);
854 _nrT(
"(atan(sin((((((((((((((((pi/cos((a/((((0.53-b)-pi)*e)/b))))+2.51)+a)-0.54)/0.98)+b)*b)+e)/a)+b)+a)+b)+pi)/e")
855 _nrT(
")+a)))*2.77)"), -2.16995656,
true);
858 iStat +=
EqnTest(
_nrT(
"1+2-3*4/5^6*(2*(1-5+(3*7^9)*(4+6*7-3)))+12"), -7995810.09926,
true);
863 mu::console() <<
_nrT(
"\n Beispielausdruecke fehlgeschlagen mit ") << iStat <<
_nrT(
" Fehlern.") << endl;
889 iStat +=
EqnTest(
_nrT(
"1 ? 128 : 255"), 128,
true);
890 iStat +=
EqnTest(
_nrT(
"1<2 ? 128 : 255"), 128,
true);
891 iStat +=
EqnTest(
_nrT(
"a<b ? 128 : 255"), 128,
true);
892 iStat +=
EqnTest(
_nrT(
"(a<b) ? 128 : 255"), 128,
true);
895 iStat +=
EqnTest(
_nrT(
"(1) ? a+b : c+d"), 3,
true);
896 iStat +=
EqnTest(
_nrT(
"(0) ? a+b : c+d"), 1,
true);
899 iStat +=
EqnTest(
_nrT(
"(a<b) ? 10 : 11"), 10,
true);
900 iStat +=
EqnTest(
_nrT(
"(a>b) ? 10 : 11"), 11,
true);
905 iStat +=
EqnTest(
_nrT(
"((a>b) ? 1 : 0) ? 1 : 2"), 2,
true);
906 iStat +=
EqnTest(
_nrT(
"((a>b) ? 1 : 0) ? 1 : sum((a>b) ? 1 : 2)"), 2,
true);
907 iStat +=
EqnTest(
_nrT(
"((a>b) ? 0 : 1) ? 1 : sum((a>b) ? 1 : 2)"), 1,
true);
909 iStat +=
EqnTest(
_nrT(
"sum((a>b) ? 1 : 2)"), 2,
true);
910 iStat +=
EqnTest(
_nrT(
"sum((1) ? 1 : 2)"), 1,
true);
911 iStat +=
EqnTest(
_nrT(
"sum((a>b) ? 1 : 2, 100)"), 102,
true);
912 iStat +=
EqnTest(
_nrT(
"sum((1) ? 1 : 2, 100)"), 101,
true);
913 iStat +=
EqnTest(
_nrT(
"sum(3, (a>b) ? 3 : 10)"), 13,
true);
914 iStat +=
EqnTest(
_nrT(
"sum(3, (a<b) ? 3 : 10)"), 6,
true);
915 iStat +=
EqnTest(
_nrT(
"10*sum(3, (a>b) ? 3 : 10)"), 130,
true);
916 iStat +=
EqnTest(
_nrT(
"10*sum(3, (a<b) ? 3 : 10)"), 60,
true);
917 iStat +=
EqnTest(
_nrT(
"sum(3, (a>b) ? 3 : 10)*10"), 130,
true);
918 iStat +=
EqnTest(
_nrT(
"sum(3, (a<b) ? 3 : 10)*10"), 60,
true);
919 iStat +=
EqnTest(
_nrT(
"(a<b) ? sum(3, (a<b) ? 3 : 10)*10 : 99"), 60,
true);
920 iStat +=
EqnTest(
_nrT(
"(a>b) ? sum(3, (a<b) ? 3 : 10)*10 : 99"), 99,
true);
921 iStat +=
EqnTest(
_nrT(
"(a<b) ? sum(3, (a<b) ? 3 : 10,10,20)*10 : 99"), 360,
true);
922 iStat +=
EqnTest(
_nrT(
"(a>b) ? sum(3, (a<b) ? 3 : 10,10,20)*10 : 99"), 99,
true);
923 iStat +=
EqnTest(
_nrT(
"(a>b) ? sum(3, (a<b) ? 3 : 10,10,20)*10 : sum(3, (a<b) ? 3 : 10)*10"), 60,
true);
926 iStat +=
EqnTest(
_nrT(
"(a<b)&&(a<b) ? 128 : 255"), 128,
true);
927 iStat +=
EqnTest(
_nrT(
"(a>b)&&(a<b) ? 128 : 255"), 255,
true);
928 iStat +=
EqnTest(
_nrT(
"(1<2)&&(1<2) ? 128 : 255"), 128,
true);
929 iStat +=
EqnTest(
_nrT(
"(1>2)&&(1<2) ? 128 : 255"), 255,
true);
930 iStat +=
EqnTest(
_nrT(
"((1<2)&&(1<2)) ? 128 : 255"), 128,
true);
931 iStat +=
EqnTest(
_nrT(
"((1>2)&&(1<2)) ? 128 : 255"), 255,
true);
932 iStat +=
EqnTest(
_nrT(
"((a<b)&&(a<b)) ? 128 : 255"), 128,
true);
933 iStat +=
EqnTest(
_nrT(
"((a>b)&&(a<b)) ? 128 : 255"), 255,
true);
935 iStat +=
EqnTest(
_nrT(
"1>0 ? 1>2 ? 128 : 255 : 1>0 ? 32 : 64"), 255,
true);
936 iStat +=
EqnTest(
_nrT(
"1>0 ? 1>2 ? 128 : 255 :(1>0 ? 32 : 64)"), 255,
true);
937 iStat +=
EqnTest(
_nrT(
"1>0 ? 1>0 ? 128 : 255 : 1>2 ? 32 : 64"), 128,
true);
938 iStat +=
EqnTest(
_nrT(
"1>0 ? 1>0 ? 128 : 255 :(1>2 ? 32 : 64)"), 128,
true);
939 iStat +=
EqnTest(
_nrT(
"1>2 ? 1>2 ? 128 : 255 : 1>0 ? 32 : 64"), 32,
true);
940 iStat +=
EqnTest(
_nrT(
"1>2 ? 1>0 ? 128 : 255 : 1>2 ? 32 : 64"), 64,
true);
941 iStat +=
EqnTest(
_nrT(
"1>0 ? 50 : 1>0 ? 128 : 255"), 50,
true);
942 iStat +=
EqnTest(
_nrT(
"1>0 ? 50 : (1>0 ? 128 : 255)"), 50,
true);
943 iStat +=
EqnTest(
_nrT(
"1>0 ? 1>0 ? 128 : 255 : 50"), 128,
true);
944 iStat +=
EqnTest(
_nrT(
"1>2 ? 1>2 ? 128 : 255 : 1>0 ? 32 : 1>2 ? 64 : 16"), 32,
true);
945 iStat +=
EqnTest(
_nrT(
"1>2 ? 1>2 ? 128 : 255 : 1>0 ? 32 :(1>2 ? 64 : 16)"), 32,
true);
946 iStat +=
EqnTest(
_nrT(
"1>0 ? 1>2 ? 128 : 255 : 1>0 ? 32 :1>2 ? 64 : 16"), 255,
true);
947 iStat +=
EqnTest(
_nrT(
"1>0 ? 1>2 ? 128 : 255 : (1>0 ? 32 :1>2 ? 64 : 16)"), 255,
true);
948 iStat +=
EqnTest(
_nrT(
"1 ? 0 ? 128 : 255 : 1 ? 32 : 64"), 255,
true);
951 iStat +=
EqnTest(
_nrT(
"a= 0 ? 128 : 255, a"), 255,
true);
952 iStat +=
EqnTest(
_nrT(
"a=((a>b)&&(a<b)) ? 128 : 255, a"), 255,
true);
953 iStat +=
EqnTest(
_nrT(
"c=(a<b)&&(a<b) ? 128 : 255, c"), 128,
true);
954 iStat +=
EqnTest(
_nrT(
"0 ? a=a+1 : 666, a"), 1,
true);
955 iStat +=
EqnTest(
_nrT(
"1?a=10:a=20, a"), 10,
true);
956 iStat +=
EqnTest(
_nrT(
"0?a=10:a=20, a"), 20,
true);
957 iStat +=
EqnTest(
_nrT(
"0?a=sum(3,4):10, a"), 1,
true);
959 iStat +=
EqnTest(
_nrT(
"a=1?b=1?3:4:5, a"), 3,
true);
960 iStat +=
EqnTest(
_nrT(
"a=1?b=1?3:4:5, b"), 3,
true);
961 iStat +=
EqnTest(
_nrT(
"a=0?b=1?3:4:5, a"), 5,
true);
962 iStat +=
EqnTest(
_nrT(
"a=0?b=1?3:4:5, b"), 2,
true);
964 iStat +=
EqnTest(
_nrT(
"a=1?5:b=1?3:4, a"), 5,
true);
965 iStat +=
EqnTest(
_nrT(
"a=1?5:b=1?3:4, b"), 2,
true);
966 iStat +=
EqnTest(
_nrT(
"a=0?5:b=1?3:4, a"), 3,
true);
967 iStat +=
EqnTest(
_nrT(
"a=0?5:b=1?3:4, b"), 3,
true);
972 mu::console() <<
_nrT(
"\n -> Wenn-Dann-Sonst fehlgeschlagen mit ") << iStat <<
_nrT(
" Fehlern.") << endl;
1012 iStat +=
ThrowTest(
_nrT(
"valueof(\"\\\"abc\\\"\")"), 999,
false);
1050 mu::console() <<
_nrT(
"\n -> Fehlercodes fehlgeschlagen mit ") << iStat <<
_nrT(
" Fehlern.") << endl;
1077 catch(std::exception &e)
1097 <<
" Ausdruecke)" << endl;
1129 if (a_bFail==
false || (a_bFail==
true && a_iErrc!=e.
GetCode()) )
1132 <<
_nrT(
"Expression: ") << a_str
1134 <<
_nrT(
" Expected:") << a_iErrc;
1137 return (a_iErrc==e.
GetCode()) ? 0 : 1;
1141 bool bRet((a_bFail==
false) ? 0 : 1);
1145 <<
_nrT(
"Expression: ") << a_str
1146 <<
_nrT(
" did evaluate; Expected error:") << a_iErrc;
1181 if ( fabs(a_fRes1-fVal[0]) > 0.0000000001)
1182 throw std::runtime_error(
"incorrect result (first pass)");
1184 if ( fabs(a_fRes2-fVal[1]) > 0.0000000001)
1185 throw std::runtime_error(
"incorrect result (second pass)");
1192 catch(std::exception &e)
1215 value_type fVal[5] = {-999, -998, -997, -996, -995};
1219 std::unique_ptr<Parser> p1;
1231 p1->DefineConst(
_nrT(
"const"), 1);
1232 p1->DefineConst(
_nrT(
"const1"), 2);
1233 p1->DefineConst(
_nrT(
"const2"), 3);
1236 p1->DefineVar(
_nrT(
"a"), &vVarVal[0]);
1237 p1->DefineVar(
_nrT(
"aa"), &vVarVal[1]);
1238 p1->DefineVar(
_nrT(
"b"), &vVarVal[1]);
1239 p1->DefineVar(
_nrT(
"c"), &vVarVal[2]);
1240 p1->DefineVar(
_nrT(
"d"), &vVarVal[3]);
1246 p1->DefineFun(
_nrT(
"ping"),
Ping);
1264 p1->DefineOprt(
_nrT(
"add"),
add, 0);
1265 p1->DefineOprt(
_nrT(
"++"),
add, 0);
1269 p1->DefineFun(
_nrT(
"min"),
Min);
1270 p1->DefineFun(
_nrT(
"max"),
Max);
1271 p1->DefineFun(
_nrT(
"sum"),
Sum);
1286 p1->DefineInfixOprt(
_nrT(
"~~"),
plus2);
1289 p1->DefinePostfixOprt(
_nrT(
"m"),
Milli);
1290 p1->DefinePostfixOprt(
_nrT(
"meg"),
Mega);
1292 p1->DefinePostfixOprt(
_nrT(
"'"),
sqr);
1297 fVal[0] = p1->Eval();
1298 fVal[1] = p1->Eval();
1299 if (fVal[0]!=fVal[1])
1307 std::vector<mu::Parser> vParser;
1308 vParser.push_back(*(p1.get()));
1315 fVal[2] = p2.
Eval();
1322 fVal[3] = p3.
Eval();
1328 fVal[4] = v[nNum-1];
1331 catch(std::exception &e)
1337 bool bCloseEnough(
true);
1338 for (
unsigned i=0; i<
sizeof(fVal)/
sizeof(
value_type); ++i)
1340 bCloseEnough &= (fabs(a_fRes-fVal[i]) <= fabs(fVal[i]*0.00001));
1345 if (numeric_limits<value_type>::has_infinity)
1346 bCloseEnough &= (fabs(fVal[i]) != numeric_limits<value_type>::infinity());
1349 iRet = ((bCloseEnough && a_fPass) || (!bCloseEnough && !a_fPass)) ? 0 : 1;
1355 <<
_nrT(
" (incorrect result; expected: ") << a_fRes
1356 <<
_nrT(
" ;calculated: ") << fVal[0] <<
_nrT(
",")
1357 << fVal[1] <<
_nrT(
",")
1358 << fVal[2] <<
_nrT(
",")
1359 << fVal[3] <<
_nrT(
",")
1360 << fVal[4] <<
_nrT(
").");
1367 if (fVal[0]!=fVal[2] && fVal[0]!=-999 && fVal[1]!=-998)
1374 catch(std::exception &e)
1410 if (fVal[0]!=fVal[1])
1413 iRet = ( (a_fRes==fVal[0] && a_fPass) ||
1414 (a_fRes!=fVal[0] && !a_fPass) ) ? 0 : 1;
1418 <<
_nrT(
" (incorrect result; expected: ") << a_fRes
1419 <<
_nrT(
" ;calculated: ") << fVal[0]<<
_nrT(
").");
1443 mu::console() <<
_nrT(
"Test failed (internal error in test class)") << endl;
void SetExpr(StringView a_sExpr)
Set the expression. Triggers first time calculation thus the creation of the bytecode and scanning of...
value_type Eval()
Single-value wrapper around the vectorized overload of this member function.
const varmap_type & GetVar() const
Return a map containing the used variables only.
void EnableOptimizer(bool a_bIsOn=true)
Enable or disable the formula optimization feature.
const varmap_type & GetUsedVar()
Return a map containing the used variables only.
void DefineVar(const string_type &a_sName, value_type *a_fVar)
Add a user defined variable.
void DefineConst(const string_type &a_sName, value_type a_fVal)
Add a user defined constant.
void RemoveVar(const string_type &a_strVarName)
Remove a variable from internal storage.
void DefinePostfixOprt(const string_type &a_strFun, fun_type1 a_pOprt, bool optimizeAway=true)
Add a user defined operator.
ParserError exception_type
Type of the error class.
void ClearPostfixOprt()
Clear all user defined postfix operators.
void ClearConst()
Clear all user defined constants.
void DefineFun(const string_type &a_strName, T a_pFun, bool optimizeAway=true)
Define a parser function without arguments.
void EnableBuiltInOprt(bool a_bIsOn=true)
Enable or disable the built in binary operators.
Error class of the parser.
EErrorCodes GetCode() const
Return the error code.
const string_type & GetMsg() const
Returns the message string for this error.
const string_type & GetExpr() const
gets the expression related tp this error.
const string_type & GetToken() const
Return string related with this token (if available).
Mathematical expressions parser.
Mathematical expressions parser.
static value_type f2of4(value_type, value_type v, value_type, value_type)
static value_type ValueOf(const char_type *)
static value_type Sum(const value_type *a_afArg, int a_iArgc)
static value_type f2of3(value_type, value_type v, value_type)
static value_type StrFun3(const char_type *v1, value_type v2, value_type v3)
std::vector< testfun_type > m_vTestFun
static value_type Mega(value_type a_fVal)
void Abort() const
Internal error in test class Test is going to be aborted.
static value_type Min(value_type a_fVal1, value_type a_fVal2)
int ThrowTest(const string_type &a_str, int a_iErrc, bool a_bFail=true)
int EqnTestInt(const string_type &a_str, double a_fRes, bool a_fPass)
static value_type add(value_type v1, value_type v2)
static value_type f4of5(value_type, value_type, value_type, value_type v, value_type)
static value_type f3of3(value_type, value_type, value_type v)
static value_type FirstArg(const value_type *a_afArg, int a_iArgc)
static value_type plus2(value_type v1)
static value_type land(value_type v1, value_type v2)
static value_type times3(value_type v1)
static value_type LastArg(const value_type *a_afArg, int a_iArgc)
static value_type f2of2(value_type, value_type v)
static value_type f4of4(value_type, value_type, value_type, value_type v)
static value_type Milli(value_type a_fVal)
static value_type f1of4(value_type v, value_type, value_type, value_type)
static value_type Max(value_type a_fVal1, value_type a_fVal2)
static value_type sign(value_type v)
void AddTest(testfun_type a_pFun)
int EqnTest(const string_type &a_str, double a_fRes, bool a_fPass)
Evaluate a tet expression.
static value_type f3of4(value_type, value_type, value_type v, value_type)
static value_type f2of5(value_type, value_type v, value_type, value_type, value_type)
int EqnTestWithVarChange(const string_type &a_str, double a_fRes1, double a_fVar1, double a_fRes2, double a_fVar2)
Evaluate a tet expression.
static value_type StrFun1(const char_type *v1)
int TestNames()
Check muParser name restriction enforcement.
static value_type f1of3(value_type v, value_type, value_type)
static value_type f1of1(value_type v)
static value_type f3of5(value_type, value_type, value_type v, value_type, value_type)
static value_type StrToFloat(const char_type *a_szMsg)
static value_type f5of5(value_type, value_type, value_type, value_type, value_type v)
static value_type f1of2(value_type v, value_type)
static value_type sqr(value_type v1)
static value_type f1of5(value_type v, value_type, value_type, value_type, value_type)
static value_type StrFun2(const char_type *v1, value_type v2)
static int IsHexVal(const char_type *a_szExpr, int *a_iPos, value_type *a_fVal)
#define _nrT(x)
Activate this option in order to compile with OpenMP support.
#define PARSER_THROWCHECK(DOMAIN, FAIL, EXPR, ARG)
This file contains the parser test class.
Namespace for mathematical applications.
MUP_BASETYPE value_type
The numeric datatype used by the parser.
string_type::value_type char_type
The character type used by the parser.
std::basic_stringstream< char_type, std::char_traits< char_type >, std::allocator< char_type > > stringstream_type
Typedef for easily using stringstream that respect the parser stringtype.
std::map< string_type, value_type * > varmap_type
Type used for storing variables.
std::ostream & console()
Encapsulate cout.
@ ecUNASSIGNABLE_TOKEN
Token cant be identified.
@ ecMISSING_PARENS
Missing parens. (Example: "3*sin(3")
@ ecUNEXPECTED_EOF
Unexpected end of formula. (Example: "2+sin(")
@ ecSTRING_EXPECTED
A string function has been called with a different type of argument.
@ ecTOO_MANY_PARAMS
Too many function parameters.
@ ecVAL_EXPECTED
A numerical function has been called with a non value type of argument.
@ ecUNEXPECTED_FUN
Unexpected function found. (Example: "sin(8)cos(9)")
@ ecSTR_RESULT
result is a string
@ ecUNEXPECTED_OPERATOR
Unexpected binary operator found.
@ ecOPRT_TYPE_CONFLICT
binary operators may only be applied to value items of the same type
@ ecUNEXPECTED_PARENS
Unexpected Parenthesis, opening or closing.
@ ecUNTERMINATED_STRING
unterminated string constant. (Example: "3*valueof("hello)")
@ ecUNEXPECTED_CONDITIONAL
@ ecTOO_FEW_PARAMS
Too few function parameters. (Example: "ite(1<2,2)")
@ ecUNEXPECTED_VAL
An unexpected value token has been found.
std::string string_type
The stringtype used by the parser.
@ prPOW
power operator priority (highest)