home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / test / intltest / nmfmtrt.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-07  |  2.2 KB  |  93 lines

  1.  
  2. /*
  3. ********************************************************************
  4. * COPYRIGHT: 
  5. * (C) Copyright International Business Machines Corporation, 1998
  6. * Licensed Material - Program-Property of IBM - All Rights Reserved. 
  7. * US Government Users Restricted Rights - Use, duplication, or disclosure 
  8. * restricted by GSA ADP Schedule Contract with IBM Corp. 
  9. *
  10. ********************************************************************
  11. */
  12.  
  13. #ifndef _NUMBERFORMATROUNDTRIPTEST_
  14. #define _NUMBERFORMATROUNDTRIPTEST_
  15.  
  16. #include "utypes.h"
  17. #include "intltest.h"
  18.  
  19. #include "fmtable.h"
  20.  
  21. class NumberFormat;
  22.  
  23. /** 
  24.  * Performs round-trip tests for NumberFormat
  25.  **/
  26. class NumberFormatRoundTripTest : public IntlTest {    
  27.     
  28.     // IntlTest override
  29.     void runIndexedTest( int32_t index, bool_t exec, char* &name, char* par );
  30. public:
  31.  
  32. static bool_t verbose;
  33. static bool_t STRING_COMPARE;
  34. static bool_t EXACT_NUMERIC_COMPARE;
  35. static bool_t DEBUG;
  36. static double MAX_ERROR;
  37. static double max_numeric_error;
  38. static double min_numeric_error;
  39.  
  40.  
  41. void start(void);
  42.  
  43. void test(NumberFormat *fmt);
  44. void test(NumberFormat *fmt, double value);
  45. void test(NumberFormat *fmt, int32_t value);
  46. void test(NumberFormat *fmt, const Formattable& value);
  47.  
  48. static double randomDouble(double range);
  49. static double proportionalError(const Formattable& a, const Formattable& b);
  50. static UnicodeString& typeOf(const Formattable& n, UnicodeString& result);
  51. static UnicodeString& escape(UnicodeString& s);
  52.  
  53. static bool_t
  54. isDouble(const Formattable& n)
  55. { return (n.getType() == Formattable::kDouble); }
  56.  
  57. static bool_t
  58. isLong(const Formattable& n)
  59. { return (n.getType() == Formattable::kLong); }
  60.  
  61. /*
  62.  * Return a random uint32_t
  63.  **/
  64. static uint32_t randLong()
  65. {
  66.     // Assume 8-bit (or larger) rand values.  Also assume
  67.     // that the system rand() function is very poor, which it always is.
  68.     uint32_t d;
  69.     int32_t i;
  70.     for (i=0; i < sizeof(uint32_t); ++i)
  71.     {
  72.         char* poke = (char*)&d;
  73.         poke[i] = (rand() & 0xFF);
  74.     }
  75.     return d;
  76. }
  77.  
  78. /**
  79.  * Return a random double 0 <= x < 1.0
  80.  **/
  81. static double randFraction()
  82. {
  83.     return (double)randLong() / (double)0xFFFFFFFF;
  84. }
  85.  
  86. protected:
  87.     bool_t failure(UErrorCode status, const char* msg);
  88.  
  89. };
  90.  
  91. #endif // _NUMBERFORMATROUNDTRIPTEST_
  92. //eof
  93.