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 // $Id$
2 // $Source$
3 // @HEADER
4 // ***********************************************************************
5 //
6 // Sacado Package
7 // Copyright (2006) Sandia Corporation
8 //
9 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
10 // the U.S. Government retains certain rights in this software.
11 //
12 // This library is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU Lesser General Public License as
14 // published by the Free Software Foundation; either version 2.1 of the
15 // License, or (at your option) any later version.
16 //
17 // This library is distributed in the hope that it will be useful, but
18 // WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 // Lesser General Public License for more details.
21 //
22 // You should have received a copy of the GNU Lesser General Public
23 // License along with this library; if not, write to the Free Software
24 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
25 // USA
26 // Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
27 // (etphipp@sandia.gov).
28 //
29 // ***********************************************************************
30 // @HEADER
31 
32 #ifndef TRAITSTESTS_HPP
33 #define TRAITSTESTS_HPP
34 
35 // Sacado includes
36 #include "Sacado_No_Kokkos.hpp"
37 #include "Sacado_Random.hpp"
38 #include "Sacado_mpl_apply.hpp"
39 #include "Sacado_mpl_is_same.hpp"
40 
41 // Cppunit includes
42 #include <cppunit/extensions/HelperMacros.h>
43 
44 // A class for testing Sacado::Traits definitions for Sacado AD types
45 template <class ADType>
46 class TraitsTests : public CppUnit::TestFixture {
47 
49 
57 
59 
60 public:
61 
62  TraitsTests();
64 
65  void setUp() {}
66 
67  void tearDown() {}
68 
69  void testScalarType();
70  void testValueType();
71  void testIsADType();
72  void testIsScalarType();
73  void testValue();
74  void testScalarValue();
75  void testStringName();
76 
77 protected:
78 
81 
82  // Random number generator
84 
85  // Memory pools for DMFad
88 
89 }; // class TraitsTests
90 
91 template <class ADType>
94  urand(),
95  poolManager(1),
96  poolManager2(1)
97 {
100 
102  Sacado::Fad::DMFad< Sacado::Fad::DMFad<double> >::setDefaultPool(pool2);
103 }
104 
105 template <class ADType>
106 void
110  CPPUNIT_ASSERT(same == true);
111 
113  CPPUNIT_ASSERT(same == true);
114 }
115 
116 template <class ADType>
117 void
121  CPPUNIT_ASSERT(same == true);
122 
124  CPPUNIT_ASSERT(same == true);
125 }
126 
127 template <class ADType>
128 void
131  CPPUNIT_ASSERT(Sacado::IsADType<ad1_t>::value == true);
132  CPPUNIT_ASSERT(Sacado::IsADType<ad2_t>::value == true);
133 }
134 
135 template <class ADType>
136 void
139  CPPUNIT_ASSERT(Sacado::IsScalarType<ad1_t>::value == false);
140  CPPUNIT_ASSERT(Sacado::IsScalarType<ad2_t>::value == false);
141 }
142 
143 template <class ADType>
144 void
147  double val = urand.number();
148  ad1_t a(val);
149  CPPUNIT_ASSERT(Sacado::Value<ad1_t>::eval(a) == val);
150 
151  ad2_t b(a);
152  CPPUNIT_ASSERT(Sacado::Value<ad2_t>::eval(b) == a);
153 }
154 
155 template <class ADType>
156 void
159  double val = urand.number();
160  ad1_t a(val);
161  CPPUNIT_ASSERT(Sacado::ScalarValue<ad1_t>::eval(a) == val);
162 
163  ad2_t b(a);
164  CPPUNIT_ASSERT(Sacado::ScalarValue<ad2_t>::eval(b) == val);
165 }
166 
167 template <class ADType>
168 void
171  // Currently we can't check the string name, here we are just making sure
172  // it compiles
175  // CPPUNIT_ASSERT(Sacado::StringName<ad1_t>::eval() == name + "< double, double >");
176  // CPPUNIT_ASSERT(Sacado::StringName<ad2_t>::eval() == name + "< " + name + "< double, double >, double >");
177 }
178 
179 #endif // TRAITSTESTS_HPP
MemPool * getMemoryPool(unsigned int dim)
Get memory pool for supplied dimension dim.
void setUp()
Definition: TraitsTests.hpp:65
void testScalarType()
static std::string eval()
Base template specification for ScalarValue.
void testIsScalarType()
Sacado::Fad::MemPoolManager< Sacado::Fad::DMFad< double > > poolManager2
Definition: TraitsTests.hpp:87
Sacado::Fad::MemPoolManager< double > poolManager
Definition: TraitsTests.hpp:86
Sacado::mpl::apply< ADType, double >::type ad1_t
Definition: TraitsTests.hpp:79
CPPUNIT_TEST_SUITE(TraitsTests)
Base template specification for IsADType.
CPPUNIT_TEST(testScalarType)
Base template specification for Value.
F::template apply< A1, A2, A3, A4, A5 >::type type
expr val()
Sacado::mpl::apply< ADType, ad1_t >::type ad2_t
Definition: TraitsTests.hpp:80
void testIsADType()
Sacado::Random< double > urand
Definition: TraitsTests.hpp:83
void testValue()
CPPUNIT_TEST_SUITE_END()
void tearDown()
Definition: TraitsTests.hpp:67
void testValueType()
Base template specification for IsScalarType.
Forward-mode AD class using dynamic memory allocation and expression templates.
void testStringName()
void testScalarValue()