10 #include "../RootParFormula.h" 26 using DVec = std::vector<double>;
31 return fabs(x1-x2) < 1.e-4;
37 const string myname =
"test_RootParFormula: ";
38 cout << myname <<
"Starting test" <<
endl;
40 cout << myname <<
"NDEBUG must be off." <<
endl;
43 string line =
"-----------------------------";
46 cout << myname << line <<
endl;
47 cout << myname <<
"Create formula and check." <<
endl;
48 string snam =
"myform";
49 string sform =
"[offset] + [scale]*x";
51 cout << myname <<
"Name: " << rpf.
name() <<
endl;
52 assert( rpf.
name() == snam );
55 cout << myname <<
"# params: " << rpf.
npar() <<
endl;
56 assert( rpf.
npar() == 2 );
57 cout << myname <<
"Params: [";
59 for (
string nam : rpf.
pars() ) {
60 if ( first ) first =
false;
65 assert( rpf.
pars().size() == 2 );
66 assert( rpf.
pars()[0] ==
"offset" );
67 assert( rpf.
pars()[1] ==
"scale" );
68 cout << myname <<
"# vars: " << rpf.
nvar() <<
endl;
69 assert( rpf.
nvar() == 1 );
70 assert( rpf.
setPars().size() == 0 );
73 assert( rpf.
pars().size() == 2 );
74 assert( ! rpf.
ready() );
76 cout << myname << line <<
endl;
77 cout << myname <<
"Check par names" <<
endl;
78 assert( rpf.
isPar(
"offset") );
79 assert( rpf.
isPar(
"scale") );
80 assert( ! rpf.
isPar(
"nosuch") );
82 cout << myname << line <<
endl;
83 cout << myname <<
"Set parameters." <<
endl;
86 assert( ! rpf.
ready() );
90 assert( ! rpf.
ready() );
94 assert( rpf.
ready() );
98 assert( rpf.
ready() );
100 cout << myname << line <<
endl;
101 cout << myname <<
"Check eval." <<
endl;
102 DVec vals = { 0.0, 1.0, 2.0 };
103 DVec evcs = { 10.0, 12.0, 14.0 };
104 for (
Index ival=0; ival<vals.size(); ++ival ) {
105 double eval = rpf.
eval(vals[ival]);
106 cout << myname <<
" " << vals[ival] <<
": " << eval <<
endl;
108 DVec vars = { vals[ival] };
109 double eval2 = rpf.
eval(vars);
113 cout << myname << line <<
endl;
114 cout << myname <<
"Set default eval." <<
endl;
121 cout << myname << line <<
endl;
122 cout << myname <<
"Reset pars." <<
endl;
123 assert( rpf.
ready() );
126 assert( ! rpf.
ready() );
129 assert( ! rpf.
ready() );
131 assert( rpf.
ready() );
134 cout << myname << line <<
endl;
135 cout << myname <<
"Done." <<
endl;
Q_EXPORT QTSManip setw(int w)
void line(double t, double *p, double &x, double &y, double &z)
QTextStream & endl(QTextStream &s)