Sacado Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
TraitsTests.hpp
Go to the documentation of this file.
1// @HEADER
2// ***********************************************************************
3//
4// Sacado Package
5// Copyright (2006) Sandia Corporation
6//
7// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8// the U.S. Government retains certain rights in this software.
9//
10// This library is free software; you can redistribute it and/or modify
11// it under the terms of the GNU Lesser General Public License as
12// published by the Free Software Foundation; either version 2.1 of the
13// License, or (at your option) any later version.
14//
15// This library is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18// Lesser General Public License for more details.
19//
20// You should have received a copy of the GNU Lesser General Public
21// License along with this library; if not, write to the Free Software
22// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
23// USA
24// Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
25// (etphipp@sandia.gov).
26//
27// ***********************************************************************
28// @HEADER
29
30#ifndef TRAITSTESTS_HPP
31#define TRAITSTESTS_HPP
32
33#include <type_traits>
34
35// Sacado includes
36#include "Sacado_No_Kokkos.hpp"
37#include "Sacado_Random.hpp"
38#include "Sacado_mpl_apply.hpp"
39
40// gtest includes
41#include <gtest/gtest.h>
42
43// A class for testing Sacado::Traits definitions for Sacado AD types
44template <class ADType>
46protected:
47
50
51 // Random number generator
53
54 // GTest creates the test fixture as a child class, so ad1_t, ad2_t are
55 // not visible. Create some data members of these types to get the types
56 // in the test cases
59
60 TraitsTests() : urand(), ad1(), ad2() {}
62
63}; // class TraitsTests
64
66
67TYPED_TEST_P(TraitsTests, testScalarType) {
68 typedef decltype(this->ad1) ad1_t;
69 typedef decltype(this->ad2) ad2_t;
70
71 bool same = std::is_same< typename Sacado::ScalarType<ad1_t>::type, double >::value;
72 ASSERT_TRUE(same == true);
73
74same = std::is_same< typename Sacado::ScalarType<ad2_t>::type,double >::value;
75 ASSERT_TRUE(same == true);
76}
77
78TYPED_TEST_P(TraitsTests, testValueType) {
79 typedef decltype(this->ad1) ad1_t;
80 typedef decltype(this->ad2) ad2_t;
81
82 bool same = std::is_same< typename Sacado::ValueType<ad1_t>::type,double >::value;
83 ASSERT_TRUE(same == true);
84
85 same = std::is_same< typename Sacado::ValueType<ad2_t>::type,ad1_t >::value;
86 ASSERT_TRUE(same == true);
87}
88
89TYPED_TEST_P(TraitsTests, testIsADType) {
90 typedef decltype(this->ad1) ad1_t;
91 typedef decltype(this->ad2) ad2_t;
92
95}
96
97TYPED_TEST_P(TraitsTests, testIsScalarType) {
98 typedef decltype(this->ad1) ad1_t;
99 typedef decltype(this->ad2) ad2_t;
100
103}
104
106 typedef decltype(this->ad1) ad1_t;
107 typedef decltype(this->ad2) ad2_t;
108
109 double val = this->urand.number();
110 ad1_t a(val);
112
113 ad2_t b(a);
115}
116
117TYPED_TEST_P(TraitsTests, testScalarValue) {
118 typedef decltype(this->ad1) ad1_t;
119 typedef decltype(this->ad2) ad2_t;
120
121 double val = this->urand.number();
122 ad1_t a(val);
124
125 ad2_t b(a);
127}
128
129TYPED_TEST_P(TraitsTests, testStringName) {
130 typedef decltype(this->ad1) ad1_t;
131 typedef decltype(this->ad2) ad2_t;
132
133 // Currently we can't check the string name, here we are just making sure
134 // it compiles
137 // ASSERT_TRUE(Sacado::StringName<ad1_t>::eval() == name + "< double, double >");
138 // ASSERT_TRUE(Sacado::StringName<ad2_t>::eval() == name + "< " + name + "< double, double >, double >");
139}
140
143 testScalarType,
144 testValueType,
145 testIsADType,
146 testIsScalarType,
147 testValue,
148 testScalarValue,
149 testStringName
150 );
151
152#endif // TRAITSTESTS_HPP
expr val()
REGISTER_TYPED_TEST_SUITE_P(TraitsTests, testScalarType, testValueType, testIsADType, testIsScalarType, testValue, testScalarValue, testStringName)
TYPED_TEST_SUITE_P(TraitsTests)
TYPED_TEST_P(TraitsTests, testScalarType)
A random number generator that generates random numbers uniformly distributed in the interval (a,...
Sacado::Random< double > urand
Sacado::mpl::apply< ADType, double >::type ad1_t
Sacado::mpl::apply< ADType, ad1_t >::type ad2_t
#define ASSERT_TRUE(condition)
Definition gtest.h:1985
static const bool value
static const bool value
static SACADO_INLINE_FUNCTION const T & eval(const T &x)
static std::string eval()
static SACADO_INLINE_FUNCTION const T & eval(const T &x)
F::template apply< mpl::none, mpl::none, mpl::none, mpl::none, mpl::none >::type type