1 // Copyright (C) 2016 and later: Unicode, Inc. and others. 2 // License & terms of use: http://www.unicode.org/copyright.html 3 /******************************************************************** 4 * COPYRIGHT: 5 * Copyright (c) 1997-2015, International Business Machines Corporation and 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" 19 20 /** 21 * Performs round-trip tests for NumberFormat 22 **/ 23 class NumberFormatRoundTripTest : public IntlTest { 24 25 // IntlTest override 26 void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par ); 27 public: 28 29 static UBool verbose; 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; 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 **/ 61 static uint32_t randLong(); 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 71 protected: 72 UBool failure(UErrorCode status, const char* msg, UBool possibleDataError=FALSE); 73 74 }; 75 76 #endif /* #if !UCONFIG_NO_FORMATTING */ 77 78 #endif // _NUMBERFORMATROUNDTRIPTEST_ 79 //eof 80