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 );
53 cout << myname <<
"Formula: " << rpf.formulaString() <<
endl;
54 assert( rpf.formulaString() == sform );
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 );
71 assert( rpf.unsetPars().size() == 2 );
72 assert( rpf.resetPars().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;
84 assert( rpf.unsetPars().size() == 2 );
85 assert( rpf.resetPars().size() == 0 );
86 assert( ! rpf.ready() );
87 rpf.setParValue(
"offset", 10.0);
88 assert( rpf.unsetPars().size() == 1 );
89 assert( rpf.resetPars().size() == 0 );
90 assert( ! rpf.ready() );
91 rpf.setParValue(
"scale", 3.0);
92 assert( rpf.unsetPars().size() == 0 );
93 assert( rpf.resetPars().size() == 0 );
94 assert( rpf.ready() );
95 rpf.setParValue(
"scale", 2.0);
96 assert( rpf.unsetPars().size() == 0 );
97 assert( rpf.resetPars().size() == 1 );
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;
115 double def = rpf.defaultEval();
117 assert( rpf.setDefaultEval(99.0) == 0 );
118 def = rpf.defaultEval();
121 cout << myname << line <<
endl;
122 cout << myname <<
"Reset pars." <<
endl;
123 assert( rpf.ready() );
125 assert( rpf.unsetParValues() == 0 );
126 assert( ! rpf.ready() );
128 rpf.setParValue(
"offset", 10.0);
129 assert( ! rpf.ready() );
130 rpf.setParValue(
"scale", 3.0);
131 assert( rpf.ready() );
134 cout << myname << line <<
endl;
135 cout << myname <<
"Done." <<
endl;
void line(double t, double *p, double &x, double &y, double &z)
QTextStream & endl(QTextStream &s)