00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
00065
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 }