| 1 | /// \ingroup newran |
| 2 | ///@{ |
| 3 | |
| 4 | /// \file tryurng.cpp |
| 5 | /// Test uniform random number generators - main program. |
| 6 | |
| 7 | #define WANT_STREAM |
| 8 | #define WANT_MATH |
| 9 | |
| 10 | #include "include.h" |
| 11 | #include "newran.h" |
| 12 | #include "format.h" |
| 13 | #include "tryurng.h" |
| 14 | #include "utility.h" |
| 15 | #include "test_out.h" |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | int main() |
| 21 | { |
| 22 | |
| 23 | Real* s1; Real* s2; Real* s3; Real* s4; |
| 24 | cout << "\nBegin test\n"; // Forces cout to allocate memory at beginning |
| 25 | cout << "Now print a real number: " << 3.14159265 << endl; |
| 26 | { s1 = new Real[8000]; delete [] s1; } |
| 27 | { s3 = new Real; delete s3;} |
| 28 | |
| 29 | |
| 30 | Try |
| 31 | { |
| 32 | bool copy_seed_from_disk = false; |
| 33 | |
| 34 | |
| 35 | double N = 10000000; |
| 36 | //double N = 100000000; |
| 37 | //double N = 1000000000; |
| 38 | //double N = 5000000000.0; // needs 500 megbytes of memory |
| 39 | cout << endl; |
| 40 | |
| 41 | Random::SetDirectory("c:\\seed\\"); |
| 42 | |
| 43 | if (N < 1000000000) |
| 44 | { |
| 45 | Format FN; FN.FormatType(Format::SCIENTIFIC); |
| 46 | time_lapse tl; // measure program run time |
| 47 | LGM_mixed urng; |
| 48 | cout << "Testing " << urng.Name() << ", N = " << FN << N << endl; |
| 49 | cout << BaseTest::Header << endl; |
| 50 | Random::Set(urng); |
| 51 | if (copy_seed_from_disk) Random::CopySeedFromDisk(true); |
| 52 | test1(N); |
| 53 | } |
| 54 | |
| 55 | if (N < 1000000000) |
| 56 | { |
| 57 | Format FN; FN.FormatType(Format::SCIENTIFIC); |
| 58 | time_lapse tl; // measure program run time |
| 59 | LGM_simple urng; |
| 60 | cout << "Testing " << urng.Name() << ", N = " << FN << N << endl; |
| 61 | cout << BaseTest::Header << endl; |
| 62 | Random::Set(urng); |
| 63 | if (copy_seed_from_disk) Random::CopySeedFromDisk(true); |
| 64 | test1(N); |
| 65 | } |
| 66 | |
| 67 | if (N < 1000000000) |
| 68 | { |
| 69 | Format FN; FN.FormatType(Format::SCIENTIFIC); |
| 70 | time_lapse tl; // measure program run time |
| 71 | FM urng; |
| 72 | cout << "Testing " << urng.Name() << ", N = " << FN << N << endl; |
| 73 | cout << BaseTest::Header << endl; |
| 74 | Random::Set(urng); |
| 75 | if (copy_seed_from_disk) Random::CopySeedFromDisk(true); |
| 76 | test1(N); |
| 77 | } |
| 78 | |
| 79 | { |
| 80 | Format FN; FN.FormatType(Format::SCIENTIFIC); |
| 81 | time_lapse tl; // measure program run time |
| 82 | MT urng; |
| 83 | cout << "Testing " << urng.Name() << ", N = " << FN << N << endl; |
| 84 | cout << BaseTest::Header << endl; |
| 85 | Random::Set(urng); |
| 86 | if (copy_seed_from_disk) Random::CopySeedFromDisk(true); |
| 87 | test1(N); |
| 88 | } |
| 89 | |
| 90 | { |
| 91 | Format FN; FN.FormatType(Format::SCIENTIFIC); |
| 92 | time_lapse tl; // measure program run time |
| 93 | WH urng; |
| 94 | cout << "Testing " << urng.Name() << ", N = " << FN << N << endl; |
| 95 | cout << BaseTest::Header << endl; |
| 96 | Random::Set(urng); |
| 97 | if (copy_seed_from_disk) Random::CopySeedFromDisk(true); |
| 98 | test1(N); |
| 99 | } |
| 100 | |
| 101 | { |
| 102 | Format FN; FN.FormatType(Format::SCIENTIFIC); |
| 103 | time_lapse tl; // measure program run time |
| 104 | MotherOfAll urng; |
| 105 | cout << "Testing " << urng.Name() << ", N = " << FN << N << endl; |
| 106 | cout << BaseTest::Header << endl; |
| 107 | Random::Set(urng); |
| 108 | if (copy_seed_from_disk) Random::CopySeedFromDisk(true); |
| 109 | test1(N); |
| 110 | } |
| 111 | |
| 112 | { |
| 113 | Format FN; FN.FormatType(Format::SCIENTIFIC); |
| 114 | time_lapse tl; // measure program run time |
| 115 | MultWithCarry urng; |
| 116 | cout << "Testing " << urng.Name() << ", N = " << FN << N << endl; |
| 117 | cout << BaseTest::Header << endl; |
| 118 | Random::Set(urng); |
| 119 | if (copy_seed_from_disk) Random::CopySeedFromDisk(true); |
| 120 | test1(N); |
| 121 | } |
| 122 | |
| 123 | Random::SetDirectory(""); |
| 124 | } |
| 125 | Catch(BaseException) |
| 126 | { |
| 127 | cout << "\nTest program fails - exception generated\n\n"; |
| 128 | cout << BaseException::what() << "\n"; |
| 129 | } |
| 130 | CatchAll |
| 131 | { |
| 132 | cout << "\nTest program fails - exception generated\n\n"; |
| 133 | } |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | { s2 = new Real[8000]; delete [] s2; } |
| 139 | cout << "\n(The following memory checks are probably not valid with all\n"; |
| 140 | cout << "compilers - see documentation)\n"; |
| 141 | cout << "\nChecking for lost memory: " |
| 142 | << (unsigned long)s1 << " " << (unsigned long)s2 << " "; |
| 143 | if (s1 != s2) cout << " - error\n"; else cout << " - ok\n"; |
| 144 | { s4 = new Real; delete s4;} |
| 145 | cout << "\nChecking for lost memory: " |
| 146 | << (unsigned long)s3 << " " << (unsigned long)s4 << " "; |
| 147 | if (s3 != s4) cout << " - error\n"; else cout << " - ok\n"; |
| 148 | cout << endl; |
| 149 | |
| 150 | return 0; |
| 151 | } |
| 152 | |
| 153 | |
| 154 | |
| 155 |