From 0157e52c00ef35c0ffba5d986a397106ab544eca Mon Sep 17 00:00:00 2001 From: Felix Gruber <gruber@igpm.rwth-aachen.de> Date: Tue, 25 Oct 2016 11:51:50 +0200 Subject: [PATCH] [test] add test for genericTransformTuple This test fails for now, as genericTransformTuple does not work on const tuples at the moment. --- dune/common/test/tupleutilitytest.cc | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/dune/common/test/tupleutilitytest.cc b/dune/common/test/tupleutilitytest.cc index c91c7a1f7..e94cd9ecf 100644 --- a/dune/common/test/tupleutilitytest.cc +++ b/dune/common/test/tupleutilitytest.cc @@ -5,7 +5,9 @@ #include "config.h" #endif +#include <cmath> #include <cstddef> +#include <iostream> #include <dune/common/tuples.hh> #include <dune/common/tupleutility.hh> @@ -142,5 +144,28 @@ typedef std::tuple< static_assert((std::is_same<Primes1, Primes2>::value), "ReduceTuple failed in primes-tmp!"); +struct Reciprocal +{ + template<class> + struct TypeEvaluator + { + typedef double Type; + }; + template<class T> + typename TypeEvaluator<T>::Type operator()(const T& val) const { + return 1./val; + }; +}; -int main() {} +int main() { + const std::tuple<int, double> t1(1, 2.); + auto t2 = Dune::genericTransformTuple(t1, Reciprocal()); + static_assert(std::is_same<decltype(t2), std::tuple<double, double>>::value, + "Type after genericTransformTuple does not match!"); + if(fabs(std::get<0>(t2)-1.) > 1e-8 || + fabs(std::get<1>(t2)-.5) > 1e-8) + { + std::cout << "genericTransformTuple gives wrong result!\n"; + std::abort(); + } +} -- GitLab