1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /********************************************************************
5 * Copyright (c) 1997-2015, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 ********************************************************************/
9 #ifndef _NUMBERFORMATROUNDTRIPTEST_
10 #define _NUMBERFORMATROUNDTRIPTEST_
12 #include "unicode/utypes.h"
14 #if !UCONFIG_NO_FORMATTING
16 #include "unicode/numfmt.h"
17 #include "unicode/fmtable.h"
21 * Performs round-trip tests for NumberFormat
23 class NumberFormatRoundTripTest
: public IntlTest
{
26 void runIndexedTest( int32_t index
, UBool exec
, const char* &name
, char* par
);
30 static UBool STRING_COMPARE
;
31 static UBool EXACT_NUMERIC_COMPARE
;
32 static UBool DEBUG_VAR
;
33 static double MAX_ERROR
;
34 static double max_numeric_error
;
35 static double min_numeric_error
;
40 void test(NumberFormat
*fmt
);
41 void test(NumberFormat
*fmt
, double value
);
42 void test(NumberFormat
*fmt
, int32_t value
);
43 void test(NumberFormat
*fmt
, const Formattable
& value
);
45 static double randomDouble(double range
);
46 static double proportionalError(const Formattable
& a
, const Formattable
& b
);
47 static UnicodeString
& typeOf(const Formattable
& n
, UnicodeString
& result
);
48 static UnicodeString
& escape(UnicodeString
& s
);
51 isDouble(const Formattable
& n
)
52 { return (n
.getType() == Formattable::kDouble
); }
55 isLong(const Formattable
& n
)
56 { return (n
.getType() == Formattable::kLong
); }
59 * Return a random uint32_t
61 static uint32_t randLong();
64 * Return a random double 0 <= x < 1.0
66 static double randFraction()
68 return (double)randLong() / (double)0xFFFFFFFF;
72 UBool
failure(UErrorCode status
, const char* msg
, UBool possibleDataError
=FALSE
);
76 #endif /* #if !UCONFIG_NO_FORMATTING */
78 #endif // _NUMBERFORMATROUNDTRIPTEST_