Skip to content
Snippets Groups Projects
Verified Commit 94396917 authored by René Fritze's avatar René Fritze
Browse files

[validation] expand tests + fixup for Vector valued validation

parent 18b3770a
No related branches found
No related tags found
No related merge requests found
......@@ -80,13 +80,13 @@ void print_collected_eoc_study_results(const std::map<std::string, std::vector<d
unsigned int grid_elements();
template <typename T>
static typename std::enable_if<Common::is_vector<T>::value, T>::type init_bound(int val)
static typename std::enable_if<Common::is_vector<T>::value, T>::type init_bound(typename Common::VectorAbstraction<T>::S val)
{
const auto size = Common::VectorAbstraction<T>::has_static_size ? Common::VectorAbstraction<T>::static_size : 3u;
return Common::VectorAbstraction<T>::create(size, val);
}
template <typename T>
static typename std::enable_if<!Common::is_vector<T>::value, T>::type init_bound(int val)
static typename std::enable_if<!Common::is_vector<T>::value, T>::type init_bound(typename Common::VectorAbstraction<T>::S val)
{
return T(val);
}
......
......@@ -28,28 +28,28 @@
#include <boost/array.hpp>
using namespace Dune::XT::Common;
using namespace Dune::XT::Test;
typedef testing::Types<double, float, // Dune::bigunsignedint,
int, unsigned int, unsigned long, long long, char, Dune::FieldVector<double, 3>> MathTestTypes;
template <class T>
struct ValidationTest : public testing::Test
{
typedef FIELD_TYPE T;
typedef DefaultRNG<T> RNGType;
static const T eps;
/** for some weird reason my compiler thinks ValidationTest is an abstract class
* if I don't implement "void TestBody();"
* \see common_math.cc testcases for why I think it's weird
**/
void TestBody()
void all()
{
using namespace boost::assign;
const int samples = 100000;
const int samples = 100;
std::cout << "\tTesting Validators for type " << Typename<T>::value() << "\n\t\t" << samples
<< " random numbers ..." << std::endl;
{
const T lower = std::numeric_limits<T>::min() + eps;
const T upper = std::numeric_limits<T>::max() - eps;
typedef VectorAbstraction<T>::S S;
const auto scalar_eps = Epsilon<S>::value;
const T lower = init_bound<T>(std::numeric_limits<S>::min() + scalar_eps);
const T upper = init_bound<T>(std::numeric_limits<S>::max() - scalar_eps);
RNGType rng(lower, upper);
for (int i = samples; i > 0; --i) {
const T arg = rng();
......@@ -65,9 +65,9 @@ struct ValidationTest : public testing::Test
}
std::cout << "\t\tfixed interval" << std::endl;
{
const T lower = T(0);
const T upper = T(2);
const T arg = T(1);
const T lower = init_bound<T>(0);
const T upper = init_bound<T>(2);
const T arg = init_bound<T>(1);
test(lower, upper, arg);
EXPECT_FALSE(ValidateLess<T>(upper)(lower));
EXPECT_FALSE(ValidateGreater<T>(lower)(upper));
......@@ -78,7 +78,6 @@ struct ValidationTest : public testing::Test
void test(const T lower, const T upper, const T arg) const
{
const T clamped_arg = clamp(arg, T(lower + eps), T(upper - eps));
EXPECT_TRUE(ValidateAny<T>()(arg));
EXPECT_TRUE(ValidateLess<T>(clamped_arg)(upper));
......@@ -88,13 +87,9 @@ struct ValidationTest : public testing::Test
EXPECT_FALSE(ValidateNone<T>()(arg));
}
};
const FIELD_TYPE ValidationTest::eps = Epsilon<T>::value;
template <typename T>
const T ValidationTest<T>::eps = Epsilon<T>::value;
TYPED_TEST_CASE(ValidationTest, MathTestTypes);
TYPED_TEST(ValidationTest, All)
TEST_F(ValidationTest, All)
{
ValidationTest<TypeParam> k;
k.TestBody();
this->all();
}
__exec_suffix = {suf_testtype}
testtype = double, float, int, unsigned int, unsigned long, long long, char, Dune::FieldVector<double\, 3> | expand field
suf_testtype = double, float, int, unsigned_int, unsigned_long, long_long, char, field_vector_double_3 | expand field
[__static]
FIELD_TYPE = {testtype}
......@@ -119,7 +119,7 @@ public:
}
inline bool operator()(const T& val) const
{
return FloatCmp::lt(val, baseval_);
return FloatCmp::lt(baseval_, val, 0., 0.);
}
std::string msg(const T& value) const
......@@ -143,7 +143,7 @@ public:
}
inline bool operator()(const T& val) const
{
return FloatCmp::gt(val, baseval_);
return FloatCmp::gt(baseval_, val, 0., 0.);
}
std::string msg(const T& value) const
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment