Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

test-random_string_generator_algorithm.cc

00001 /*
00002 *  Name:      test-regular_expression_matcher.cc
00003 *  Author:    Rafael Jesus Alcantara Perez
00004 *  Summary:   Test for random string generator class
00005 *  Date:      $Date: 2003/04/14 00:18:36 $
00006 *  Revision:  $Revision: 1.1 $
00007 *
00008 *  Copyright (C) 2000-2002  Rafael Jesus Alcantara Perez <rafa@dedalo-ing.com>
00009 *
00010 *  This program is free software; you can redistribute it and/or modify
00011 *  it under the terms of the GNU General Public License as published by
00012 *  the Free Software Foundation; either version 2 of the License, or
00013 *  (at your option) any later version.
00014 *
00015 *  This program is distributed in the hope that it will be useful,
00016 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 *  GNU General Public License for more details.
00019 *
00020 *  You should have received a copy of the GNU General Public License
00021 *  along with this program; if not, write to the Free Software
00022 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00023 *  MA 02111-1307, USA.
00024 */
00025 
00026 #include <cmath>
00027 #include <cstring>
00028 #include <ctime>
00029 #include <mpcl/util/strategy/random_string_generator.hh>
00030 #include <mpcl/test.h>
00031 
00032 
00034 int main (void)
00035 {
00036 
00037   using mpcl::text::TString;
00038   using mpcl::util::strategy::TRandomStringGenerator;
00039   using std::fabs;
00040   using std::strlen;
00041 
00042   TEST_INIT ("tests for class 'TRandomStringGenerator'");
00043 
00044   double                   dError;
00045   double                   dModel;
00046   TString                  yManyChars;
00047   long unsigned int        luiIterations = 100000;
00048   const char*              pkcAlphabet   = "abcdefghijklmnopqrstuvwxyz0123456789";
00049   TRandomStringGenerator   tRandomStringGenerator (pkcAlphabet);
00050   
00051   std::srand ((unsigned int) std::time (NULL));
00052   for (int I = 0; ( I < 1000 ) ;++I)
00053   {
00054     TEST_NUMBERS (8, tRandomStringGenerator.execute (8).size());
00055     TEST_NUMBERS (1, tRandomStringGenerator.execute (1).size());
00056     TEST_NUMBERS (0, tRandomStringGenerator.execute (0).size());
00057   }
00058   for (long unsigned int I = 0; ( I < luiIterations ) ;++I)
00059   {
00060     yManyChars.append (tRandomStringGenerator.execute (1));
00061   }
00062 
00063   //
00064   //  Variable \a dModel will hold the perfect number of appearances of each
00065   //  symbol.  And \a dError  will hold the  maximum error  permitted (10%).
00066   //
00067   dModel = ((double) luiIterations) / strlen (pkcAlphabet);
00068   dError = 0.10 * dModel;
00069   TEST_NUMBERS (true, ( dError >= fabs (yManyChars.occurrences ('a') - dModel) ));
00070   TEST_NUMBERS (true, ( dError >= fabs (yManyChars.occurrences ('b') - dModel) ));
00071   TEST_NUMBERS (true, ( dError >= fabs (yManyChars.occurrences ('c') - dModel) ));
00072   TEST_NUMBERS (true, ( dError >= fabs (yManyChars.occurrences ('d') - dModel) ));
00073   TEST_NUMBERS (true, ( dError >= fabs (yManyChars.occurrences ('e') - dModel) ));
00074   TEST_NUMBERS (true, ( dError >= fabs (yManyChars.occurrences ('f') - dModel) ));
00075   TEST_NUMBERS (true, ( dError >= fabs (yManyChars.occurrences ('g') - dModel) ));
00076   TEST_NUMBERS (true, ( dError >= fabs (yManyChars.occurrences ('h') - dModel) ));
00077   TEST_NUMBERS (true, ( dError >= fabs (yManyChars.occurrences ('i') - dModel) ));
00078   TEST_NUMBERS (true, ( dError >= fabs (yManyChars.occurrences ('j') - dModel) ));
00079   TEST_NUMBERS (true, ( dError >= fabs (yManyChars.occurrences ('k') - dModel) ));
00080   TEST_NUMBERS (true, ( dError >= fabs (yManyChars.occurrences ('l') - dModel) ));
00081   TEST_NUMBERS (true, ( dError >= fabs (yManyChars.occurrences ('m') - dModel) ));
00082   TEST_NUMBERS (true, ( dError >= fabs (yManyChars.occurrences ('n') - dModel) ));
00083   TEST_NUMBERS (true, ( dError >= fabs (yManyChars.occurrences ('o') - dModel) ));
00084   TEST_NUMBERS (true, ( dError >= fabs (yManyChars.occurrences ('p') - dModel) ));
00085   TEST_NUMBERS (true, ( dError >= fabs (yManyChars.occurrences ('q') - dModel) ));
00086   TEST_NUMBERS (true, ( dError >= fabs (yManyChars.occurrences ('r') - dModel) ));
00087   TEST_NUMBERS (true, ( dError >= fabs (yManyChars.occurrences ('s') - dModel) ));
00088   TEST_NUMBERS (true, ( dError >= fabs (yManyChars.occurrences ('t') - dModel) ));
00089   TEST_NUMBERS (true, ( dError >= fabs (yManyChars.occurrences ('u') - dModel) ));
00090   TEST_NUMBERS (true, ( dError >= fabs (yManyChars.occurrences ('v') - dModel) ));
00091   TEST_NUMBERS (true, ( dError >= fabs (yManyChars.occurrences ('w') - dModel) ));
00092   TEST_NUMBERS (true, ( dError >= fabs (yManyChars.occurrences ('x') - dModel) ));
00093   TEST_NUMBERS (true, ( dError >= fabs (yManyChars.occurrences ('y') - dModel) ));
00094   TEST_NUMBERS (true, ( dError >= fabs (yManyChars.occurrences ('z') - dModel) ));
00095   TEST_NUMBERS (true, ( dError >= fabs (yManyChars.occurrences ('0') - dModel) ));
00096   TEST_NUMBERS (true, ( dError >= fabs (yManyChars.occurrences ('1') - dModel) ));
00097   TEST_NUMBERS (true, ( dError >= fabs (yManyChars.occurrences ('2') - dModel) ));
00098   TEST_NUMBERS (true, ( dError >= fabs (yManyChars.occurrences ('3') - dModel) ));
00099   TEST_NUMBERS (true, ( dError >= fabs (yManyChars.occurrences ('4') - dModel) ));
00100   TEST_NUMBERS (true, ( dError >= fabs (yManyChars.occurrences ('5') - dModel) ));
00101   TEST_NUMBERS (true, ( dError >= fabs (yManyChars.occurrences ('6') - dModel) ));
00102   TEST_NUMBERS (true, ( dError >= fabs (yManyChars.occurrences ('7') - dModel) ));
00103   TEST_NUMBERS (true, ( dError >= fabs (yManyChars.occurrences ('8') - dModel) ));
00104   TEST_NUMBERS (true, ( dError >= fabs (yManyChars.occurrences ('9') - dModel) ));
00105 
00106   TEST_MEMORY_STATUS;
00107   TEST_RETURN_CODE;
00108 
00109 }  // main()

Generated on Mon Oct 13 02:35:24 2003 for MPCL by doxygen1.2.18