test_Set.cpp

00001 /*--------------------------------------------------------------------*/
00002 /*    Copyright 2005 Sandia Corporation.                              */
00003 /*    Under the terms of Contract DE-AC04-94AL85000, there is a       */
00004 /*    non-exclusive license for use of this work by or on behalf      */
00005 /*    of the U.S. Government.  Export of this program may require     */
00006 /*    a license from the United States Government.                    */
00007 /*--------------------------------------------------------------------*/
00008 
00009 #include <fei_macros.hpp>
00010 #include <fei_mpi.h>
00011 
00012 #include <test_utils/test_Set.hpp>
00013 
00014 #include <snl_fei_Utils.hpp>
00015 #include <fei_ctg_set.hpp>
00016 
00017 #undef fei_file
00018 #define fei_file "test_Set.cpp"
00019 #include <fei_ErrMacros.hpp>
00020 
00021 test_Set::test_Set(MPI_Comm comm)
00022  : tester(comm)
00023 {
00024 }
00025 
00026 test_Set::~test_Set()
00027 {
00028 }
00029 
00030 template<typename SET_TYPE>
00031 void set_test1(SET_TYPE& set_obj)
00032 {
00033   if (set_obj.size() < 1) {
00034     typename SET_TYPE::const_iterator
00035       s_beg = set_obj.begin(),
00036       s_end = set_obj.end();
00037 
00038     if (s_beg != s_end) {
00039       throw std::runtime_error("failed test 1");
00040     }
00041   }
00042   else set_obj.clear();
00043 
00044   std::pair<typename SET_TYPE::const_iterator,bool> result = set_obj.insert(5);
00045 
00046   if (!result.second) {
00047     throw std::runtime_error("failed test 2");
00048   }
00049 
00050   result = set_obj.insert(4);
00051 
00052   if (!result.second) {
00053     throw std::runtime_error("failed test 3");
00054   }
00055 
00056   result = set_obj.insert(7);
00057 
00058   ++(result.first);
00059   if (result.first != set_obj.end()) {
00060     throw std::runtime_error("failed test 4");
00061   }
00062 
00063   result = set_obj.insert(6);
00064 
00065   if (!result.second) {
00066     throw std::runtime_error("failed test 5");
00067   }
00068 
00069   ++(result.first);
00070 
00071   if (*(result.first) != 7) {
00072     throw std::runtime_error("failed test 6");
00073   }
00074 
00075   ++(result.first);
00076   if (result.first != set_obj.end()) {
00077     throw std::runtime_error("failed test 7");
00078   }
00079 
00080   result = set_obj.insert(2);
00081   result = set_obj.insert(3);
00082 
00083   ++(result.first);
00084   if (*(result.first) != 4) {
00085     throw std::runtime_error("failed test 8");
00086   }
00087 
00088   SET_TYPE set_copy(set_obj);
00089 
00090   if (set_copy.size() != set_obj.size()) {
00091     throw std::runtime_error("failed test 9");
00092   }
00093 
00094   typename SET_TYPE::const_iterator
00095     s_iter = set_obj.begin(),
00096     s_end = set_obj.end();
00097 
00098   typename SET_TYPE::const_iterator
00099     c_iter = set_copy.begin(),
00100     c_end = set_copy.end();
00101 
00102   for(; s_iter != s_end; ++s_iter) {
00103     if (*s_iter != *c_iter) {
00104       throw std::runtime_error("failed test 10");
00105     }
00106     ++c_iter;
00107   }
00108 
00109   if (c_iter != c_end) {
00110     throw std::runtime_error("failed test 11");
00111   }
00112 }
00113 
00114 template<typename SET_TYPE>
00115 void set_test2(SET_TYPE& set_obj)
00116 {
00117   if (set_obj.size() < 1) {
00118     typename SET_TYPE::const_iterator
00119       s_beg = set_obj.begin(),
00120       s_end = set_obj.end();
00121 
00122     if (s_beg != s_end) {
00123       throw std::runtime_error("failed test2 1");
00124     }
00125   }
00126   else set_obj.clear();
00127 
00128   set_obj.insert2(5);
00129   set_obj.insert2(4);
00130   set_obj.insert2(7);
00131   set_obj.insert2(6);
00132   set_obj.insert2(2);
00133   set_obj.insert2(3);
00134 
00135   SET_TYPE set_copy(set_obj);
00136 
00137   if (set_copy.size() != set_obj.size()) {
00138     throw std::runtime_error("failed test2 2");
00139   }
00140 
00141   typename SET_TYPE::const_iterator
00142     s_iter = set_obj.begin(),
00143     s_end = set_obj.end();
00144 
00145   typename SET_TYPE::const_iterator
00146     c_iter = set_copy.begin(),
00147     c_end = set_copy.end();
00148 
00149   for(; s_iter != s_end; ++s_iter) {
00150     if (*s_iter != *c_iter) {
00151       throw std::runtime_error("failed test2 3");
00152     }
00153     ++c_iter;
00154   }
00155 
00156   if (c_iter != c_end) {
00157     throw std::runtime_error("failed test2 4");
00158   }
00159 }
00160 
00161 int test_Set::runtests()
00162 {
00163   if (numProcs_ > 1) return(0);
00164 
00165   CHK_ERR( test1() );
00166   CHK_ERR( test2() );
00167   CHK_ERR( test3() );
00168   CHK_ERR( test4() );
00169   CHK_ERR( test5() );
00170   CHK_ERR( test6() );
00171   CHK_ERR( test7() );
00172   CHK_ERR( test8() );
00173   CHK_ERR( test9() );
00174 
00175   return(0);
00176 }
00177 
00178 int test_Set::test1()
00179 {
00180   return(0);
00181 }
00182 
00183 int test_Set::test2()
00184 {
00185   FEI_COUT << "testing fei::ctg_set<int> insert,insert2,find,iterate...";
00186   fei::ctg_set<int> sset2;
00187 
00188   sset2.insert(5);
00189   sset2.insert(8);
00190   sset2.insert(3);
00191   sset2.insert(0);
00192   sset2.insert(4);
00193   sset2.insert(1);
00194   sset2.insert(2);
00195 
00196   fei::ctg_set<int>::const_iterator
00197     ss2_iter = sset2.begin(),
00198     ss2_end = sset2.end();
00199 
00200   int i=0;
00201   for(; ss2_iter != ss2_end; ++ss2_iter) {
00202     if (*ss2_iter != i && *ss2_iter != 8) {
00203       return(-1);
00204     }
00205     ++i;
00206   }
00207 
00208   int size2 = sset2.size();
00209   if (size2 != 7) {
00210     return(-1);
00211   }
00212 
00213   fei::ctg_set<int>::const_iterator iter4 = sset2.find(4);
00214   if (*iter4 != 4) {
00215     return(-2);
00216   }
00217 
00218   ++iter4;
00219   if (*iter4 != 5) {
00220     return(-3);
00221   }
00222 
00223   fei::ctg_set<int>::const_iterator iter8 = sset2.find(8);
00224   if (*iter8 != 8) {
00225     return(-4);
00226   }
00227 
00228   set_test2(sset2);
00229 
00230   fei::ctg_set<int> sset3;
00231 
00232   sset3.insert2(1);
00233   sset3.insert2(3);
00234   sset3.insert2(6);
00235   sset3.insert2(8);
00236   sset3.insert2(0);
00237   sset3.insert2(2);
00238   sset3.insert2(9);
00239   sset3.insert2(11);
00240   sset3.insert2(4);
00241   sset3.insert2(10);
00242 
00243   int size3 = sset3.size();
00244   if (size3 != 10) {
00245     return(-1);
00246   }
00247 
00248   fei::ctg_set<int>::const_iterator ss3_iter4 = sset3.find(4);
00249   if (*ss3_iter4 != 4) {
00250     return(-2);
00251   }
00252 
00253   ++ss3_iter4;
00254   if (*ss3_iter4 != 6) {
00255     return(-3);
00256   }
00257 
00258   fei::ctg_set<int>::const_iterator ss3_iter8 = sset3.find(8);
00259   if (*ss3_iter8 != 8) {
00260     return(-4);
00261   }
00262 
00263   FEI_COUT << "ok"<<FEI_ENDL;
00264   return(0);
00265 }
00266 
00267 int test_Set::test3()
00268 {
00269   return(0);
00270 }
00271 
00272 int test_Set::test4()
00273 {
00274 
00275   return(0);
00276 }
00277 
00278 int test_Set::test5()
00279 {
00280   FEI_COUT << "testing fei::binarySearch(...,start,end,...)...";
00281 
00282   std::vector<int> array;
00283   for(int i=0; i<10; ++i) array.push_back(i);
00284 
00285   int start = 2;
00286   int end = 6;
00287   int insertPoint = -1;
00288   int offset = fei::binarySearch(9, &array[0], array.size(),
00289              start, end, insertPoint);
00290   if (offset >= 0) {
00291     return(-1);
00292   }
00293 
00294   offset = fei::binarySearch(4, &array[0], array.size(),
00295          start, end, insertPoint);
00296 
00297   if (offset < 0) {
00298     return(-1);
00299   }
00300 
00301   fei::ctg_set<int> sset;
00302   sset.insert2(1);
00303   sset.insert2(5);
00304   sset.insert2(9);
00305   sset.insert2(0);
00306   sset.insert2(4);
00307   sset.insert2(8);
00308 
00309   if (sset.size() != 6) {
00310     ERReturn(-1);
00311   }
00312 
00313   if (sset.find(0) == sset.end()) {
00314     ERReturn(-1);
00315   }
00316 
00317   FEI_COUT << "ok"<<FEI_ENDL;
00318 
00319   return(0);
00320 }
00321 
00322 int test_Set::test6()
00323 {
00324   return(0);
00325 }
00326 
00327 int test_Set::test7()
00328 {
00329   return(0);
00330 }
00331 
00332 
00333 int test_Set::test8()
00334 {
00335   return(0);
00336 }
00337 
00338 int test_Set::test9()
00339 {
00340 
00341   return(0);
00342 }

Generated on Tue Jul 13 09:27:46 2010 for FEI by  doxygen 1.4.7