Index: trunk/tests/test_GaussLegendreQuadrature.cc =================================================================== --- trunk/tests/test_GaussLegendreQuadrature.cc (revision 714) +++ trunk/tests/test_GaussLegendreQuadrature.cc (revision 715) @@ -1,112 +1,119 @@ #include #include #include #include "UnitTest++.h" #include "test_utils.hh" #include "npstat/nm/GaussLegendreQuadrature.hh" #include "npstat/nm/GaussLegendreQuadratureQ.hh" #include "npstat/nm/GaussLegendreQuadrature2D.hh" using namespace npstat; using namespace std; namespace { struct MyPoly : public Functor1 { long double operator()(const long double& x) const {return x*x*x*x*x - 11*x*x*x - 2*x*x + 3*x - 7;} }; struct Fcn2D { long double operator()(const long double x, const long double y) const {return expl(-(x*x + y*y));} }; #ifdef USE_LAPACK_QUAD struct MyFcn : public Functor1 { lapack_double operator()(const lapack_double& x) const { return std::exp(-x*x/2.0Q); } }; TEST(GaussLegendreQuadratureQ) { const lapack_double sqrt2pi = 2.506628274631000502415765284811045253Q; const unsigned nsup[] = {128, 256, 512, 1024}; for (unsigned icycle=0; icycle w(nsup[icycle]/2); quad.getWeights(&w[0], w.size()); long double sum = 0.0L; for (int k=w.size()-1; k>=0; --k) sum += w[k]; CHECK_CLOSE(1.0L, sum, 1.e-16L); const long double v = quad.integrate(MyPoly(), 0.L, 4.L); CHECK_CLOSE(-68.0L, v, 1.e-14); const long double v2 = quad.integrate(MyPoly(), 0.L, 4.L, 5); CHECK_CLOSE(-68.0L, v2, 1.e-14); const auto& points = quad.weightedIntegrationPoints(MyPoly(), 0.L, 4.L); sum = 0.0L; for (int k=points.size()-1; k>=0; --k) sum += points[k].second; CHECK_CLOSE(-68.0L, sum, 1.e-14); } bool thrown = false; try { GaussLegendreQuadrature quad(1234567U); } catch (std::invalid_argument& e) { thrown = true; } CHECK(thrown); } TEST(GaussLegendreQuadrature_minimalExactRule) { for (unsigned i=0; i<10000; ++i) { const unsigned deg = test_rng()*1000; const unsigned npt = GaussLegendreQuadrature::minimalExactRule(deg); CHECK(npt*2 > deg); } } TEST(GaussLegendreQuadrature2D) { - GaussLegendreQuadrature2D glq(128, 256); Fcn2D fcn; - const double tmp = glq.integrate(fcn, 1.0, 2.0, 2.0, 3.0); + + GaussLegendreQuadrature2D glq1(128, 256); + double tmp = glq1.integrate(fcn, 1.0, 2.0, 2.0, 3.0); + CHECK(glq1.npoints(0) == 128); + CHECK(glq1.npoints(1) == 256); CHECK_CLOSE(0.0005580656974759, tmp, 1.e-14); + + GaussLegendreQuadrature2D glq2(256, 128); + tmp = glq2.integrate(fcn, 0.5, 3.0, 2.0, 2.5); + CHECK_CLOSE(0.00160829642594, tmp, 1.e-14); } }