TraitsTests.hpp

Go to the documentation of this file.
00001 // $Id$ 
00002 // $Source$ 
00003 // @HEADER
00004 // ***********************************************************************
00005 // 
00006 //                           Sacado Package
00007 //                 Copyright (2006) Sandia Corporation
00008 // 
00009 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00010 // the U.S. Government retains certain rights in this software.
00011 // 
00012 // This library is free software; you can redistribute it and/or modify
00013 // it under the terms of the GNU Lesser General Public License as
00014 // published by the Free Software Foundation; either version 2.1 of the
00015 // License, or (at your option) any later version.
00016 //  
00017 // This library is distributed in the hope that it will be useful, but
00018 // WITHOUT ANY WARRANTY; without even the implied warranty of
00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020 // Lesser General Public License for more details.
00021 //  
00022 // You should have received a copy of the GNU Lesser General Public
00023 // License along with this library; if not, write to the Free Software
00024 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00025 // USA
00026 // Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
00027 // (etphipp@sandia.gov).
00028 // 
00029 // ***********************************************************************
00030 // @HEADER
00031 
00032 #ifndef TRAITSTESTS_HPP
00033 #define TRAITSTESTS_HPP
00034 
00035 // Sacado includes
00036 #include "Sacado.hpp"
00037 #include "Sacado_Random.hpp"
00038 #include "Sacado_mpl_apply.hpp"
00039 #include "Sacado_mpl_is_same.hpp"
00040 
00041 // Cppunit includes
00042 #include <cppunit/extensions/HelperMacros.h>
00043 
00044 // A class for testing Sacado::Traits definitions for Sacado AD types
00045 template <class ADType>
00046 class TraitsTests : public CppUnit::TestFixture {
00047 
00048   CPPUNIT_TEST_SUITE( TraitsTests );
00049   
00050   CPPUNIT_TEST(testScalarType);
00051   CPPUNIT_TEST(testValueType);
00052   CPPUNIT_TEST(testIsADType);
00053   CPPUNIT_TEST(testIsScalarType);
00054   CPPUNIT_TEST(testValue);
00055   CPPUNIT_TEST(testScalarValue);
00056   CPPUNIT_TEST(testStringName);
00057 
00058   CPPUNIT_TEST_SUITE_END();
00059 
00060 public:
00061 
00062   TraitsTests();
00063   ~TraitsTests() {}
00064 
00065   void setUp() {}
00066 
00067   void tearDown() {}
00068 
00069   void testScalarType();
00070   void testValueType();
00071   void testIsADType();
00072   void testIsScalarType();
00073   void testValue();
00074   void testScalarValue();
00075   void testStringName();
00076 
00077 protected:
00078 
00079   typedef typename Sacado::mpl::apply<ADType,double>::type ad1_t;
00080   typedef typename Sacado::mpl::apply<ADType,ad1_t>::type ad2_t;
00081 
00082   // Random number generator
00083   Sacado::Random<double> urand;
00084 
00085   // Memory pools for DMFad
00086   Sacado::Fad::MemPoolManager<double> poolManager;
00087   Sacado::Fad::MemPoolManager< Sacado::Fad::DMFad<double> > poolManager2;
00088 
00089 }; // class TraitsTests
00090 
00091 template <class ADType>
00092 TraitsTests<ADType>::
00093 TraitsTests() :
00094   urand(),
00095   poolManager(1),
00096   poolManager2(1)
00097 {
00098   Sacado::Fad::MemPool *pool = poolManager.getMemoryPool(1);
00099   Sacado::Fad::DMFad<double>::setDefaultPool(pool);
00100 
00101   Sacado::Fad::MemPool *pool2 = poolManager2.getMemoryPool(1);
00102   Sacado::Fad::DMFad< Sacado::Fad::DMFad<double> >::setDefaultPool(pool2);
00103 }
00104 
00105 template <class ADType>
00106 void
00107 TraitsTests<ADType>::
00108 testScalarType() {
00109   bool same = Sacado::mpl::is_same< typename Sacado::ScalarType<ad1_t>::type, double >::value;
00110   CPPUNIT_ASSERT(same == true);
00111   
00112   same = Sacado::mpl::is_same< typename Sacado::ScalarType<ad2_t>::type,double >::value;
00113   CPPUNIT_ASSERT(same == true);
00114 }
00115 
00116 template <class ADType>
00117 void
00118 TraitsTests<ADType>::
00119 testValueType() {
00120   bool same = Sacado::mpl::is_same< typename Sacado::ValueType<ad1_t>::type,double >::value;
00121   CPPUNIT_ASSERT(same == true);
00122 
00123   same = Sacado::mpl::is_same< typename Sacado::ValueType<ad2_t>::type,ad1_t >::value;
00124   CPPUNIT_ASSERT(same == true);
00125 }
00126 
00127 template <class ADType>
00128 void
00129 TraitsTests<ADType>::
00130 testIsADType() {
00131   CPPUNIT_ASSERT(Sacado::IsADType<ad1_t>::value == true);
00132   CPPUNIT_ASSERT(Sacado::IsADType<ad2_t>::value == true);
00133 }
00134 
00135 template <class ADType>
00136 void
00137 TraitsTests<ADType>::
00138 testIsScalarType() {
00139   CPPUNIT_ASSERT(Sacado::IsScalarType<ad1_t>::value == false);
00140   CPPUNIT_ASSERT(Sacado::IsScalarType<ad2_t>::value == false);
00141 }
00142 
00143 template <class ADType>
00144 void
00145 TraitsTests<ADType>::
00146 testValue() {
00147   double val = urand.number();
00148   ad1_t a(val);
00149   CPPUNIT_ASSERT(Sacado::Value<ad1_t>::eval(a) == val);
00150 
00151   ad2_t b(a);
00152   CPPUNIT_ASSERT(Sacado::Value<ad2_t>::eval(b) == a);
00153 }
00154 
00155 template <class ADType>
00156 void
00157 TraitsTests<ADType>::
00158 testScalarValue() {
00159   double val = urand.number();
00160   ad1_t a(val);
00161   CPPUNIT_ASSERT(Sacado::ScalarValue<ad1_t>::eval(a) == val);
00162 
00163   ad2_t b(a);
00164   CPPUNIT_ASSERT(Sacado::ScalarValue<ad2_t>::eval(b) == val);
00165 }
00166 
00167 template <class ADType>
00168 void
00169 TraitsTests<ADType>::
00170 testStringName() {
00171   // Currently we can't check the string name, here we are just making sure
00172   // it compiles
00173   Sacado::StringName<ad1_t>::eval();
00174   Sacado::StringName<ad2_t>::eval();
00175   // CPPUNIT_ASSERT(Sacado::StringName<ad1_t>::eval() == name + "< double, double >");
00176   // CPPUNIT_ASSERT(Sacado::StringName<ad2_t>::eval() == name + "< " + name + "< double, double >, double >");
00177 }
00178 
00179 #endif // TRAITSTESTS_HPP

Generated on Wed May 12 21:39:42 2010 for Sacado Package Browser (Single Doxygen Collection) by  doxygen 1.4.7