Sacado Package Browser (Single Doxygen Collection)
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
test
GTestSuite
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
48
typedef
typename
Sacado::mpl::apply<ADType,double>::type
ad1_t
;
49
typedef
typename
Sacado::mpl::apply<ADType,ad1_t>::type
ad2_t
;
50
51
// Random number generator
52
Sacado::Random<double>
urand
;
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
57
ad1_t
ad1
;
58
ad2_t
ad2
;
59
60
TraitsTests
() :
urand
(),
ad1
(),
ad2
() {}
61
~TraitsTests
() {}
62
63
};
// class TraitsTests
64
65
TYPED_TEST_SUITE_P
(
TraitsTests
);
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
93
ASSERT_TRUE
(
Sacado::IsADType<ad1_t>::value
==
true
);
94
ASSERT_TRUE
(
Sacado::IsADType<ad2_t>::value
==
true
);
95
}
96
97
TYPED_TEST_P
(
TraitsTests
, testIsScalarType) {
98
typedef
decltype
(this->ad1) ad1_t;
99
typedef
decltype
(this->ad2) ad2_t;
100
101
ASSERT_TRUE
(
Sacado::IsScalarType<ad1_t>::value
==
false
);
102
ASSERT_TRUE
(
Sacado::IsScalarType<ad2_t>::value
==
false
);
103
}
104
105
TYPED_TEST_P
(
TraitsTests
, testValue) {
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
);
111
ASSERT_TRUE
(
Sacado::Value<ad1_t>::eval
(
a
) ==
val
);
112
113
ad2_t b(
a
);
114
ASSERT_TRUE
(
Sacado::Value<ad2_t>::eval
(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
);
123
ASSERT_TRUE
(
Sacado::ScalarValue<ad1_t>::eval
(
a
) ==
val
);
124
125
ad2_t b(
a
);
126
ASSERT_TRUE
(
Sacado::ScalarValue<ad2_t>::eval
(b) ==
val
);
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
135
Sacado::StringName<ad1_t>::eval
();
136
Sacado::StringName<ad2_t>::eval
();
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
141
REGISTER_TYPED_TEST_SUITE_P
(
142
TraitsTests
,
143
testScalarType,
144
testValueType,
145
testIsADType,
146
testIsScalarType,
147
testValue,
148
testScalarValue,
149
testStringName
150
);
151
152
#endif
// TRAITSTESTS_HPP
a
a
Definition
Sacado_CacheFad_Ops.hpp:426
val
expr val()
Sacado_No_Kokkos.hpp
Sacado_Random.hpp
Sacado_mpl_apply.hpp
REGISTER_TYPED_TEST_SUITE_P
REGISTER_TYPED_TEST_SUITE_P(TraitsTests, testScalarType, testValueType, testIsADType, testIsScalarType, testValue, testScalarValue, testStringName)
TYPED_TEST_SUITE_P
TYPED_TEST_SUITE_P(TraitsTests)
TYPED_TEST_P
TYPED_TEST_P(TraitsTests, testScalarType)
Definition
TraitsTests.hpp:67
Sacado::Random
A random number generator that generates random numbers uniformly distributed in the interval (a,...
Definition
Sacado_Random.hpp:46
TraitsTests
Definition
TraitsTests.hpp:45
TraitsTests::ad2
ad2_t ad2
Definition
TraitsTests.hpp:58
TraitsTests::urand
Sacado::Random< double > urand
Definition
TraitsTests.hpp:52
TraitsTests::~TraitsTests
~TraitsTests()
Definition
TraitsTests.hpp:61
TraitsTests::ad1
ad1_t ad1
Definition
TraitsTests.hpp:57
TraitsTests::ad1_t
Sacado::mpl::apply< ADType, double >::type ad1_t
Definition
TraitsTests.hpp:48
TraitsTests::ad2_t
Sacado::mpl::apply< ADType, ad1_t >::type ad2_t
Definition
TraitsTests.hpp:49
TraitsTests::TraitsTests
TraitsTests()
Definition
TraitsTests.hpp:60
testing::Test
Definition
gtest.h:414
gtest.h
ASSERT_TRUE
#define ASSERT_TRUE(condition)
Definition
gtest.h:1985
Sacado::IsADType::value
static const bool value
Definition
Sacado_Traits.hpp:338
Sacado::IsScalarType::value
static const bool value
Definition
Sacado_Traits.hpp:347
Sacado::ScalarValue::eval
static SACADO_INLINE_FUNCTION const T & eval(const T &x)
Definition
Sacado_Traits.hpp:384
Sacado::StringName::eval
static std::string eval()
Definition
Sacado_Traits.hpp:411
Sacado::Value::eval
static SACADO_INLINE_FUNCTION const T & eval(const T &x)
Definition
Sacado_Traits.hpp:365
Sacado::mpl::apply_wrap5< F, mpl::none, mpl::none, mpl::none, mpl::none, mpl::none >::type
F::template apply< mpl::none, mpl::none, mpl::none, mpl::none, mpl::none >::type type
Definition
Sacado_mpl_apply_wrap.hpp:84
Generated by
1.17.0