1 /********************************************************************
3 * Copyright (c) 1997-2015, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
7 #ifndef _NUMBERFORMATROUNDTRIPTEST_
8 #define _NUMBERFORMATROUNDTRIPTEST_
10 #include "unicode/utypes.h"
12 #if !UCONFIG_NO_FORMATTING
14 #include "unicode/numfmt.h"
15 #include "unicode/fmtable.h"
19 * Performs round-trip tests for NumberFormat
21 class NumberFormatRoundTripTest
: public IntlTest
{
24 void runIndexedTest( int32_t index
, UBool exec
, const char* &name
, char* par
);
28 static UBool STRING_COMPARE
;
29 static UBool EXACT_NUMERIC_COMPARE
;
30 static UBool DEBUG_VAR
;
31 static double MAX_ERROR
;
32 static double max_numeric_error
;
33 static double min_numeric_error
;
38 void test(NumberFormat
*fmt
);
39 void test(NumberFormat
*fmt
, double value
);
40 void test(NumberFormat
*fmt
, int32_t value
);
41 void test(NumberFormat
*fmt
, const Formattable
& value
);
43 static double randomDouble(double range
);
44 static double proportionalError(const Formattable
& a
, const Formattable
& b
);
45 static UnicodeString
& typeOf(const Formattable
& n
, UnicodeString
& result
);
46 static UnicodeString
& escape(UnicodeString
& s
);
49 isDouble(const Formattable
& n
)
50 { return (n
.getType() == Formattable::kDouble
); }
53 isLong(const Formattable
& n
)
54 { return (n
.getType() == Formattable::kLong
); }
57 * Return a random uint32_t
59 static uint32_t randLong();
62 * Return a random double 0 <= x < 1.0
64 static double randFraction()
66 return (double)randLong() / (double)0xFFFFFFFF;
70 UBool
failure(UErrorCode status
, const char* msg
, UBool possibleDataError
=FALSE
);
74 #endif /* #if !UCONFIG_NO_FORMATTING */
76 #endif // _NUMBERFORMATROUNDTRIPTEST_