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 // Sacado Package
4 //
5 // Copyright 2006 NTESS and the Sacado contributors.
6 // SPDX-License-Identifier: LGPL-2.1-or-later
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef TRAITSTESTS_HPP
11 #define TRAITSTESTS_HPP
12 
13 #include <type_traits>
14 
15 // Sacado includes
16 #include "Sacado_No_Kokkos.hpp"
17 #include "Sacado_Random.hpp"
18 #include "Sacado_mpl_apply.hpp"
19 
20 // gtest includes
21 #include <gtest/gtest.h>
22 
23 // A class for testing Sacado::Traits definitions for Sacado AD types
24 template <class ADType>
25 class TraitsTests : public ::testing::Test {
26 protected:
27 
30 
31  // Random number generator
33 
34  // GTest creates the test fixture as a child class, so ad1_t, ad2_t are
35  // not visible. Create some data members of these types to get the types
36  // in the test cases
39 
40  TraitsTests() : urand(), ad1(), ad2() {}
42 
43 }; // class TraitsTests
44 
46 
47 TYPED_TEST_P(TraitsTests, testScalarType) {
48  typedef decltype(this->ad1) ad1_t;
49  typedef decltype(this->ad2) ad2_t;
50 
51  bool same = std::is_same< typename Sacado::ScalarType<ad1_t>::type, double >::value;
52  ASSERT_TRUE(same == true);
53 
54 same = std::is_same< typename Sacado::ScalarType<ad2_t>::type,double >::value;
55  ASSERT_TRUE(same == true);
56 }
57 
58 TYPED_TEST_P(TraitsTests, testValueType) {
59  typedef decltype(this->ad1) ad1_t;
60  typedef decltype(this->ad2) ad2_t;
61 
62  bool same = std::is_same< typename Sacado::ValueType<ad1_t>::type,double >::value;
63  ASSERT_TRUE(same == true);
64 
65  same = std::is_same< typename Sacado::ValueType<ad2_t>::type,ad1_t >::value;
66  ASSERT_TRUE(same == true);
67 }
68 
69 TYPED_TEST_P(TraitsTests, testIsADType) {
70  typedef decltype(this->ad1) ad1_t;
71  typedef decltype(this->ad2) ad2_t;
72 
75 }
76 
77 TYPED_TEST_P(TraitsTests, testIsScalarType) {
78  typedef decltype(this->ad1) ad1_t;
79  typedef decltype(this->ad2) ad2_t;
80 
83 }
84 
86  typedef decltype(this->ad1) ad1_t;
87  typedef decltype(this->ad2) ad2_t;
88 
89  double val = this->urand.number();
90  ad1_t a(val);
92 
93  ad2_t b(a);
95 }
96 
97 TYPED_TEST_P(TraitsTests, testScalarValue) {
98  typedef decltype(this->ad1) ad1_t;
99  typedef decltype(this->ad2) ad2_t;
100 
101  double val = this->urand.number();
102  ad1_t a(val);
104 
105  ad2_t b(a);
107 }
108 
109 TYPED_TEST_P(TraitsTests, testStringName) {
110  typedef decltype(this->ad1) ad1_t;
111  typedef decltype(this->ad2) ad2_t;
112 
113  // Currently we can't check the string name, here we are just making sure
114  // it compiles
117  // ASSERT_TRUE(Sacado::StringName<ad1_t>::eval() == name + "< double, double >");
118  // ASSERT_TRUE(Sacado::StringName<ad2_t>::eval() == name + "< " + name + "< double, double >, double >");
119 }
120 
122  TraitsTests,
123  testScalarType,
124  testValueType,
125  testIsADType,
126  testIsScalarType,
127  testValue,
128  testScalarValue,
129  testStringName
130  );
131 
132 #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:28
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:29
Sacado::Random< double > urand
Definition: TraitsTests.hpp:32
int value
TYPED_TEST_SUITE_P(FadBLASUnitTests)
Base template specification for IsScalarType.