00001 #include "config.h"
00002
00003 #include <iostream>
00004 #include <string>
00005 #include <cassert>
00006
00007 #include "types.h"
00008 #include "error.h"
00009 #include "estring.h"
00010 #include "strfmt.h"
00011 #include "rmath.h"
00012 #include "timer.h"
00013
00014
00015 #define ERR_OUT(e)
00016
00017 #define TEST(code) \
00018 try { \
00019 code; \
00020 } \
00021 catch(error e) { \
00022 ERR_OUT(e); \
00023 thrown = true; \
00024 } \
00025 catch(...) { \
00026 assert(0); \
00027 }
00028
00029
00030 void test(void)
00031 {
00032 const uint8 max = max_limit<uint8>();
00033 uint8 x;
00034 std::string s;
00035 std::string last_s;
00036 std::string::size_type s_len;
00037 std::string::size_type idx;
00038 timer t;
00039 int ip;
00040 double dp;
00041
00042 t.start();
00043 for (x = 0; x != max; ++x) {
00044 s = percent_string(x,max);
00045 idx = s.find(".");
00046 s_len = s.size();
00047 if (last_s != s) {
00048 t.stop();
00049 dp = static_cast<double>(x) / static_cast<double>(max);
00050 ip = static_cast<unsigned int>(dp);
00051 std::cerr
00052 << "Test is "
00053 << s
00054 << " complete. ETA: "
00055 << t.eta(ip)
00056 << std::endl;
00057 last_s = s;
00058 }
00059 if (s_len - idx > 3)
00060 std::cerr
00061 << "percent_string("
00062 << static_cast<unsigned int>(x)
00063 << ","
00064 << static_cast<unsigned int>(max)
00065 << ") = "
00066 << s
00067 << std::endl;
00068 }
00069 }
00070
00071 int main(int argc, char const * argv[])
00072 {
00073 try {
00074 test();
00075 }
00076 catch(error e) {
00077 std::cerr << e;
00078 assert(0);
00079 }
00080 catch(...) {
00081 std::cerr << err_unknown;
00082 assert(0);
00083 }
00084 return(0);
00085 }
00086