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