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 }; // class TraitsTests
86 
87 template <class ADType>
90  urand()
91 {
92 }
93 
94 template <class ADType>
95 void
99  CPPUNIT_ASSERT(same == true);
100 
102  CPPUNIT_ASSERT(same == true);
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
120  CPPUNIT_ASSERT(Sacado::IsADType<ad1_t>::value == true);
121  CPPUNIT_ASSERT(Sacado::IsADType<ad2_t>::value == true);
122 }
123 
124 template <class ADType>
125 void
128  CPPUNIT_ASSERT(Sacado::IsScalarType<ad1_t>::value == false);
129  CPPUNIT_ASSERT(Sacado::IsScalarType<ad2_t>::value == false);
130 }
131 
132 template <class ADType>
133 void
136  double val = urand.number();
137  ad1_t a(val);
138  CPPUNIT_ASSERT(Sacado::Value<ad1_t>::eval(a) == val);
139 
140  ad2_t b(a);
141  CPPUNIT_ASSERT(Sacado::Value<ad2_t>::eval(b) == a);
142 }
143 
144 template <class ADType>
145 void
148  double val = urand.number();
149  ad1_t a(val);
150  CPPUNIT_ASSERT(Sacado::ScalarValue<ad1_t>::eval(a) == val);
151 
152  ad2_t b(a);
153  CPPUNIT_ASSERT(Sacado::ScalarValue<ad2_t>::eval(b) == val);
154 }
155 
156 template <class ADType>
157 void
160  // Currently we can't check the string name, here we are just making sure
161  // it compiles
164  // CPPUNIT_ASSERT(Sacado::StringName<ad1_t>::eval() == name + "< double, double >");
165  // CPPUNIT_ASSERT(Sacado::StringName<ad2_t>::eval() == name + "< " + name + "< double, double >, double >");
166 }
167 
168 #endif // TRAITSTESTS_HPP
void setUp()
Definition: TraitsTests.hpp:65
void testScalarType()
Definition: TraitsTests.hpp:97
static std::string eval()
Base template specification for ScalarValue.
void testIsScalarType()
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.
void testStringName()
void testScalarValue()