]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/intltest/tsnmfmt.cpp
ICU-461.12.tar.gz
[apple/icu.git] / icuSources / test / intltest / tsnmfmt.cpp
index 1b126603e04bfa5c36a2c00748da8747e4d9ebb4..c78c672137bd5967bef48847ef37559185795dc2 100644 (file)
@@ -1,8 +1,8 @@
-/********************************************************************
+/***********************************************************************
  * COPYRIGHT: 
- * Copyright (c) 1997-2003, International Business Machines Corporation and
- * others. All Rights Reserved.
- ********************************************************************/
+ * Copyright (c) 1997-2009, International Business Machines Corporation
+ * and others. All Rights Reserved.
+ ***********************************************************************/
 
 #include "unicode/utypes.h"
 
 
 #include "unicode/decimfmt.h"
 #include "tsnmfmt.h"
+#include "putilimp.h"
 #include <float.h>
+#include <stdlib.h>
+
+IntlTestNumberFormat::~IntlTestNumberFormat() {}
 
 static const char * formattableTypeName(Formattable::Type t)
 {
@@ -20,6 +24,7 @@ static const char * formattableTypeName(Formattable::Type t)
   case Formattable::kLong: return "kLong";
   case Formattable::kString: return "kString";
   case Formattable::kArray: return "kArray";
+  case Formattable::kInt64: return "kInt64";
   default: return "??unknown??";
   }
 }
@@ -88,6 +93,12 @@ IntlTestNumberFormat::testLocale(/* char* par, */const Locale& locale, const Uni
     fStatus = U_ZERO_ERROR;
     fFormat = NumberFormat::createPercentInstance(locale, fStatus);
     testFormat(/* par */);
+       
+    name = "Scientific test";
+    logln((UnicodeString)name + " (" + localeName + ")");
+    fStatus = U_ZERO_ERROR;
+    fFormat = NumberFormat::createScientificInstance(locale, fStatus);
+    testFormat(/* par */);
 }
 
 double IntlTestNumberFormat::randDouble()
@@ -128,13 +139,15 @@ uint32_t IntlTestNumberFormat::randLong()
 }
 
 
-/* Make sure that we don't get something too large and multiply into infinity. */
+/* Make sure that we don't get something too large and multiply into infinity.
+   @param smallerThanMax the requested maximum value smaller than DBL_MAX */
 double IntlTestNumberFormat::getSafeDouble(double smallerThanMax) {
     double it;
+    double high = (DBL_MAX/smallerThanMax)/10.0;
+    double low = -high;
     do {
         it = randDouble();
-    } while (-DBL_MAX/smallerThanMax > it || it > DBL_MAX/smallerThanMax);
-    it *= smallerThanMax/10.0;
+    } while (low > it || it > high);
     return it;
 }
 
@@ -143,7 +156,7 @@ IntlTestNumberFormat::testFormat(/* char* par */)
 {
     if (U_FAILURE(fStatus))
     { 
-        errln((UnicodeString)"**** FAIL: createXxxInstance failed.");
+        dataerrln((UnicodeString)"**** FAIL: createXxxInstance failed. - " + u_errorName(fStatus));
         if (fFormat != 0)
             errln("**** FAIL: Non-null format returned by createXxxInstance upon failure.");
         delete fFormat;
@@ -204,6 +217,8 @@ IntlTestNumberFormat::testFormat(/* char* par */)
     tryIt(9.99999999999996);
     tryIt(9.999999999999996);
 
+       tryIt(5.06e-27);
+       
     tryIt((int32_t)INT32_MIN);
     tryIt((int32_t)INT32_MAX);
     tryIt((double)INT32_MIN);
@@ -290,6 +305,8 @@ IntlTestNumberFormat::tryIt(double aNumber)
         // Convert from long to double
         if (number[i].getType() == Formattable::kLong)
             number[i].setDouble(number[i].getLong());
+        else if (number[i].getType() == Formattable::kInt64)
+            number[i].setDouble((double)number[i].getInt64());
         else if (number[i].getType() != Formattable::kDouble)
         {
             errMsg = ("**** FAIL: Parse of " + prettify(string[i-1])
@@ -392,7 +409,7 @@ void IntlTestNumberFormat::testAvailableLocales(/* char* par */)
         logln(all);
     }
     else
-        errln((UnicodeString)"**** FAIL: Zero available locales or null array pointer");
+        dataerrln((UnicodeString)"**** FAIL: Zero available locales or null array pointer");
 }
 
 void IntlTestNumberFormat::monsterTest(/* char* par */)