Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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
44 template <class ADType>
45 class TraitsTests : public ::testing::Test {
46 protected:
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 
67 TYPED_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 
74 same = std::is_same< typename Sacado::ScalarType<ad2_t>::type,double >::value;
75  ASSERT_TRUE(same == true);
76 }
77 
78 TYPED_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 
89 TYPED_TEST_P(TraitsTests, testIsADType) {
90  typedef decltype(this->ad1) ad1_t;
91  typedef decltype(this->ad2) ad2_t;
92 
95 }
96 
97 TYPED_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 
117 TYPED_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 
129 TYPED_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 
142  TraitsTests,
143  testScalarType,
144  testValueType,
145  testIsADType,
146  testIsScalarType,
147  testValue,
148  testScalarValue,
149  testStringName
150  );
151 
152 #endif // TRAITSTESTS_HPP
REGISTER_TYPED_TEST_SUITE_P(FadBLASUnitTests, testSCAL1, testSCAL2, testSCAL3, testSCAL4, testCOPY1, testCOPY2, testCOPY3, testCOPY4, testAXPY1, testAXPY2, testAXPY3, testAXPY4, testDOT1, testDOT2, testDOT3, testDOT4, testNRM21, testNRM22, testGEMV1, testGEMV2, testGEMV3, testGEMV4, testGEMV5, testGEMV6, testGEMV7, testGEMV8, testGEMV9, testTRMV1, testTRMV2, testTRMV3, testTRMV4, testGER1, testGER2, testGER3, testGER4, testGER5, testGER6, testGER7, testGEMM1, testGEMM2, testGEMM3, testGEMM4, testGEMM5, testGEMM6, testGEMM7, testGEMM8, testGEMM9, testGEMM10, testSYMM1, testSYMM2, testSYMM3, testSYMM4, testSYMM5, testSYMM6, testSYMM7, testSYMM8, testSYMM9, testTRMM1, testTRMM2, testTRMM3, testTRMM4, testTRMM5, testTRMM6, testTRMM7, testTRSM1, testTRSM2, testTRSM3, testTRSM4, testTRSM5, testTRSM6, testTRSM7)
static std::string eval()
TYPED_TEST_P(FadBLASUnitTests, testSCAL1)
Base template specification for ScalarValue.
Sacado::mpl::apply< ADType, double >::type ad1_t
Definition: TraitsTests.hpp:48
Base template specification for IsADType.
Base template specification for Value.
F::template apply< A1, A2, A3, A4, A5 >::type type
expr val()
#define ASSERT_TRUE(condition)
Definition: gtest.h:1985
Sacado::mpl::apply< ADType, ad1_t >::type ad2_t
Definition: TraitsTests.hpp:49
Sacado::Random< double > urand
Definition: TraitsTests.hpp:52
int value
TYPED_TEST_SUITE_P(FadBLASUnitTests)
Base template specification for IsScalarType.