Commit 87a0824d authored by Felix Gruber's avatar Felix Gruber

use TestSuite for functionspacebases tests

As opposed to the previously used assert(), the use of TestSuite also
works in non-debug builds.
parent 7d58945c
Pipeline #15183 passed with stage
in 20 minutes and 8 seconds
......@@ -8,6 +8,7 @@
#include <dune/common/exceptions.hh>
#include <dune/common/fvector.hh>
#include <dune/common/parallel/mpihelper.hh>
#include <dune/common/test/testsuite.hh>
#include <dune/dpg/innerproductfactory.hh>
#include <dune/dpg/spacetuple.hh>
......@@ -23,7 +24,7 @@ using namespace Dune;
using namespace Dune::Functions;
template<class Basis>
void testNormedAdaptorOn(const typename Basis::GridView gridView)
TestSuite testNormedAdaptorOn(const typename Basis::GridView gridView)
{
auto testSpaces = make_space_tuple<Basis>(gridView);
......@@ -39,10 +40,10 @@ void testNormedAdaptorOn(const typename Basis::GridView gridView)
using InnerProduct = decltype(innerProduct);
NormalizedBasis<InnerProduct> normedBasis(innerProduct);
testScalarBasis(normedBasis);
return testScalarBasis(normedBasis);
}
int main (int argc, char* argv[]) try
int main(int argc, char* argv[])
{
Dune::MPIHelper::instance(argc, argv);
......@@ -56,17 +57,7 @@ int main (int argc, char* argv[]) try
typedef GridType::LeafGridView GridView;
const GridView gridView = grid.leafGridView();
testNormedAdaptorOn<LagrangeDGBasis<GridView, 2>>(gridView);
TestSuite t = testNormedAdaptorOn<LagrangeDGBasis<GridView, 2>>(gridView);
return 0;
} catch ( Dune::Exception &e )
{
std::cerr << "Dune reported error: " << e << std::endl;
return 1;
}
catch(...)
{
std::cerr << "Unknown exception thrown!" << std::endl;
return 1;
return t.exit();
}
......@@ -8,6 +8,7 @@
#include <dune/common/exceptions.hh>
#include <dune/common/fvector.hh>
#include <dune/common/parallel/mpihelper.hh>
#include <dune/common/test/testsuite.hh>
#include <dune/dpg/innerproductfactory.hh>
#include <dune/dpg/spacetuple.hh>
......@@ -23,7 +24,7 @@ using namespace Dune;
using namespace Dune::Functions;
template<class Basis>
void testNormedAdaptorOn(const typename Basis::GridView gridView)
TestSuite testNormedAdaptorOn(const typename Basis::GridView gridView)
{
auto testSpaces = make_space_tuple<Basis>(gridView);
......@@ -39,10 +40,10 @@ void testNormedAdaptorOn(const typename Basis::GridView gridView)
using InnerProduct = decltype(innerProduct);
NormalizedRefinedBasis<InnerProduct> normedBasis(innerProduct);
testRefinedScalarBasis(normedBasis);
return testRefinedScalarBasis(normedBasis);
}
int main (int argc, char* argv[]) try
int main(int argc, char* argv[])
{
Dune::MPIHelper::instance(argc, argv);
......@@ -56,17 +57,8 @@ int main (int argc, char* argv[]) try
typedef GridType::LeafGridView GridView;
const GridView gridView = grid.leafGridView();
testNormedAdaptorOn<PQkDGRefinedDGBasis<GridView, 1, 2>>(gridView);
TestSuite t
= testNormedAdaptorOn<PQkDGRefinedDGBasis<GridView, 1, 2>>(gridView);
return 0;
} catch ( Dune::Exception &e )
{
std::cerr << "Dune reported error: " << e << std::endl;
return 1;
}
catch(...)
{
std::cerr << "Unknown exception thrown!" << std::endl;
return 1;
return t.exit();
}
......@@ -6,6 +6,7 @@
#include <dune/common/exceptions.hh>
#include <dune/common/parallel/mpihelper.hh>
#include <dune/common/test/testsuite.hh>
#include <dune/grid/yaspgrid.hh>
......@@ -16,7 +17,7 @@
using namespace Dune;
using namespace Dune::Functions;
int main (int argc, char* argv[]) try
int main(int argc, char* argv[])
{
Dune::MPIHelper::instance(argc, argv);
......@@ -31,17 +32,7 @@ int main (int argc, char* argv[]) try
const GridView gridView = grid.leafGridView();
Functions::PQkDGRefinedDGBasis<GridView, 1, 2> dgrefinedbasis(gridView);
testRefinedScalarBasis(dgrefinedbasis);
TestSuite t = testRefinedScalarBasis(dgrefinedbasis);
return 0;
} catch ( Dune::Exception &e )
{
std::cerr << "Dune reported error: " << e << std::endl;
return 1;
}
catch(...)
{
std::cerr << "Unknown exception thrown!" << std::endl;
return 1;
return t.exit();
}
......@@ -6,6 +6,7 @@
#include <dune/common/exceptions.hh>
#include <dune/common/parallel/mpihelper.hh>
#include <dune/common/test/testsuite.hh>
#include <dune/grid/yaspgrid.hh>
......@@ -16,7 +17,7 @@
using namespace Dune;
using namespace Dune::Functions;
int main (int argc, char* argv[]) try
int main(int argc, char* argv[])
{
Dune::MPIHelper::instance(argc, argv);
......@@ -30,27 +31,19 @@ int main (int argc, char* argv[]) try
typedef GridType::LeafGridView GridView;
const GridView gridView = grid.leafGridView();
TestSuite t;
PQkTraceNodalBasis<GridView, 1> pq1Basis(gridView);
testScalarBasis(pq1Basis);
t.subTest(testScalarBasis(pq1Basis));
PQkTraceNodalBasis<GridView, 2> pq2Basis(gridView);
testScalarBasis(pq2Basis);
t.subTest(testScalarBasis(pq2Basis));
PQkTraceNodalBasis<GridView, 3> pq3Basis(gridView);
testScalarBasis(pq3Basis);
t.subTest(testScalarBasis(pq3Basis));
PQkTraceNodalBasis<GridView, 4> pq4Basis(gridView);
testScalarBasis(pq4Basis);
return 0;
t.subTest(testScalarBasis(pq4Basis));
} catch ( Dune::Exception &e )
{
std::cerr << "Dune reported error: " << e << std::endl;
return 1;
}
catch(...)
{
std::cerr << "Unknown exception thrown!" << std::endl;
return 1;
return t.exit();
}
......@@ -3,7 +3,7 @@
#ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_TEST_REFINEDBASISTEST_HH
#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_TEST_REFINEDBASISTEST_HH
#include <dune/common/exceptions.hh>
#include <dune/common/test/testsuite.hh>
#include <dune/common/typetraits.hh>
#include <dune/common/unused.hh>
#include <dune/common/version.hh>
......@@ -13,8 +13,9 @@
namespace Dune {
template <typename Basis>
void testLocalFeForEachElement(const Basis& feBasis)
TestSuite testLocalFeForEachElement(const Basis& feBasis)
{
TestSuite t;
typedef typename Basis::GridView GridView;
const GridView gridView = feBasis.gridView();
......@@ -28,25 +29,26 @@ void testLocalFeForEachElement(const Basis& feBasis)
// The general LocalFiniteElement unit test from
// dune/localfunctions/test/test-localfe.hh
const auto& lFE = localView.tree().finiteElement();
testFE(lFE);
t.check(testFE(lFE));
const size_t numSubElements =
localView.tree().refinedReferenceElementGridView().size(0);
if (lFE.size() * numSubElements != localView.size())
DUNE_THROW(Exception,
"Size of leaf node and finite element do not coincide: "
t.require(lFE.size() * numSubElements == localView.size())
<< "Size of leaf node and finite element do not coincide: "
<< lFE.size() << " * " << numSubElements
<< " != " << localView.size());
<< " != " << localView.size();
}
return t;
}
template <typename Basis>
void checkRangeOfGlobalIndices(const Basis& feBasis)
TestSuite checkRangeOfGlobalIndices(const Basis& feBasis)
{
/////////////////////////////////////////////////////////////////////
// Check whether the global indices are in the correct range,
// and whether each global index appears at least once.
/////////////////////////////////////////////////////////////////////
TestSuite t;
const auto gridView = feBasis.gridView();
......@@ -61,28 +63,29 @@ void checkRangeOfGlobalIndices(const Basis& feBasis)
for (size_t i=0; i<localView.tree().size(); i++)
{
if (localView.index(i)[0] < 0)
DUNE_THROW(Exception, "Index is negative, which is not allowed");
t.check(localView.index(i)[0] >= 0);
if (localView.index(i)[0] >= seen.size())
DUNE_THROW(Exception, "Local index " << i
<< " is mapped to global index "
<< localView.index(i)
<< ", which is larger than allowed");
t.check(localView.index(i)[0] < seen.size())
<< "Local index " << i
<< " is mapped to global index "
<< localView.index(i)
<< ", which is larger than allowed";
seen[localView.index(i)[0]] = true;
}
}
for (size_t i=0; i<seen.size(); i++)
if (! seen[i])
DUNE_THROW(Exception,
"Index [" << i << "] does not exist as global basis vector");
t.check(seen[i])
<< "Index [" << i << "] does not exist as global basis vector";
return t;
}
template <typename Basis>
void checkConsistencyOfLocalViewAndIndexSet(const Basis& feBasis)
TestSuite checkConsistencyOfLocalViewAndIndexSet(const Basis& feBasis)
{
TestSuite t;
const auto gridView = feBasis.gridView();
auto localView = feBasis.localView();
auto localView2 = feBasis.localView();
......@@ -93,26 +96,28 @@ void checkConsistencyOfLocalViewAndIndexSet(const Basis& feBasis)
localView2.bind(element);
// paranoia checks
assert(&(localView.globalBasis()) == &(feBasis));
t.require(&(localView.globalBasis()) == &(feBasis));
assert(localView.size() == localView2.size());
t.require(localView.size() == localView2.size());
for (size_t i=0; i<localView.size(); i++)
assert(localView.index(i) == localView2.index(i));
t.check(localView.index(i) == localView2.index(i));
typedef typename Basis::LocalView::Tree Tree;
DUNE_UNUSED const Tree& tree = localView.tree();
// we have a flat tree...
assert(localView.size() == tree.size());
t.require(localView.size() == tree.size());
localView.unbind();
}
return t;
}
template <typename Basis>
void testRefinedScalarBasis(const Basis& feBasis)
TestSuite testRefinedScalarBasis(const Basis& feBasis)
{
testLocalFeForEachElement(feBasis);
TestSuite t;
t.subTest(testLocalFeForEachElement(feBasis));
// Check whether the basis exports a type 'MultiIndex'
typedef typename Basis::MultiIndex MultiIndex;
......@@ -126,8 +131,9 @@ void testRefinedScalarBasis(const Basis& feBasis)
"MultiIndex must support operator[]");
#endif
checkRangeOfGlobalIndices(feBasis);
checkConsistencyOfLocalViewAndIndexSet(feBasis);
t.subTest(checkRangeOfGlobalIndices(feBasis));
t.subTest(checkConsistencyOfLocalViewAndIndexSet(feBasis));
return t;
}
}
......
......@@ -3,7 +3,7 @@
#ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_TEST_UNREFINEDBASISTEST_HH
#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_TEST_UNREFINEDBASISTEST_HH
#include <dune/common/exceptions.hh>
#include <dune/common/test/testsuite.hh>
#include <dune/common/typetraits.hh>
#include <dune/common/unused.hh>
#include <dune/common/version.hh>
......@@ -13,8 +13,9 @@
namespace Dune {
template <typename Basis>
void testLocalFeForEachElement(const Basis& feBasis)
TestSuite testLocalFeForEachElement(const Basis& feBasis)
{
TestSuite t;
typedef typename Basis::GridView GridView;
const GridView gridView = feBasis.gridView();
......@@ -29,21 +30,22 @@ void testLocalFeForEachElement(const Basis& feBasis)
// The general LocalFiniteElement unit test from
// dune/localfunctions/test/test-localfe.hh
const auto& lFE = localView.tree().finiteElement();
testFE(lFE);
t.check(testFE(lFE));
if (lFE.size() != localView.size())
DUNE_THROW(Exception,
"Size of leaf node and finite element do not coincide");
t.require(lFE.size() == localView.size())
<< "Size of leaf node and finite element do not coincide";
}
return t;
}
template <typename Basis>
void checkRangeOfGlobalIndices(const Basis& feBasis)
TestSuite checkRangeOfGlobalIndices(const Basis& feBasis)
{
/////////////////////////////////////////////////////////////////////
// Check whether the global indices are in the correct range,
// and whether each global index appears at least once.
/////////////////////////////////////////////////////////////////////
TestSuite t;
const auto gridView = feBasis.gridView();
......@@ -58,28 +60,29 @@ void checkRangeOfGlobalIndices(const Basis& feBasis)
for (size_t i=0; i<localView.tree().size(); i++)
{
if (localView.index(i)[0] < 0)
DUNE_THROW(Exception, "Index is negative, which is not allowed");
t.check(localView.index(i)[0] >= 0);
if (localView.index(i)[0] >= seen.size())
DUNE_THROW(Exception, "Local index " << i
<< " is mapped to global index "
<< localView.index(i)
<< ", which is larger than allowed");
t.check(localView.index(i)[0] < seen.size())
<< "Local index " << i
<< " is mapped to global index "
<< localView.index(i)
<< ", which is larger than allowed";
seen[localView.index(i)[0]] = true;
}
}
for (size_t i=0; i<seen.size(); i++)
if (! seen[i])
DUNE_THROW(Exception,
"Index [" << i << "] does not exist as global basis vector");
t.check(seen[i])
<< "Index [" << i << "] does not exist as global basis vector";
return t;
}
template <typename Basis>
void checkConsistencyOfLocalViewAndIndexSet(const Basis& feBasis)
TestSuite checkConsistencyOfLocalViewAndIndexSet(const Basis& feBasis)
{
TestSuite t;
const auto gridView = feBasis.gridView();
typename Basis::LocalView localView(feBasis);
auto localView2 = feBasis.localView();
......@@ -90,27 +93,29 @@ void checkConsistencyOfLocalViewAndIndexSet(const Basis& feBasis)
localView2.bind(element);
// paranoia checks
assert(&(localView.globalBasis()) == &(feBasis));
t.require(&(localView.globalBasis()) == &(feBasis));
assert(localView.size() == localView2.size());
t.require(localView.size() == localView2.size());
for (size_t i=0; i<localView.size(); i++)
assert(localView.index(i) == localView2.index(i));
t.check(localView.index(i) == localView2.index(i));
typedef typename Basis::LocalView::Tree Tree;
DUNE_UNUSED const Tree& tree = localView.tree();
// we have a flat tree...
assert(localView.size() == tree.size());
assert(localView.size() == tree.finiteElement().localBasis().size());
t.require(localView.size() == tree.size());
t.require(localView.size() == tree.finiteElement().localBasis().size());
localView.unbind();
}
return t;
}
template <typename Basis>
void testScalarBasis(const Basis& feBasis)
TestSuite testScalarBasis(const Basis& feBasis)
{
testLocalFeForEachElement(feBasis);
TestSuite t;
t.subTest(testLocalFeForEachElement(feBasis));
// Check whether the basis exports a type 'MultiIndex'
typedef typename Basis::MultiIndex MultiIndex;
......@@ -124,8 +129,9 @@ void testScalarBasis(const Basis& feBasis)
"MultiIndex must support operator[]");
#endif
checkRangeOfGlobalIndices(feBasis);
checkConsistencyOfLocalViewAndIndexSet(feBasis);
t.subTest(checkRangeOfGlobalIndices(feBasis));
t.subTest(checkConsistencyOfLocalViewAndIndexSet(feBasis));
return t;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment