Sacado Package Browser (Single Doxygen Collection)  Version of the Day
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 // Sacado includes
34 #include "Sacado_No_Kokkos.hpp"
35 #include "Sacado_Random.hpp"
36 #include "Sacado_mpl_apply.hpp"
37 #include "Sacado_mpl_is_same.hpp"
38 
39 // gtest includes
40 #include <gtest/gtest.h>
41 
42 // A class for testing Sacado::Traits definitions for Sacado AD types
43 template <class ADType>
44 class TraitsTests : public ::testing::Test {
45 protected:
46 
49 
50  // Random number generator
52 
53  // GTest creates the test fixture as a child class, so ad1_t, ad2_t are
54  // not visible. Create some data members of these types to get the types
55  // in the test cases
58 
59  TraitsTests() : urand(), ad1(), ad2() {}
61 
62 }; // class TraitsTests
63 
65 
66 TYPED_TEST_P(TraitsTests, testScalarType) {
67  typedef decltype(this->ad1) ad1_t;
68  typedef decltype(this->ad2) ad2_t;
69 
71  ASSERT_TRUE(same == true);
72 
74  ASSERT_TRUE(same == true);
75 }
76 
77 TYPED_TEST_P(TraitsTests, testValueType) {
78  typedef decltype(this->ad1) ad1_t;
79  typedef decltype(this->ad2) ad2_t;
80 
82  ASSERT_TRUE(same == true);
83 
85  ASSERT_TRUE(same == true);
86 }
87 
88 TYPED_TEST_P(TraitsTests, testIsADType) {
89  typedef decltype(this->ad1) ad1_t;
90  typedef decltype(this->ad2) ad2_t;
91 
94 }
95 
96 TYPED_TEST_P(TraitsTests, testIsScalarType) {
97  typedef decltype(this->ad1) ad1_t;
98  typedef decltype(this->ad2) ad2_t;
99 
102 }
103 
105  typedef decltype(this->ad1) ad1_t;
106  typedef decltype(this->ad2) ad2_t;
107 
108  double val = this->urand.number();
109  ad1_t a(val);
111 
112  ad2_t b(a);
114 }
115 
116 TYPED_TEST_P(TraitsTests, testScalarValue) {
117  typedef decltype(this->ad1) ad1_t;
118  typedef decltype(this->ad2) ad2_t;
119 
120  double val = this->urand.number();
121  ad1_t a(val);
123 
124  ad2_t b(a);
126 }
127 
128 TYPED_TEST_P(TraitsTests, testStringName) {
129  typedef decltype(this->ad1) ad1_t;
130  typedef decltype(this->ad2) ad2_t;
131 
132  // Currently we can't check the string name, here we are just making sure
133  // it compiles
136  // ASSERT_TRUE(Sacado::StringName<ad1_t>::eval() == name + "< double, double >");
137  // ASSERT_TRUE(Sacado::StringName<ad2_t>::eval() == name + "< " + name + "< double, double >, double >");
138 }
139 
141  TraitsTests,
142  testScalarType,
143  testValueType,
144  testIsADType,
145  testIsScalarType,
146  testValue,
147  testScalarValue,
148  testStringName
149  );
150 
151 #endif // TRAITSTESTS_HPP
static std::string eval()
Base template specification for ScalarValue.
REGISTER_TYPED_TEST_SUITE_P(TraitsTests, testScalarType, testValueType, testIsADType, testIsScalarType, testValue, testScalarValue, testStringName)
Sacado::mpl::apply< ADType, double >::type ad1_t
Definition: TraitsTests.hpp:47
Base template specification for IsADType.
Base template specification for Value.
lambda< F >::type ::template apply< A1, A2, A3, A4, A5 >::type type
expr val()
TYPED_TEST_P(TraitsTests, testScalarType)
Definition: TraitsTests.hpp:66
#define ASSERT_TRUE(condition)
Definition: gtest.h:1985
Sacado::mpl::apply< ADType, ad1_t >::type ad2_t
Definition: TraitsTests.hpp:48
Sacado::Random< double > urand
Definition: TraitsTests.hpp:51
int value
TYPED_TEST_SUITE_P(TraitsTests)
Base template specification for IsScalarType.