mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Testing workflow with upstream + local repo.
Added template for unit test for new feature. Updated (CMake's) list of unit tests.
This commit is contained in:
parent
d92849b419
commit
23e2034118
@ -44,6 +44,7 @@ list (APPEND TEST_SOURCE_FILES
|
||||
tests/test_boprops_ad.cpp
|
||||
tests/test_span.cpp
|
||||
tests/test_syntax.cpp
|
||||
tests/test_scalar_mult.cpp
|
||||
)
|
||||
|
||||
list (APPEND TEST_DATA_FILES
|
||||
|
53
tests/test_scalar_mult.cpp
Normal file
53
tests/test_scalar_mult.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
#include <config.h>
|
||||
|
||||
#if HAVE_DYNAMIC_BOOST_TEST
|
||||
#define BOOST_TEST_DYN_LINK
|
||||
#endif
|
||||
|
||||
#define BOOST_TEST_MODULE ScalarMultTest
|
||||
|
||||
#include <opm/autodiff/AutoDiff.hpp>
|
||||
|
||||
#include <cmath>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ScalarMultiplication)
|
||||
{
|
||||
|
||||
|
||||
std::cout << "er her" << std::endl;
|
||||
|
||||
|
||||
typedef AutoDiff::Forward<double> AdFW;
|
||||
|
||||
const double atol = 1.0e-14;
|
||||
|
||||
AdFW a = AdFW::variable(0.0);
|
||||
AdFW b = AdFW::variable(1.0);
|
||||
|
||||
AdFW two_a = a + a;
|
||||
BOOST_CHECK_CLOSE(two_a.val(), 2*a.val(), atol);
|
||||
BOOST_CHECK_CLOSE(two_a.der(), 2*a.der(), atol);
|
||||
|
||||
double av = a.val();
|
||||
double ad = a.der();
|
||||
a += b;
|
||||
BOOST_CHECK_CLOSE(a.val(), av + b.val(), atol);
|
||||
BOOST_CHECK_CLOSE(a.der(), ad + b.der(), atol);
|
||||
|
||||
av = a.val();
|
||||
ad = a.der();
|
||||
a += 1;
|
||||
BOOST_CHECK_CLOSE(a.val(), av + 1, atol);
|
||||
BOOST_CHECK_CLOSE(a.der(), ad , atol);
|
||||
|
||||
AdFW bpo = b + 1; // b plus one
|
||||
BOOST_CHECK_CLOSE(bpo.val(), b.val() + 1, atol);
|
||||
BOOST_CHECK_CLOSE(bpo.der(), b.der() , atol);
|
||||
|
||||
AdFW opb = 1 + b; // one plus b
|
||||
BOOST_CHECK_CLOSE(opb.val(), b.val() + 1, atol);
|
||||
BOOST_CHECK_CLOSE(opb.der(), b.der() , atol);
|
||||
}
|
Loading…
Reference in New Issue
Block a user