astyle --style=ansi

git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@373 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
syntheticpp 2005-11-29 13:20:54 +00:00
parent 3b596259ec
commit fa05da94c0

View file

@ -32,7 +32,8 @@ Integral2 RandomInt(Integral1 low, Integral2 up)
assert(bucket_size > 0); assert(bucket_size > 0);
Integral2 r; Integral2 r;
do r = Integral2(rand() / bucket_size); do
r = Integral2(rand() / bucket_size);
while (r > n); while (r > n);
r += low2; r += low2;
@ -44,17 +45,20 @@ string RandomString(unsigned int maxSize)
{ {
string result(RandomInt(0, maxSize), '\0'); string result(RandomInt(0, maxSize), '\0');
unsigned int i = 0; unsigned int i = 0;
for (; i != result.size(); ++i) { for (; i != result.size(); ++i)
{
result[i] = RandomInt('a', 'z'); result[i] = RandomInt('a', 'z');
} }
return result; return result;
} }
template <class T> template <class T>
void TestCase(const string& fmt, T value) { void TestCase(const string& fmt, T value)
{
char buf[4096]; char buf[4096];
std::string s; std::string s;
const int i1 = SPrintf(s, fmt.c_str())(value); const int i1 = SPrintf(s, fmt.c_str())(value);
#ifdef _MSC_VER #ifdef _MSC_VER
const int i2 = _snprintf(buf, sizeof(buf), fmt.c_str(), value); const int i2 = _snprintf(buf, sizeof(buf), fmt.c_str(), value);
#else #else
@ -74,7 +78,8 @@ void TestCase(const string& fmt, T value) {
} }
template <class T, class U> template <class T, class U>
void TestCase2(const string& fmt, T value, U value2) { void TestCase2(const string& fmt, T value, U value2)
{
char buf[4096]; char buf[4096];
std::string s; std::string s;
const int i1 = SPrintf(s, fmt.c_str())(value)(value2); const int i1 = SPrintf(s, fmt.c_str())(value)(value2);
@ -83,25 +88,31 @@ void TestCase2(const string& fmt, T value, U value2) {
assert(s == buf); assert(s == buf);
} }
int main(int argc, char** argv) { int main(int argc, char** argv)
if (argc == 3) { {
if (argc == 3)
{
// test speed // test speed
int i = atoi(argv[2]); int i = atoi(argv[2]);
switch (argv[1][0]) { switch (argv[1][0])
{
case 'p': case 'p':
for (; i > 0; --i) { for (; i > 0; --i)
{
printf("Hey, %u frobnicators and %u twiddlicators\n", printf("Hey, %u frobnicators and %u twiddlicators\n",
i, i); i, i);
} }
break; break;
case 's': case 's':
for (; i > 0; --i) { for (; i > 0; --i)
{
cout << "Hey, " << i << " frobnicators and " << i << cout << "Hey, " << i << " frobnicators and " << i <<
" twiddlicators\n"; " twiddlicators\n";
} }
break; break;
case 'n': case 'n':
for (; i > 0; --i) { for (; i > 0; --i)
{
Printf("Hey, %u frobnicators and %u twiddlicators\n") Printf("Hey, %u frobnicators and %u twiddlicators\n")
(i)(i); (i)(i);
} }
@ -112,7 +123,8 @@ int main(int argc, char** argv) {
//srand(time(0)); //srand(time(0));
srand(0); srand(0);
for (unsigned i = 0; ; ++i) { for (unsigned i = 0; ; ++i)
{
printf("%u\r", i); printf("%u\r", i);
// Generate a random string for the head // Generate a random string for the head
@ -122,18 +134,21 @@ int main(int argc, char** argv) {
// Generate a random set of flags // Generate a random set of flags
static const string flags("-+0 #"); static const string flags("-+0 #");
unsigned int maxFlags = RandomInt(0u, flags.length() - 1); unsigned int maxFlags = RandomInt(0u, flags.length() - 1);
for (unsigned int i = 0; i != maxFlags; ++i) { for (unsigned int i = 0; i != maxFlags; ++i)
{
formatSpec += flags[RandomInt(0u, flags.length() - 1)]; formatSpec += flags[RandomInt(0u, flags.length() - 1)];
} }
// Generate an optional random width // Generate an optional random width
if (RandomInt(0, 1)) { if (RandomInt(0, 1))
{
const unsigned int width = RandomInt(0, 100); const unsigned int width = RandomInt(0, 100);
char buf[4]; char buf[4];
sprintf(buf, "%u", width); sprintf(buf, "%u", width);
formatSpec += buf; formatSpec += buf;
} }
// Generate an optional random precision // Generate an optional random precision
if (RandomInt(0, 1)) { if (RandomInt(0, 1))
{
const unsigned int prec = RandomInt(0, 100); const unsigned int prec = RandomInt(0, 100);
char buf[4]; char buf[4];
sprintf(buf, "%u", prec); sprintf(buf, "%u", prec);
@ -145,21 +160,32 @@ int main(int argc, char** argv) {
const char typeSpec = type[RandomInt(0, type.size() - 1)]; const char typeSpec = type[RandomInt(0, type.size() - 1)];
// Generate an optional type prefix // Generate an optional type prefix
static const string prefix("hl"); static const string prefix("hl");
if (typeSpec != 's' && RandomInt(0, 1)) { if (typeSpec != 's' && RandomInt(0, 1))
{
formatSpec += prefix[RandomInt(0, prefix.size() - 1)]; formatSpec += prefix[RandomInt(0, prefix.size() - 1)];
} }
formatSpec += typeSpec; formatSpec += typeSpec;
formatSpec += '|'; formatSpec += '|';
formatSpec += RandomString(100); formatSpec += RandomString(100);
switch (typeSpec) { switch (typeSpec)
{
case 'c': case 'c':
TestCase(formatSpec, RandomInt(1, 127)); TestCase(formatSpec, RandomInt(1, 127));
break; break;
case 'd': case 'i': case 'o': case 'u': case 'x': case 'X': case 'd':
case 'i':
case 'o':
case 'u':
case 'x':
case 'X':
TestCase(formatSpec, RandomInt(-10000, 10000)); TestCase(formatSpec, RandomInt(-10000, 10000));
break; break;
case 'e': case 'E': case 'f': case 'g': case 'G': case 'e':
case 'E':
case 'f':
case 'g':
case 'G':
TestCase(formatSpec, TestCase(formatSpec,
RandomInt(-10000, 10000) / double(RandomInt(1, 100))); RandomInt(-10000, 10000) / double(RandomInt(1, 100)));
break; break;