2000-01-15 02:00:06 +00:00
|
|
|
/********************************************************************
|
|
|
|
* COPYRIGHT:
|
|
|
|
* Copyright (c) 1997-1999, International Business Machines Corporation and
|
|
|
|
* others. All Rights Reserved.
|
|
|
|
********************************************************************/
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
#ifndef _NUMBERFORMATROUNDTRIPTEST_
|
|
|
|
#define _NUMBERFORMATROUNDTRIPTEST_
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/utypes.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "intltest.h"
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/fmtable.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
class NumberFormat;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Performs round-trip tests for NumberFormat
|
|
|
|
**/
|
|
|
|
class NumberFormatRoundTripTest : public IntlTest {
|
|
|
|
|
|
|
|
// IntlTest override
|
2000-08-14 21:42:36 +00:00
|
|
|
void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par );
|
1999-08-16 21:50:52 +00:00
|
|
|
public:
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
static UBool verbose;
|
|
|
|
static UBool STRING_COMPARE;
|
|
|
|
static UBool EXACT_NUMERIC_COMPARE;
|
|
|
|
static UBool DEBUG;
|
1999-08-16 21:50:52 +00:00
|
|
|
static double MAX_ERROR;
|
|
|
|
static double max_numeric_error;
|
|
|
|
static double min_numeric_error;
|
|
|
|
|
|
|
|
|
|
|
|
void start(void);
|
|
|
|
|
|
|
|
void test(NumberFormat *fmt);
|
|
|
|
void test(NumberFormat *fmt, double value);
|
|
|
|
void test(NumberFormat *fmt, int32_t value);
|
|
|
|
void test(NumberFormat *fmt, const Formattable& value);
|
|
|
|
|
|
|
|
static double randomDouble(double range);
|
|
|
|
static double proportionalError(const Formattable& a, const Formattable& b);
|
|
|
|
static UnicodeString& typeOf(const Formattable& n, UnicodeString& result);
|
|
|
|
static UnicodeString& escape(UnicodeString& s);
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
static UBool
|
1999-08-16 21:50:52 +00:00
|
|
|
isDouble(const Formattable& n)
|
|
|
|
{ return (n.getType() == Formattable::kDouble); }
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
static UBool
|
1999-08-16 21:50:52 +00:00
|
|
|
isLong(const Formattable& n)
|
|
|
|
{ return (n.getType() == Formattable::kLong); }
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return a random uint32_t
|
|
|
|
**/
|
|
|
|
static uint32_t randLong()
|
|
|
|
{
|
|
|
|
// Assume 8-bit (or larger) rand values. Also assume
|
|
|
|
// that the system rand() function is very poor, which it always is.
|
|
|
|
uint32_t d;
|
|
|
|
int32_t i;
|
2000-08-11 22:19:54 +00:00
|
|
|
char* poke = (char*)&d;
|
1999-08-16 21:50:52 +00:00
|
|
|
for (i=0; i < sizeof(uint32_t); ++i)
|
|
|
|
{
|
2000-08-11 22:19:54 +00:00
|
|
|
poke[i] = (char)(rand() & 0xFF);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a random double 0 <= x < 1.0
|
|
|
|
**/
|
|
|
|
static double randFraction()
|
|
|
|
{
|
|
|
|
return (double)randLong() / (double)0xFFFFFFFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool failure(UErrorCode status, const char* msg);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _NUMBERFORMATROUNDTRIPTEST_
|
|
|
|
//eof
|