]>
Commit | Line | Data |
---|---|---|
b75a7d8f A |
1 | /******************************************************************** |
2 | * COPYRIGHT: | |
3 | * Copyright (c) 1997-2001, 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 | #include <stdlib.h> | |
18 | ||
19 | /** | |
20 | * Performs round-trip tests for NumberFormat | |
21 | **/ | |
22 | class NumberFormatRoundTripTest : public IntlTest { | |
23 | ||
24 | // IntlTest override | |
25 | void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par ); | |
26 | public: | |
27 | ||
28 | static UBool verbose; | |
29 | static UBool STRING_COMPARE; | |
30 | static UBool EXACT_NUMERIC_COMPARE; | |
31 | static UBool DEBUG; | |
32 | static double MAX_ERROR; | |
33 | static double max_numeric_error; | |
34 | static double min_numeric_error; | |
35 | ||
36 | ||
37 | void start(void); | |
38 | ||
39 | void test(NumberFormat *fmt); | |
40 | void test(NumberFormat *fmt, double value); | |
41 | void test(NumberFormat *fmt, int32_t value); | |
42 | void test(NumberFormat *fmt, const Formattable& value); | |
43 | ||
44 | static double randomDouble(double range); | |
45 | static double proportionalError(const Formattable& a, const Formattable& b); | |
46 | static UnicodeString& typeOf(const Formattable& n, UnicodeString& result); | |
47 | static UnicodeString& escape(UnicodeString& s); | |
48 | ||
49 | static inline UBool | |
50 | isDouble(const Formattable& n) | |
51 | { return (n.getType() == Formattable::kDouble); } | |
52 | ||
53 | static inline UBool | |
54 | isLong(const Formattable& n) | |
55 | { return (n.getType() == Formattable::kLong); } | |
56 | ||
57 | /* | |
58 | * Return a random uint32_t | |
59 | **/ | |
60 | static uint32_t randLong() | |
61 | { | |
62 | // Assume 8-bit (or larger) rand values. Also assume | |
63 | // that the system rand() function is very poor, which it always is. | |
64 | uint32_t d; | |
65 | uint32_t i; | |
66 | char* poke = (char*)&d; | |
67 | for (i=0; i < sizeof(uint32_t); ++i) | |
68 | { | |
69 | poke[i] = (char)(rand() & 0xFF); | |
70 | } | |
71 | return d; | |
72 | } | |
73 | ||
74 | /** | |
75 | * Return a random double 0 <= x < 1.0 | |
76 | **/ | |
77 | static double randFraction() | |
78 | { | |
79 | return (double)randLong() / (double)0xFFFFFFFF; | |
80 | } | |
81 | ||
82 | protected: | |
83 | UBool failure(UErrorCode status, const char* msg); | |
84 | ||
85 | }; | |
86 | ||
87 | #endif /* #if !UCONFIG_NO_FORMATTING */ | |
88 | ||
89 | #endif // _NUMBERFORMATROUNDTRIPTEST_ | |
90 | //eof |