Skip to content
Snippets Groups Projects
Commit 5bbf5503 authored by Pospelov, Gennady's avatar Pospelov, Gennady
Browse files

Form factor numeric tests switched to new machinery

parent afbbe2c1
No related branches found
No related tags found
No related merge requests found
...@@ -32,4 +32,3 @@ ADD_GTEST(Core "DataStructure" ${libs} 0) ...@@ -32,4 +32,3 @@ ADD_GTEST(Core "DataStructure" ${libs} 0)
ADD_GTEST(Core "Other" ${libs} 0) ADD_GTEST(Core "Other" ${libs} 0)
ADD_GTEST(Core "Numeric0" ${libs} 1) ADD_GTEST(Core "Numeric0" ${libs} 1)
ADD_GTEST(Core "Numeric1" ${libs} 1) ADD_GTEST(Core "Numeric1" ${libs} 1)
ADD_GTEST(Core "Numeric2" ${libs} 0)
#include "google_test.h" #include "google_test.h"
#include "MathConstants.h" #include "FormFactorTest.h"
#include "BornAgainNamespace.h"
#include "HardParticles.h"
#include "qLoopedTest.h"
class FFSpecializationTest : public QLoopedTest class FFSpecializationTest : public FormFactorTest
{ {
public: protected:
void test_ff_eq(IFormFactorBorn* p0, IFormFactorBorn* p1, double eps=1e-12) { ~FFSpecializationTest();
complex_t f0 = p0->evaluate_for_q(q);
complex_t f1 = p1->evaluate_for_q(q); void run_test(IFormFactorBorn* p0, IFormFactorBorn* p1, double eps, double qmag1, double qmag2)
{
test_all(qmag1, qmag2, [&](){test_ff_eq(p0, p1, eps);});
}
void test_ff_eq(IFormFactorBorn* p0, IFormFactorBorn* p1, double eps) {
complex_t f0 = p0->evaluate_for_q(m_q);
complex_t f1 = p1->evaluate_for_q(m_q);
double avge = (std::abs(f0) + std::abs(f1))/2; double avge = (std::abs(f0) + std::abs(f1))/2;
//std::cout<<"q="<<q<<" -> "<<std::setprecision(16)<<" f0="<<f0<<", f1="<<f1<<"\n";
EXPECT_NEAR( real(f0), real(f1), eps*avge ); EXPECT_NEAR( real(f0), real(f1), eps*avge );
EXPECT_NEAR( imag(f0), imag(f1), eps*avge ); EXPECT_NEAR( imag(f0), imag(f1), eps*avge );
} }
~FFSpecializationTest();
static double eps_polyh;
}; };
FFSpecializationTest::~FFSpecializationTest() = default; FFSpecializationTest::~FFSpecializationTest() = default;
double FFSpecializationTest::eps_polyh = 7.5e-13;
INSTANTIATE_TEST_CASE_P( TEST_F(FFSpecializationTest, TruncatedCubeAsBox)
FFSpecializationTests,
FFSpecializationTest,
qlist);
//*********** polyhedra ***************
double eps_polyh = 7.5e-13;
TEST_P(FFSpecializationTest, TruncatedCubeAsBox)
{ {
if (skip_q(1e-99, 5e2)) const double L = .5;
return;
double L = .5;
FormFactorTruncatedCube p0(L, 0); FormFactorTruncatedCube p0(L, 0);
FormFactorBox p1(L, L, L); FormFactorBox p1(L, L, L);
test_ff_eq(&p0, &p1, eps_polyh); run_test(&p0, &p1, eps_polyh, 1e-99, 5e2);
} }
TEST_P(FFSpecializationTest, AnisoPyramidAsPyramid) TEST_F(FFSpecializationTest, AnisoPyramidAsPyramid)
{ {
if (skip_q(1e-99, 5e3)) const double L = 1.5, H = .24, alpha = .6;
return;
double L = 1.5, H = .24, alpha = .6;
FormFactorAnisoPyramid p0(L, L, H, alpha); FormFactorAnisoPyramid p0(L, L, H, alpha);
FormFactorPyramid p1(L, H, alpha); FormFactorPyramid p1(L, H, alpha);
test_ff_eq(&p0, &p1, eps_polyh); run_test(&p0, &p1, eps_polyh, 1e-99, 5e3);
} }
TEST_P(FFSpecializationTest, Pyramid3AsPrism) TEST_F(FFSpecializationTest, Pyramid3AsPrism)
{ {
if (skip_q(1e-99, 5e3)) const double L = 1.8, H = .3;
return;
double L = 1.8, H = .3;
FormFactorTetrahedron p0(L, H, M_PI / 2); FormFactorTetrahedron p0(L, H, M_PI / 2);
FormFactorPrism3 p1(L, H); FormFactorPrism3 p1(L, H);
test_ff_eq(&p0, &p1, eps_polyh); run_test(&p0, &p1, eps_polyh, 1e-99, 5e3);
} }
TEST_P(FFSpecializationTest, PyramidAsBox) TEST_F(FFSpecializationTest, PyramidAsBox)
{ {
if (skip_q(1e-99, 5e2)) const double L = 1.8, H = .3;
return;
double L = 1.8, H = .3;
FormFactorPyramid p0(L, H, M_PI / 2); FormFactorPyramid p0(L, H, M_PI / 2);
FormFactorBox p1(L, L, H); FormFactorBox p1(L, L, H);
test_ff_eq(&p0, &p1, eps_polyh); run_test(&p0, &p1, eps_polyh, 1e-99, 5e2);
} }
TEST_P(FFSpecializationTest, Cone6AsPrism) TEST_F(FFSpecializationTest, Cone6AsPrism)
{ {
if (skip_q(1e-99, 5e2)) const double L = .8, H = 1.13;
return;
double L = .8, H = 1.13;
FormFactorCone6 p0(L, H, M_PI / 2); FormFactorCone6 p0(L, H, M_PI / 2);
FormFactorPrism6 p1(L, H); FormFactorPrism6 p1(L, H);
test_ff_eq(&p0, &p1, eps_polyh); run_test(&p0, &p1, eps_polyh, 1e-99, 5e2);
} }
//*********** spheroids *************** //*********** spheroids ***************
TEST_P(FFSpecializationTest, HemiEllipsoidAsTruncatedSphere) TEST_F(FFSpecializationTest, HemiEllipsoidAsTruncatedSphere)
{ {
if (skip_q(1e-99, 5e2)) const double R = 1.07;
return;
double R = 1.07;
FormFactorHemiEllipsoid p0(R, R, R); FormFactorHemiEllipsoid p0(R, R, R);
FormFactorTruncatedSphere p1(R, R); FormFactorTruncatedSphere p1(R, R);
test_ff_eq(&p0, &p1, 1e-10); run_test(&p0, &p1, 1e-10, 1e-99, 5e2);
} }
TEST_P(FFSpecializationTest, EllipsoidalCylinderAsCylinder) TEST_F(FFSpecializationTest, EllipsoidalCylinderAsCylinder)
{ {
if (skip_q(1e-99, 5e3)) const double R = .8, H = 1.2;
return;
double R = .8, H = 1.2;
FormFactorEllipsoidalCylinder p0(R, R, H); FormFactorEllipsoidalCylinder p0(R, R, H);
FormFactorCylinder p1(R, H); FormFactorCylinder p1(R, H);
test_ff_eq(&p0, &p1, 1e-11); run_test(&p0, &p1, 1e-11, 1e-99, 5e3);
} }
TEST_P(FFSpecializationTest, TruncatedSphereAsSphere) TEST_F(FFSpecializationTest, TruncatedSphereAsSphere)
{ {
if (skip_q(.02, 5e1)) // WAITING #1416 improve/replace numeric integration const double R = 1.;
return;
double R = 1.;
FormFactorTruncatedSphere p0(R, 2 * R); FormFactorTruncatedSphere p0(R, 2 * R);
FormFactorFullSphere p1(R); FormFactorFullSphere p1(R);
test_ff_eq(&p0, &p1); run_test(&p0, &p1, 1e-12, .02, 5e1);
} }
#include "google_test.h"
#include "FormFactorTest.h"
class FFSpecializationTest2 : public FormFactorTest
{
protected:
~FFSpecializationTest2();
void run_test(IFormFactorBorn* p0, IFormFactorBorn* p1, double eps, double qmag1, double qmag2)
{
test_all(qmag1, qmag2, [&](){test_ff_eq(p0, p1, eps);});
}
void test_ff_eq(IFormFactorBorn* p0, IFormFactorBorn* p1, double eps) {
complex_t f0 = p0->evaluate_for_q(m_q);
complex_t f1 = p1->evaluate_for_q(m_q);
double avge = (std::abs(f0) + std::abs(f1))/2;
EXPECT_NEAR( real(f0), real(f1), eps*avge );
EXPECT_NEAR( imag(f0), imag(f1), eps*avge );
}
static double eps_polyh;
};
FFSpecializationTest2::~FFSpecializationTest2() = default;
double FFSpecializationTest2::eps_polyh = 7.5e-13;
TEST_F(FFSpecializationTest2, TruncatedCubeAsBox)
{
const double L = .5;
FormFactorTruncatedCube p0(L, 0);
FormFactorBox p1(L, L, L);
run_test(&p0, &p1, eps_polyh, 1e-99, 5e2);
}
TEST_F(FFSpecializationTest2, AnisoPyramidAsPyramid)
{
const double L = 1.5, H = .24, alpha = .6;
FormFactorAnisoPyramid p0(L, L, H, alpha);
FormFactorPyramid p1(L, H, alpha);
run_test(&p0, &p1, eps_polyh, 1e-99, 5e3);
}
TEST_F(FFSpecializationTest2, Pyramid3AsPrism)
{
const double L = 1.8, H = .3;
FormFactorTetrahedron p0(L, H, M_PI / 2);
FormFactorPrism3 p1(L, H);
run_test(&p0, &p1, eps_polyh, 1e-99, 5e3);
}
TEST_F(FFSpecializationTest2, PyramidAsBox)
{
const double L = 1.8, H = .3;
FormFactorPyramid p0(L, H, M_PI / 2);
FormFactorBox p1(L, L, H);
run_test(&p0, &p1, eps_polyh, 1e-99, 5e2);
}
TEST_F(FFSpecializationTest2, Cone6AsPrism)
{
const double L = .8, H = 1.13;
FormFactorCone6 p0(L, H, M_PI / 2);
FormFactorPrism6 p1(L, H);
run_test(&p0, &p1, eps_polyh, 1e-99, 5e2);
}
//*********** spheroids ***************
TEST_F(FFSpecializationTest2, HemiEllipsoidAsTruncatedSphere)
{
const double R = 1.07;
FormFactorHemiEllipsoid p0(R, R, R);
FormFactorTruncatedSphere p1(R, R);
run_test(&p0, &p1, 1e-10, 1e-99, 5e2);
}
TEST_F(FFSpecializationTest2, EllipsoidalCylinderAsCylinder)
{
const double R = .8, H = 1.2;
FormFactorEllipsoidalCylinder p0(R, R, H);
FormFactorCylinder p1(R, H);
run_test(&p0, &p1, 1e-11, 1e-99, 5e3);
}
TEST_F(FFSpecializationTest2, TruncatedSphereAsSphere)
{
const double R = 1.;
FormFactorTruncatedSphere p0(R, 2 * R);
FormFactorFullSphere p1(R);
run_test(&p0, &p1, 1e-12, .02, 5e1);
}
// To renew this file, run /G/ba/dev-tools/code-tools/update-gtestlist.py <directory> // To renew this file, run /G/ba/dev-tools/code-tools/update-gtestlist.py <directory>
//#include "FormFactorSpecializationTest.h" #include "FormFactorSpecializationTest.h"
#include "FormFactorSpecializationTest2.h"
#include "google_test.h" #include "google_test.h"
#include "FormFactorTest.h"
#include "MathConstants.h" #include "MathConstants.h"
#include "BornAgainNamespace.h" #include <functional>
#include "HardParticles.h"
#include "qLoopedTest.h"
class FFSymmetryTest : public QLoopedTest class FFSymmetryTest : public FormFactorTest
{ {
public: public:
~FFSymmetryTest(); ~FFSymmetryTest();
void test_qq_eq( IFormFactorBorn* p, cvector_t q0, cvector_t q1, double eps=1e-12 ) {
using transform_t = std::function<cvector_t(const cvector_t&)>;
std::cout
<< q0.x().real() << " " void run_test(IFormFactorBorn* p, transform_t fun, double eps, double qmag1, double qmag2)
<< q0.x().imag() << " " {
<< q0.y().real() << " " test_all(qmag1, qmag2, [&](){test_qq_eq(p, fun, eps);});
<< q0.y().imag() << " " }
<< q0.z().real() << " "
<< q0.z().imag() << " " void test_qq_eq( IFormFactorBorn* p, transform_t fun, double eps=1e-12 ) {
<< q1.x().real() << " " complex_t f0 = p->evaluate_for_q(m_q);
<< q1.x().imag() << " " complex_t f1 = p->evaluate_for_q(fun(m_q));
<< q1.y().real() << " "
<< q1.y().imag() << " "
<< q1.z().real() << " "
<< q1.z().imag() << " "
<< std::endl;
complex_t f0 = p->evaluate_for_q(q0);
complex_t f1 = p->evaluate_for_q(q1);
double avge = (std::abs(f0) + std::abs(f1))/2; double avge = (std::abs(f0) + std::abs(f1))/2;
EXPECT_NEAR( real(f0), real(f1), eps*avge ); EXPECT_NEAR( real(f0), real(f1), eps*avge );
EXPECT_NEAR( imag(f0), imag(f1), eps*avge ); EXPECT_NEAR( imag(f0), imag(f1), eps*avge );
} }
cvector_t qt;
}; };
FFSymmetryTest::~FFSymmetryTest() = default; FFSymmetryTest::~FFSymmetryTest() = default;
INSTANTIATE_TEST_CASE_P(
FFSymmetryTests,
FFSymmetryTest,
qlist);
//*********** polyhedra *************** //*********** polyhedra ***************
//TEST_P(FFSymmetryTest, Prism3) TEST_F(FFSymmetryTest, Prism3)
//{ {
// if (skip_q(1e-99, 2e2)) FormFactorPrism3 p(.83, .45);
// return; run_test(&p, [](const cvector_t& q)->cvector_t{return q.rotatedZ(M_TWOPI / 3);},
// FormFactorPrism3 p(.83, .45); 1e-12, 1e-99, 2e2);
// test_qq_eq(&p, q, q.rotatedZ(M_TWOPI / 3)); }
//}
TEST_F(FFSymmetryTest, Prism6)
//TEST_P(FFSymmetryTest, Prism6) {
//{ FormFactorPrism6 p(1.33, .42);
// if (skip_q(1e-99, 2e3)) run_test(&p, [](const cvector_t& q)->cvector_t{return q.rotatedZ(M_PI / 3);},
// return; 1e-12, 1e-99, 2e3);
// FormFactorPrism6 p(1.33, .42); run_test(&p, [](const cvector_t& q)->cvector_t{return q.rotatedZ(-M_TWOPI / 3);},
// test_qq_eq(&p, q, q.rotatedZ(M_PI / 3), 1e-12); 3.8e-12, 1e-99, 2e3);
// test_qq_eq(&p, q, q.rotatedZ(-M_TWOPI / 3), 3.8e-12); }
//}
TEST_F(FFSymmetryTest, Tetrahedron)
//TEST_P(FFSymmetryTest, Tetrahedron) {
//{ FormFactorTetrahedron p(8.43, .25, .53);
// if (skip_q(1e-99, 2e2)) run_test(&p, [](const cvector_t& q)->cvector_t{return q.rotatedZ(M_TWOPI / 3);},
// return; 6e-12, 1e-99, 2e2);
// FormFactorTetrahedron p(8.43, .25, .53); // Linux: 3e-12, relaxed for Mac
// test_qq_eq(&p, q, q.rotatedZ(M_TWOPI / 3), 6e-12); }
// // Linux: 3e-12, relaxed for Mac
//} TEST_F(FFSymmetryTest, Cone6_flat)
{
//TEST_P(FFSymmetryTest, Cone6_flat) // TODO for larger q, imag(ff) is nan
//{ FormFactorCone6 p(4.3, .09, .1);
// if (skip_q(1e-99, 2e2)) // TODO for larger q, imag(ff) is nan run_test(&p, [](const cvector_t& q)->cvector_t{return q.rotatedZ(-M_PI / 3);},
// return; 3.8e-12, 1e-99, 2e2);
// FormFactorCone6 p(4.3, .09, .1); }
// test_qq_eq(&p, q, q.rotatedZ(-M_PI / 3), 3.8e-12);
//} TEST_F(FFSymmetryTest, Cone6_steep)
{
//TEST_P(FFSymmetryTest, Cone6_steep) FormFactorCone6 p(.23, 3.5, .999 * M_PI / 2);
//{ run_test(&p, [](const cvector_t& q)->cvector_t{return q.rotatedZ(-M_PI / 3);},
// if (skip_q(1e-99, 2e2)) // TODO for larger q, imag(ff) is nan 2.5e-12, 1e-99, 2e2);
// return; }
// FormFactorCone6 p(.23, 3.5, .999 * M_PI / 2);
// test_qq_eq(&p, q, q.rotatedZ(-M_PI / 3), 2.5e-12);
//}
//*********** spheroids *************** //*********** spheroids ***************
TEST_P(FFSymmetryTest, HemiEllipsoid) TEST_F(FFSymmetryTest, HemiEllipsoid)
{ {
if (skip_q(1e-99, 2e2))
return;
FormFactorHemiEllipsoid p(.53, .78, 1.3); FormFactorHemiEllipsoid p(.53, .78, 1.3);
test_qq_eq(&p, q, cvector_t(-q.x(), q.y(), q.z())); run_test(&p, [](const cvector_t& q)->cvector_t{return cvector_t(-q.x(), q.y(), q.z());},
test_qq_eq(&p, q, cvector_t(q.x(), -q.y(), q.z())); 1e-12, 1e-99, 2e2);
run_test(&p, [](const cvector_t& q)->cvector_t{return cvector_t(q.x(), -q.y(), q.z());},
1e-12, 1e-99, 2e2);
} }
//TEST_P(FFSymmetryTest, TruncatedSphere) TEST_F(FFSymmetryTest, TruncatedSphere)
//{ {
// if (skip_q(1e-99, 2e2)) FormFactorTruncatedSphere p(.79, .34);
// return; run_test(&p, [](const cvector_t& q)->cvector_t{return q.rotatedZ(M_PI / 3.13698);},
// FormFactorTruncatedSphere p(.79, .34); 1e-10, 1e-99, 2e2);
// test_qq_eq(&p, q, q.rotatedZ(M_PI / 3.13698), 1e-10); }
//}
// ****** TODO: tests that do not pass for the full q range ********* // ****** TODO: tests that do not pass for the full q range *********
#include "google_test.h"
#include "FormFactorTest.h"
#include "MathConstants.h"
#include <functional>
class FFSymmetryTest2 : public FormFactorTest
{
public:
~FFSymmetryTest2();
using transform_t = std::function<cvector_t(const cvector_t&)>;
void run_test(IFormFactorBorn* p, transform_t fun, double eps, double qmag1, double qmag2)
{
test_all(qmag1, qmag2, [&](){test_qq_eq(p, fun, eps);});
}
void test_qq_eq( IFormFactorBorn* p, transform_t fun, double eps=1e-12 ) {
complex_t f0 = p->evaluate_for_q(m_q);
complex_t f1 = p->evaluate_for_q(fun(m_q));
double avge = (std::abs(f0) + std::abs(f1))/2;
EXPECT_NEAR( real(f0), real(f1), eps*avge );
EXPECT_NEAR( imag(f0), imag(f1), eps*avge );
}
};
FFSymmetryTest2::~FFSymmetryTest2() = default;
//*********** polyhedra ***************
TEST_F(FFSymmetryTest2, Prism3)
{
FormFactorPrism3 p(.83, .45);
run_test(&p, [](const cvector_t& q)->cvector_t{return q.rotatedZ(M_TWOPI / 3);},
1e-12, 1e-99, 2e2);
}
TEST_F(FFSymmetryTest2, Prism6)
{
FormFactorPrism6 p(1.33, .42);
run_test(&p, [](const cvector_t& q)->cvector_t{return q.rotatedZ(M_PI / 3);},
1e-12, 1e-99, 2e3);
run_test(&p, [](const cvector_t& q)->cvector_t{return q.rotatedZ(-M_TWOPI / 3);},
3.8e-12, 1e-99, 2e3);
}
TEST_F(FFSymmetryTest2, Tetrahedron)
{
FormFactorTetrahedron p(8.43, .25, .53);
run_test(&p, [](const cvector_t& q)->cvector_t{return q.rotatedZ(M_TWOPI / 3);},
6e-12, 1e-99, 2e2);
// Linux: 3e-12, relaxed for Mac
}
TEST_F(FFSymmetryTest2, Cone6_flat)
{
// TODO for larger q, imag(ff) is nan
FormFactorCone6 p(4.3, .09, .1);
run_test(&p, [](const cvector_t& q)->cvector_t{return q.rotatedZ(-M_PI / 3);},
3.8e-12, 1e-99, 2e2);
}
TEST_F(FFSymmetryTest2, Cone6_steep)
{
FormFactorCone6 p(.23, 3.5, .999 * M_PI / 2);
run_test(&p, [](const cvector_t& q)->cvector_t{return q.rotatedZ(-M_PI / 3);},
2.5e-12, 1e-99, 2e2);
}
//*********** spheroids ***************
TEST_F(FFSymmetryTest2, HemiEllipsoid)
{
FormFactorHemiEllipsoid p(.53, .78, 1.3);
run_test(&p, [](const cvector_t& q)->cvector_t{return cvector_t(-q.x(), q.y(), q.z());},
1e-12, 1e-99, 2e2);
run_test(&p, [](const cvector_t& q)->cvector_t{return cvector_t(q.x(), -q.y(), q.z());},
1e-12, 1e-99, 2e2);
}
TEST_F(FFSymmetryTest2, TruncatedSphere)
{
FormFactorTruncatedSphere p(.79, .34);
run_test(&p, [](const cvector_t& q)->cvector_t{return q.rotatedZ(M_PI / 3.13698);},
1e-10, 1e-99, 2e2);
}
// ****** TODO: tests that do not pass for the full q range *********
// To renew this file, run /G/ba/dev-tools/code-tools/update-gtestlist.py <directory> // To renew this file, run /G/ba/dev-tools/code-tools/update-gtestlist.py <directory>
//#include "FormFactorSymmetryTest.h" #include "FormFactorSymmetryTest.h"
#include "FormFactorSymmetryTest2.h"
#include "google_test.h"
#include "Vectors3D.h"
#include "Complex.h"
#include "gtest/internal/gtest-param-util.h"
#include "HardParticles.h"
const complex_t I(0,1);
double eps_polyh = 7.5e-13;
using ::testing::Values;
using ::testing::internal::ParamGenerator;
using ::testing::Combine;
auto qlist = testing::Combine(
testing::Values(
cvector_t({ 1, 0, 0 }),
cvector_t({ 0, 1, 0 }),
cvector_t({ 0, 0, 1 }),
cvector_t({ 1, 1, 0 }),
cvector_t({ 1, 0, 1 }),
cvector_t({ 1, 0, 1 }),
cvector_t({ 1, 1, 1 })
),
testing::Values(
cvector_t({ 1, 0, 0 }),
cvector_t({ 0, 1, 0 }),
cvector_t({ 0, 0, 1 }),
cvector_t({ 1, 1, 0 }),
cvector_t({ 1, 0, 1 }),
cvector_t({ 1, 0, 1 }),
cvector_t({ 1, 1, 1 })
),
testing::Values(
1e-19, 1e-17, 1e-15, 1e-13, 1e-11, 1e-9, 1e-7, 1e-5, 1e-4, 1e-3, 1e-2, .1,
1., 1e1, 1e2, 1e3, 1e4 ),
testing::Values(
-1e-15, +1e-14, -1e-13*I, +1e-12*I,
-1e-11, +1e-10, -1e-9*I, +1e-8*I,
-1e-7, +1e-6, -1e-5*I, +1e-4*I,
-1e-3, +1e-2, -1e-1*I, +1e-1*I,
.9, -.99, .999, -.9999 )
);
class SpecializationTest : public ::testing::Test
{
protected:
SpecializationTest() : gen(qlist) {}
~SpecializationTest();
void test_all(IFormFactorBorn* p0, IFormFactorBorn* p1, double eps=1e-12) {
for (auto it : gen) {
cvector_t qdir = std::get<0>(it);
cvector_t qdev = std::get<1>(it);
double qmag = std::get<2>(it);
complex_t qeps = std::get<3>(it);
m_q = qmag * (qdir + qeps*qdev).unit();
if (skip_q(1e-99, 5e2))
continue;
test_ff_eq(p0, p1, eps_polyh);
}
}
void test_ff_eq(IFormFactorBorn* p0, IFormFactorBorn* p1, double eps=1e-12) {
complex_t f0 = p0->evaluate_for_q(m_q);
complex_t f1 = p1->evaluate_for_q(m_q);
double avge = (std::abs(f0) + std::abs(f1))/2;
//std::cout<<"q="<<q<<" -> "<<std::setprecision(16)<<" f0="<<f0<<", f1="<<f1<<"\n";
EXPECT_NEAR( real(f0), real(f1), eps*avge );
EXPECT_NEAR( imag(f0), imag(f1), eps*avge );
}
bool skip_q( double qmag_begin=1e-99, double qmag_end=1e99 ) {
return m_q.mag()<=qmag_begin || m_q.mag()>=qmag_end;
}
cvector_t m_q;
ParamGenerator<std::tuple<cvector_t, cvector_t, double, complex_t>> gen;
};
SpecializationTest::~SpecializationTest() = default;
TEST_F(SpecializationTest, Start)
{
double L = 1.5, H = .24, alpha = .6;
FormFactorAnisoPyramid p0(L, L, H, alpha);
FormFactorPyramid p1(L, H, alpha);
test_all(&p0, &p1, eps_polyh);
}
// To renew this file, run /G/ba/dev-tools/code-tools/update-gtestlist.py <directory>
#include "SpecializationTest.h"
// ************************************************************************** //
//
// BornAgain: simulate and fit scattering at grazing incidence
//
//! @file Tests/UnitTests/utilities/qLoopedTest.h
//! @brief Auxiliary utility to loop over q vectors for tests.
//!
//! @homepage http://bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2016
//! @authors Scientific Computing Group at MLZ Garching
//! @authors M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke
//
// ************************************************************************** //
#ifndef QLOOPEDTEST_H
#define QLOOPEDTEST_H
#include <tuple>
const complex_t I(0,1);
class QLoopedTest:
public ::testing::TestWithParam<std::tuple<cvector_t, cvector_t, double, complex_t>>
{
protected:
QLoopedTest() {}
virtual void SetUp()
{
cvector_t qdir = std::get<0>(GetParam());
cvector_t qdev = std::get<1>(GetParam());
double qmag = std::get<2>(GetParam());
complex_t qeps = std::get<3>(GetParam());
q = qmag * (qdir + qeps*qdev).unit();
}
cvector_t q;
bool skip_q( double qmag_begin=1e-99, double qmag_end=1e99 ) {
return q.mag()<=qmag_begin || q.mag()>=qmag_end;
}
};
auto qlist = testing::Combine(
testing::Values(
cvector_t({ 1, 0, 0 }),
cvector_t({ 0, 1, 0 }),
cvector_t({ 0, 0, 1 }),
cvector_t({ 1, 1, 0 }),
cvector_t({ 1, 0, 1 }),
cvector_t({ 1, 0, 1 }),
cvector_t({ 1, 1, 1 })
),
testing::Values(
cvector_t({ 1, 0, 0 }),
cvector_t({ 0, 1, 0 }),
cvector_t({ 0, 0, 1 }),
cvector_t({ 1, 1, 0 }),
cvector_t({ 1, 0, 1 }),
cvector_t({ 1, 0, 1 }),
cvector_t({ 1, 1, 1 })
),
testing::Values(
1e-19, 1e-17, 1e-15, 1e-13, 1e-11, 1e-9, 1e-7, 1e-5, 1e-4, 1e-3, 1e-2, .1,
1., 1e1, 1e2, 1e3, 1e4 ),
testing::Values(
-1e-15, +1e-14, -1e-13*I, +1e-12*I,
-1e-11, +1e-10, -1e-9*I, +1e-8*I,
-1e-7, +1e-6, -1e-5*I, +1e-4*I,
-1e-3, +1e-2, -1e-1*I, +1e-1*I,
.9, -.99, .999, -.9999 )
);
#endif // QLOOPEDTEST_H
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