...
 
Commits (3)
......@@ -10,7 +10,7 @@ variables:
BASE_IMAGE: dorie/dune-env
# Use semantic versioning (not the version of DUNE) and bump according to
# to whether changes are backwards-compatible or not.
IMAGE_VERSION: "1.2"
IMAGE_VERSION: "1.3"
DUNE_ENV_IMAGE: ${BASE_IMAGE}:img-v${IMAGE_VERSION}
CMAKE_FLAGS:
......
......@@ -48,7 +48,7 @@ add_subdirectory("python")
add_subdirectory("doc")
add_subdirectory("dune")
add_subdirectory("lib")
if(dune-testtools_FOUND)
if(DORIE_TESTING)
add_subdirectory("test")
endif()
......
......@@ -41,11 +41,23 @@ find_package (yaml-cpp 0.5.2 REQUIRED)
# muparser
find_package (muparser REQUIRED)
# BOOST Unit Test framework
find_package(Boost 1.62
COMPONENTS unit_test_framework)
# Report the DUNE libs
message (STATUS "DUNE Libraries: ${DUNE_LIBS}")
# Remove CMake policy stack
cmake_policy(POP)
# Add DORiE testing functions
include(DorieTesting)
# Check if testing is enabled
if (dune-testtools_FOUND AND TARGET Boost::unit_test_framework)
message(STATUS "Testing enabled: dune-testtools and Boost Unit Test found.")
set(DORIE_TESTING TRUE)
# include the DORiE testing macros
include(DorieTesting)
else()
message(STATUS "Testing disabled: dune-testtools and Boost Unit Test "
"not found.")
endif()
......@@ -82,6 +82,13 @@ function(dorie_add_unit_test)
target_link_libraries(${UNIT_TEST_TARGET}
muparser::muparser hdf5 yaml-cpp spdlog)
add_coverage_links(${UNIT_TEST_TARGET})
# add Boost Unit Test links and compile options
target_link_libraries(${UNIT_TEST_TARGET} Boost::unit_test_framework)
# NOTE: Might lead to issues if linked to the static unit test library
target_compile_definitions(${UNIT_TEST_TARGET}
PRIVATE BOOST_TEST_DYN_LINK)
add_dependencies(build_unit_tests ${UNIT_TEST_TARGET})
endfunction()
......
......@@ -19,6 +19,7 @@ RUN apt-get clean \
gfortran \
git \
libatlas-base-dev \
libboost-test-dev \
libfftw3-dev \
libfftw3-mpi-dev \
libfreetype6-dev \
......
add_subdirectory("common")
add_subdirectory("model")
if(dune-testtools_FOUND)
if(DORIE_TESTING)
add_subdirectory("test")
endif()
......
#define BOOST_TEST_MODULE simulation base test
#include <boost/test/unit_test.hpp>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <cassert>
#include <dune/common/parallel/mpihelper.hh>
#include <dune/common/float_cmp.hh>
#include <dune/common/parallel/mpihelper.hh>
#include <dune/dorie/common/simulation_base.hh>
/// Dummy model for testing.
/** Makes sure that all functions of SimulationBase are properly overridden
* and called.
*/
class DummyModel : public Dune::Dorie::SimulationBase
/// Fixture for all test cases
struct DummyFixture
{
public:
DummyModel(Dune::MPIHelper& helper)
: Dune::Dorie::SimulationBase("dummy",
/// Initialize the DUNE MPI Helper from the command line arguments
Dune::MPIHelper& helper = Dune::MPIHelper::instance(
boost::unit_test::framework::master_test_suite().argc,
boost::unit_test::framework::master_test_suite().argv
);
/// Dummy model for testing only. Implements all pure virtual methods.
class DummyModel : public Dune::Dorie::SimulationBase
{
private:
using Base = Dune::Dorie::SimulationBase;
public:
DummyModel (Dune::MPIHelper& helper) :
Base("dummy",
"debug",
helper,
Dune::Dorie::OutputPolicy::None,
Dune::Dorie::AdaptivityPolicy::None)
, _dt(.1)
, _current_time(begin_time())
, _end_time(1.0)
, _grid_was_adapted(false)
, _data_was_written(false)
{}
Dune::Dorie::AdaptivityPolicy::None),
_dt(.1),
_current_time(begin_time()),
_end_time(1.0),
_grid_was_adapted(false),
_data_was_written(false)
{ }
double begin_time() const override { return 0.; }
double end_time() const override { return _end_time; }
......@@ -50,45 +60,76 @@ public:
_data_was_written = true;
}
private:
private:
double _dt;
double _current_time;
public:
public:
double _end_time;
bool _grid_was_adapted;
mutable bool _data_was_written;
} model = DummyModel(helper);
};
int main(int argc, char **argv)
/// Create a new suite using the fixture in every test case
BOOST_FIXTURE_TEST_SUITE(suite, DummyFixture);
/// Test if the model is correctly initialized
BOOST_AUTO_TEST_CASE (initialize)
{
BOOST_TEST(model._end_time == 1.0);
BOOST_TEST(model._grid_was_adapted == false);
BOOST_TEST(model._data_was_written == false);
BOOST_TEST(model.begin_time() == 0.0);
BOOST_TEST(model.current_time() == 0.0);
const bool output_policy =
(model.output_policy() == Dune::Dorie::OutputPolicy::None);
BOOST_TEST(output_policy);
const bool adaptivity_policy =
(model.adaptivity_policy() == Dune::Dorie::AdaptivityPolicy::None);
BOOST_TEST(adaptivity_policy);
}
/// Test if policies are correctly set
BOOST_AUTO_TEST_CASE (policies)
{
auto& helper = Dune::MPIHelper::instance(argc, argv);
const auto adapt_policy = Dune::Dorie::AdaptivityPolicy::WaterFlux;
model.set_policy(adapt_policy);
bool policy_correct = (model.adaptivity_policy() == adapt_policy);
BOOST_TEST(policy_correct);
const auto output_policy = Dune::Dorie::OutputPolicy::EndOfRichardsStep;
model.set_policy(output_policy);
policy_correct = (model.output_policy() == output_policy);
BOOST_TEST(policy_correct);
}
try {
DummyModel model(helper);
/// Test if the model correctly performs the run() algorithm
BOOST_AUTO_TEST_CASE (run)
{
// perform a step
model.step();
BOOST_TEST(Dune::FloatCmp::eq(model.current_time(),
model.begin_time() + 0.1));
// run the model without adaptivity
// run multiple steps
model.run();
assert(not model._grid_was_adapted);
assert(not model._data_was_written);
assert(Dune::FloatCmp::ge(model.current_time(), model.end_time()));
BOOST_TEST(Dune::FloatCmp::eq(model.current_time(),
model.end_time()));
BOOST_TEST(not model._grid_was_adapted);
BOOST_TEST(not model._data_was_written);
// now set adaptivity
// set new policies
model.set_policy(Dune::Dorie::AdaptivityPolicy::WaterFlux);
model.set_policy(Dune::Dorie::OutputPolicy::EndOfRichardsStep);
model._end_time += 1.0;
model.run();
assert(model._grid_was_adapted);
assert(model._data_was_written);
assert(Dune::FloatCmp::ge(model.current_time(), model.end_time()));
} catch (Dune::Exception& e) {
std::cout << e.what() << std::endl;
return 1;
} catch (...) {
std::cerr << "Exception occurred!" << std::endl;
return 1;
}
return 0;
// run multiple steps, check if policies are applied
model.run();
BOOST_TEST(Dune::FloatCmp::eq(model.current_time(),
model.end_time()));
BOOST_TEST(model._grid_was_adapted);
BOOST_TEST(model._data_was_written);
}
BOOST_AUTO_TEST_SUITE_END()