Loading [MathJax]/extensions/TeX/AMSsymbols.js
Radium Engine  1.5.29
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
unittestUtils.hpp
1#pragma once
2
3#include <Core/Math/Math.hpp>
4#include <Core/Types.hpp>
5#include <Core/Utils/StdOptional.hpp>
6#include <Core/Utils/TypesUtils.hpp>
7
8// need StdOptional included before
9#ifdef have_optional
10template <typename S>
11inline bool isApprox( const Ra::Core::Utils::optional<S>& lhs, const S& rhs ) {
12 return lhs.has_value() && Ra::Core::Math::areApproxEqual( *lhs, rhs );
13}
14
15template <typename S>
16inline bool isApprox( const S& lhs, const Ra::Core::Utils::optional<S>& rhs ) {
17 return rhs.has_value() && Ra::Core::Math::areApproxEqual( lhs, *rhs );
18}
19#endif
20
21template <typename S>
22inline bool isApprox( const S& lhs, const S& rhs ) {
23 return Ra::Core::Math::areApproxEqual( lhs, rhs );
24}
25
26// A non-copyable move semantics struct
27struct NonCopy {
28 explicit NonCopy( int x ) : value( x ) {}
29 NonCopy( NonCopy&& other ) {
30 value = other.value;
31 other.value = 0;
32 }
33 NonCopy& operator=( NonCopy&& other ) {
34 value = other.value;
35 other.value = 0;
36 return *this;
37 }
38
39 int value;
40
41 private:
42 NonCopy( const NonCopy& ) = delete;
43 NonCopy& operator=( const NonCopy& ) = delete;
44};
45
47template <class Class>
49 template <class V>
50 static auto test( V* ) -> decltype( std::declval<std::ostream>() << std::declval<V>() );
51 template <typename>
52 static auto test( ... ) -> std::false_type;
53
54 using type = typename std::is_same<std::ostream&, decltype( test<Class>( 0 ) )>::type;
55};
56
57template <class Class>
58struct has_ostream_operator : has_ostream_operator_impl<Class>::type {};
59
61template <typename Types>
63 using types = Types;
64
65 template <typename T,
66 typename std::enable_if<has_ostream_operator<T>::value, bool>::type = true>
67 void operator()( const std::string& name, T& value ) {
68 std::cout << " [ " << name << " --> " << value << " ("
69 << Ra::Core::Utils::simplifiedDemangledType<T>() << ") ]\n";
70 }
71
72 template <typename T,
73 typename std::enable_if<!has_ostream_operator<T>::value, bool>::type = true>
74 void operator()( const std::string& name, const T& ) {
75 std::cout << " [ " << name << " --> ___ (" << Ra::Core::Utils::simplifiedDemangledType<T>()
76 << ") ]\n";
77 }
78};
T declval(T... args)
std::enable_if<!std::numeric_limits< T >::is_integer, bool >::type areApproxEqual(T x, T y, T espilonBoostFactor=T(10))
Compare two numbers such that |x-y| < espilon*epsilonBoostFactor.
Definition Math.hpp:42
Types, list of types as Ra::Core::Utils::TypeList< ... >
https://gist.github.com/szymek156/9b1b90fe474277be4641e9ef4666f472