Skip to content
Snippets Groups Projects
Commit 095cc396 authored by Xavier Valls Pla's avatar Xavier Valls Pla Committed by Guilherme Amadio
Browse files

Add test for TF1 constructors

parent d6cdaaa8
No related branches found
No related tags found
No related merge requests found
...@@ -321,7 +321,7 @@ public: ...@@ -321,7 +321,7 @@ public:
TF1(const char *name, std::function<T(const T *data, const Double_t *param)> &fcn, Double_t xmin = 0, Double_t xmax = 1, Int_t npar = 0, Int_t ndim = 1, EAddToList addToGlobList = EAddToList::kDefault): TF1(const char *name, std::function<T(const T *data, const Double_t *param)> &fcn, Double_t xmin = 0, Double_t xmax = 1, Int_t npar = 0, Int_t ndim = 1, EAddToList addToGlobList = EAddToList::kDefault):
TF1(EFType::kTemplScalar, name, xmin, xmax, npar, ndim, addToGlobList, new TF1Parameters(npar), new TF1FunctorPointerImpl<T>(fcn)) TF1(EFType::kTemplScalar, name, xmin, xmax, npar, ndim, addToGlobList, new TF1Parameters(npar), new TF1FunctorPointerImpl<T>(fcn))
{ {
fType = std::is_same<T, double>::value? TF1::EFType::kTemplScalar : TF1::EFType::kTemplVec; fType = std::is_same<T, double>::value ? TF1::EFType::kTemplScalar : TF1::EFType::kTemplVec;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
......
...@@ -8,6 +8,25 @@ ...@@ -8,6 +8,25 @@
using namespace std; using namespace std;
class MyClass {
public:
double operator()(double *x, double *p) { return *x + *p; };
};
class MyClassConst {
public:
double operator()(const double *x, const double *p) { return *x + *p; };
};
double func(const double *x, const double *p)
{
return *x + *p;
}
double functionConst(const double *x, const double *p)
{
return *x + *p;
}
Float_t delta = 0.00000000001; Float_t delta = 0.00000000001;
void coeffNamesGeneric(TString &formula, TObjArray *coeffNames) void coeffNamesGeneric(TString &formula, TObjArray *coeffNames)
...@@ -177,3 +196,26 @@ TEST(TF1, CopyClone) ...@@ -177,3 +196,26 @@ TEST(TF1, CopyClone)
{ {
test_copyClone(); test_copyClone();
} }
TEST(TF1, Constructors)
{
MyClass testObj, testObjConst;
double x = 1;
double p = 1;
std::function<double(const double *data, const double *param)> stdFunction = functionConst;
std::vector<TF1> vtf1;
vtf1.emplace_back(TF1("Functor", testObj, 0, 1, 0));
vtf1.emplace_back(TF1("FunctorConst", testObjConst, 0, 1, 0));
vtf1.emplace_back(TF1("FunctorPtr", &testObj, 0, 1, 0));
vtf1.emplace_back(TF1("FunctorConstPtr", &testObjConst, 0, 1, 0));
vtf1.emplace_back(TF1("function", func));
vtf1.emplace_back(TF1("functionConst", functionConst));
vtf1.emplace_back(TF1("lambda", [](double *x1, double *x2) { return *x1 + *x2; }));
vtf1.emplace_back(TF1("lambdaConst", [](double *x1, double *x2) { return *x1 + *x2; }));
vtf1.emplace_back(TF1("stdFunction", stdFunction));
for (auto tf1 : vtf1)
EXPECT_EQ(tf1(&x, &p), 2);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment