Page MenuHomeHEPForge

No OneTemporary

Index: trunk/tests/test_GaussLegendreQuadrature.cc
===================================================================
--- trunk/tests/test_GaussLegendreQuadrature.cc (revision 577)
+++ trunk/tests/test_GaussLegendreQuadrature.cc (revision 578)
@@ -1,65 +1,71 @@
#include <cmath>
#include <stdexcept>
#include <vector>
#include "UnitTest++.h"
#include "test_utils.hh"
#include "npstat/nm/GaussLegendreQuadrature.hh"
using namespace npstat;
using namespace std;
namespace {
struct MyPoly : public Functor1<long double, long double>
{
long double operator()(const long double& x) const
{return x*x*x*x*x - 11*x*x*x - 2*x*x + 3*x - 7;}
};
TEST(GaussLegendreQuadrature)
{
const unsigned nsup[] = {4, 6, 8, 10, 12, 16, 32, 64,
100, 128, 256, 512, 1024};
for (unsigned icycle=0; icycle<sizeof(nsup)/sizeof(nsup[0]); ++icycle)
{
GaussLegendreQuadrature quad(nsup[icycle]);
CHECK_EQUAL(nsup[icycle], quad.npoints());
std::vector<long double> 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);
}
}
}
Index: trunk/tests/test_FejerQuadrature.cc
===================================================================
--- trunk/tests/test_FejerQuadrature.cc (revision 577)
+++ trunk/tests/test_FejerQuadrature.cc (revision 578)
@@ -1,59 +1,65 @@
#include <cmath>
#include <stdexcept>
#include <vector>
#include "UnitTest++.h"
#include "test_utils.hh"
#include "npstat/nm/FejerQuadrature.hh"
#include "npstat/nm/SimpleFunctors.hh"
using namespace npstat;
using namespace std;
namespace {
struct MyPoly : public Functor1<long double, long double>
{
long double operator()(const long double& x) const
{return x*x*x*x*x - 11*x*x*x - 2*x*x + 3*x - 7;}
};
TEST(FejerQuadrature)
{
const unsigned nsup[] = {6, 8, 11, 12, 16, 32, 64};
for (unsigned icycle=0; icycle<sizeof(nsup)/sizeof(nsup[0]); ++icycle)
{
FejerQuadrature quad(nsup[icycle]);
CHECK_EQUAL(nsup[icycle], quad.npoints());
std::vector<long double> w(nsup[icycle]);
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(2.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 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);
}
}
TEST(FejerQuadrature_minimalExactRule)
{
for (unsigned i=0; i<10000; ++i)
{
const unsigned deg = test_rng()*1000;
const unsigned npt = FejerQuadrature::minimalExactRule(deg);
CHECK(npt == deg+1U);
}
}
TEST(FejerQuadrature_minPoints)
{
FejerQuadrature fej(1);
CHECK_CLOSE(12.0, fej.integrate(ConstValue1<double,double>(3.0),
-1.L, 3.L), 1.e-15);
}
}

File Metadata

Mime Type
text/x-diff
Expires
Sat, Dec 21, 4:52 PM (15 h, 2 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4023531
Default Alt Text
(4 KB)

Event Timeline