proj home

Files   Classes   Functions   Hierarchy  

randomtest.cpp

Go to the documentation of this file.
00001 #include <cassert>
00002 #include <list>
00003 #include <iostream>
00004 using namespace std;
00005 
00006 #include <random.h>
00007 #include <randomtest.h>
00008 
00009 
00010 template< typename R >
00011 boolc randomtest::randomcontainer
00012 ( 
00013   list< typename R::Ttype > & lst,
00014   R & r, 
00015   uintc n,
00016   boolc zero,
00017   boolc one 
00018 )
00019 {
00020   for (uint i=0; i<n; ++i)
00021     lst.push_back(r());
00022 
00023   return domaintest(lst,r,zero,one);
00024 }
00025 
00026 template< typename R >
00027 boolc randomtest::domaintest
00028 (
00029   list< typename R::Ttype > & lst,
00030   R const & r, 
00031   boolc zero,
00032   boolc one 
00033 )
00034 {
00035   for 
00036   (
00037     typename list< typename R::Ttype >::iterator i = lst.begin();
00038     i!=lst.end(); i++ 
00039   )
00040   {
00041     if (randomgenerator::domain(*i,zero,one)==false)
00042       return false;
00043   }
00044 
00045   return true;
00046 }
00047 
00048 template< typename R >
00049 boolc randomtest::testprintrandom
00050 ( 
00051   R & r, 
00052   uintc n,
00053   boolc zero,
00054   boolc one  
00055 )
00056 {
00057   list< typename R::Ttype > lst;
00058 
00059   bool res = randomtest::randomcontainer(lst,r,n,zero,one);
00060 
00061   for (
00062     typename list< typename R::Ttype >::iterator i = lst.begin();
00063     i!=lst.end(); i++ )
00064     { cout << *i << " "; }
00065   cout << endl << endl;
00066 
00067   cout << "Removing duplicates to look at sample space." << endl;
00068 
00069   lst.sort();
00070   lst.unique();
00071 
00072   for (
00073     typename list< typename R::Ttype >::iterator i = lst.begin();
00074     i!=lst.end(); i++ )
00075     { cout << *i << " "; }
00076   cout << endl << endl;
00077 
00078   assert(res);
00079 
00080   return res;
00081 }
00082 
00083 int randomtest::test01()
00084 {
00085   cout << endl << "[0,1] interval, n=8" << endl; 
00086   random11<> r(8);
00087   return ! testprintrandom(r,30,true,true);
00088 }
00089 
00090 int randomtest::test02()
00091 {
00092   cout << endl << "(0,1) interval, n=8" << endl;
00093   random00<> r(8);
00094   return ! testprintrandom(r,30,false,false);
00095 }
00096 
00097 int randomtest::test03()
00098 {
00099   cout << endl << "[0,1) interval, n=8" << endl;
00100   random10<> r(8);
00101   return ! testprintrandom(r,30,true,false);
00102 }
00103 
00104 int randomtest::test04()
00105 {
00106   cout << endl << "(0,1] interval, n=8" << endl;
00107   random01<> r(8);
00108   return ! testprintrandom(r,30,false,true);
00109 }
00110 
00111 int randomtest::test05()
00112 {
00113   typedef point2<double> pt2;
00114   typedef point3<double> pt3;
00115 
00116   uint N=100;
00117   bool res=true;
00118 
00119   for (uint i=0; i<N; ++i)
00120   {
00121     pt2 p1 = randompoint<>().makepoint2();
00122 //    cout << SHOW(p1) << endl;
00123     res &= randomgenerator::domain(p1);
00124   }
00125 
00126   for (uint i=0; i<N; ++i)
00127   {
00128     pt2 p1 = randompoint< random01<> >(random01<>(8)).makepoint2();
00129     res &= randomgenerator::domain(p1);
00130   }
00131 
00132   for (uint i=0; i<N; ++i)
00133   {
00134     pt2 p1 = randompoint< random10<> >(random10<>(8)).makepoint2();
00135     res &= randomgenerator::domain(p1);
00136   }
00137 
00138   for (uint i=0; i<N; ++i)
00139   {
00140     pt2 p1 = randompoint< random00<> >(random00<>(16)).makepoint2();
00141     res &= randomgenerator::domain(p1);
00142   }
00143 
00144   for (uint i=0; i<N; ++i)
00145   {
00146     pt3 p1 = randompoint<>().makepoint3();
00147 //    cout << SHOW(p1) << endl;
00148     res &= randomgenerator::domain(p1);
00149   }
00150     
00151   return !res;
00152 }
00153 
00154 void randomtest::test06()
00155 {
00156   uint count=10;
00157   cout << "Repeated list of random numbers each time this program called." << endl;
00158   cout << "Ouput " << count << " rand() numbers" << endl;
00159   for (uint i=0; i<count; ++i)
00160     cout << i << ": " << rand() << endl;
00161 }
00162 
00163 void randomtest::test07()
00164 {
00165   randomgenerator().randomize_start();
00166 
00167   uint count=10;
00168   cout << "Different list of random numbers each time this program called." << endl;
00169   cout << "Ouput " << count << " rand() numbers" << endl;
00170   for (uint i=0; i<count; ++i)
00171     cout << i << ": " << rand() << endl;
00172 }
00173 
00174 
00175 
00176 

Generated on Fri Mar 4 00:49:28 2011 for Chelton Evans Source by  doxygen 1.5.8