]> git.saurik.com Git - apple/icu.git/blob - icuSources/test/intltest/nmfmtrt.h
ICU-551.41.tar.gz
[apple/icu.git] / icuSources / test / intltest / nmfmtrt.h
1 /********************************************************************
2 * COPYRIGHT:
3 * Copyright (c) 1997-2009, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
6
7 #ifndef _NUMBERFORMATROUNDTRIPTEST_
8 #define _NUMBERFORMATROUNDTRIPTEST_
9
10 #include "unicode/utypes.h"
11
12 #if !UCONFIG_NO_FORMATTING
13
14 #include "unicode/numfmt.h"
15 #include "unicode/fmtable.h"
16 #include "intltest.h"
17
18 /**
19 * Performs round-trip tests for NumberFormat
20 **/
21 class NumberFormatRoundTripTest : public IntlTest {
22
23 // IntlTest override
24 void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par );
25 public:
26
27 static UBool verbose;
28 static UBool STRING_COMPARE;
29 static UBool EXACT_NUMERIC_COMPARE;
30 static UBool DEBUG;
31 static double MAX_ERROR;
32 static double max_numeric_error;
33 static double min_numeric_error;
34
35
36 void start(void);
37
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);
42
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);
47
48 static inline UBool
49 isDouble(const Formattable& n)
50 { return (n.getType() == Formattable::kDouble); }
51
52 static inline UBool
53 isLong(const Formattable& n)
54 { return (n.getType() == Formattable::kLong); }
55
56 /*
57 * Return a random uint32_t
58 **/
59 static uint32_t randLong();
60
61 /**
62 * Return a random double 0 <= x < 1.0
63 **/
64 static double randFraction()
65 {
66 return (double)randLong() / (double)0xFFFFFFFF;
67 }
68
69 protected:
70 UBool failure(UErrorCode status, const char* msg, UBool possibleDataError=FALSE);
71
72 };
73
74 #endif /* #if !UCONFIG_NO_FORMATTING */
75
76 #endif // _NUMBERFORMATROUNDTRIPTEST_
77 //eof