]> granicus.if.org Git - icu/commitdiff
ICU-13177 NumberFormatter tests are passing.
authorShane Carr <shane@unicode.org>
Wed, 27 Sep 2017 03:02:02 +0000 (03:02 +0000)
committerShane Carr <shane@unicode.org>
Wed, 27 Sep 2017 03:02:02 +0000 (03:02 +0000)
X-SVN-Rev: 40467

icu4c/source/i18n/number_affixutils.cpp
icu4c/source/i18n/number_affixutils.h
icu4c/source/i18n/number_decimalquantity.cpp
icu4c/source/i18n/number_decimalquantity.h
icu4c/source/i18n/number_patternmodifier.cpp
icu4c/source/i18n/number_patternmodifier.h
icu4c/source/i18n/number_rounding.cpp
icu4c/source/test/intltest/itformat.cpp
icu4c/source/test/intltest/numbertest.h
icu4c/source/test/intltest/numbertest_decimalquantity.cpp

index 85af1d18d218402e33a0fcb42e0842998020a6e6..ec8b5b05240e18ecf0e868e1d39f5e005e898cbd 100644 (file)
@@ -149,7 +149,7 @@ int32_t
 AffixUtils::unescape(const CharSequence &affixPattern, NumberStringBuilder &output, int32_t position,
                      const SymbolProvider &provider, UErrorCode &status) {
     int32_t length = 0;
-    AffixTag tag = {0};
+    AffixTag tag;
     while (hasNext(tag, affixPattern)) {
         tag = nextToken(tag, affixPattern, status);
         if (tag.type == TYPE_CURRENCY_OVERFLOW) {
@@ -168,7 +168,7 @@ AffixUtils::unescape(const CharSequence &affixPattern, NumberStringBuilder &outp
 int32_t AffixUtils::unescapedCodePointCount(const CharSequence &affixPattern,
                                             const SymbolProvider &provider, UErrorCode &status) {
     int32_t length = 0;
-    AffixTag tag = {0};
+    AffixTag tag;
     while (hasNext(tag, affixPattern)) {
         tag = nextToken(tag, affixPattern, status);
         if (tag.type == TYPE_CURRENCY_OVERFLOW) {
@@ -187,7 +187,7 @@ AffixUtils::containsType(const CharSequence &affixPattern, AffixPatternType type
     if (affixPattern.length() == 0) {
         return false;
     }
-    AffixTag tag = {0};
+    AffixTag tag;
     while (hasNext(tag, affixPattern)) {
         tag = nextToken(tag, affixPattern, status);
         if (tag.type == type) {
@@ -201,7 +201,7 @@ bool AffixUtils::hasCurrencySymbols(const CharSequence &affixPattern, UErrorCode
     if (affixPattern.length() == 0) {
         return false;
     }
-    AffixTag tag = {0};
+    AffixTag tag;
     while (hasNext(tag, affixPattern)) {
         tag = nextToken(tag, affixPattern, status);
         if (tag.type < 0 && getFieldForType(tag.type) == UNUM_CURRENCY_FIELD) {
@@ -217,7 +217,7 @@ UnicodeString AffixUtils::replaceType(const CharSequence &affixPattern, AffixPat
     if (affixPattern.length() == 0) {
         return output;
     };
-    AffixTag tag = {0};
+    AffixTag tag;
     while (hasNext(tag, affixPattern)) {
         tag = nextToken(tag, affixPattern, status);
         if (tag.type == type) {
index 5fc2719cb567113191e16a044bb984aee3c356d0..5ff331420aeff7d3b96b03561a15ca1db9157f6c 100644 (file)
@@ -34,6 +34,8 @@ struct AffixTag {
     AffixPatternState state;
     AffixPatternType type;
 
+    AffixTag() : offset(0), state(STATE_BASE) {}
+
     AffixTag(int32_t offset) : offset(offset) {}
 
     AffixTag(int32_t offset, UChar32 codePoint, AffixPatternState state, AffixPatternType type)
index a4112d09b670ad976fe8996dbe5c6a05e22d513b..a355f96d3f1b2008ebb144497017c921c0c2ea5a 100644 (file)
@@ -141,7 +141,7 @@ uint64_t DecimalQuantity::getPositionFingerprint() const {
 }
 
 void DecimalQuantity::roundToIncrement(double roundingIncrement, RoundingMode roundingMode,
-                                       UErrorCode& status) {
+                                       int32_t minMaxFrac, UErrorCode& status) {
     // TODO: This is innefficient.  Improve?
     // TODO: Should we convert to decNumber instead?
     double temp = toDouble();
@@ -151,6 +151,9 @@ void DecimalQuantity::roundToIncrement(double roundingIncrement, RoundingMode ro
     temp = toDouble();
     temp *= roundingIncrement;
     setToDouble(temp);
+    // Since we reset the value to a double, we need to specify the rounding boundary
+    // in order to get the DecimalQuantity out of approximation mode.
+    roundToMagnitude(minMaxFrac, roundingMode, status);
 }
 
 void DecimalQuantity::multiplyBy(int32_t multiplicand) {
index ec0d69ebdaa9ef2530b27f4119ff42a174fba61e..e2a6e92022b5bf53c6cdaef76d2f62f9f800010d 100644 (file)
@@ -67,7 +67,8 @@ class DecimalQuantity : public IFixedDecimal, public UMemory {
      * @param roundingIncrement The increment to which to round.
      * @param mathContext The {@link RoundingMode} to use if rounding is necessary.
      */
-    void roundToIncrement(double roundingIncrement, RoundingMode roundingMode, UErrorCode& status);
+    void roundToIncrement(double roundingIncrement, RoundingMode roundingMode,
+                          int32_t minMaxFrac, UErrorCode& status);
 
     /**
      * Rounds the number to a specified magnitude (power of ten).
index 0874c83ed18f0a4673d2c9d16bc1990fec02631d..80121d84a7545e0c779cba7c442e9ef85f461e84 100644 (file)
@@ -22,7 +22,7 @@ void MutablePatternModifier::setPatternAttributes(UNumberSignDisplay signDisplay
 void
 MutablePatternModifier::setSymbols(const DecimalFormatSymbols *symbols, const CurrencyUnit &currency,
                                    const UNumberUnitWidth unitWidth, const PluralRules *rules) {
-    U_ASSERT((rules == nullptr) == needsPlurals());
+    U_ASSERT((rules != nullptr) == needsPlurals());
     this->symbols = symbols;
     uprv_memcpy(static_cast<char16_t *>(this->currencyCode),
             currency.getISOCurrency(),
index be2fbfbeabe1f85d08e696fa48ab0b2b5ecace21..475b427e12ec20015e1a9e2b4e683b0730340fbd 100644 (file)
@@ -195,7 +195,7 @@ class MutablePatternModifier
     const MicroPropsGenerator *parent;
 
     // Transient CharSequence fields
-    bool inCharSequenceMode;
+    bool inCharSequenceMode = false;
     int32_t fFlags;
     int32_t fLength;
     bool prependSign;
index 52229f9ad33c09c46e9d13678d34f6c55f8037ee..e51158acb1982595081f6dde7a3f51275013f908 100644 (file)
@@ -318,7 +318,8 @@ void Rounder::apply(impl::DecimalQuantity &value, UErrorCode& status) const {
         }
 
         case RND_INCREMENT:
-            value.roundToIncrement(fUnion.increment.fIncrement, fRoundingMode, status);
+            value.roundToIncrement(
+                fUnion.increment.fIncrement, fRoundingMode, fUnion.increment.fMinFrac, status);
             value.setFractionLength(fUnion.increment.fMinFrac, fUnion.increment.fMinFrac);
             break;
 
index 6059930b7d0ffbd79b35a69d83a57f124cb4d01c..0b3bf8a481c76d3238b3ed715df6d3c8f5bb8d5a 100644 (file)
@@ -223,13 +223,7 @@ void IntlTestFormat::runIndexedTest( int32_t index, UBool exec, const char* &nam
             callTest(*test, par); 
           } 
           break;
-        TESTCLASS(51,AffixUtilsTest);
-        TESTCLASS(52,NumberFormatterApiTest);
-        TESTCLASS(53,DecimalQuantityTest);
-        TESTCLASS(54,ModifiersTest);
-        TESTCLASS(55,PatternModifierTest);
-        TESTCLASS(56,PatternStringTest);
-        TESTCLASS(57,NumberStringBuilderTest);
+        TESTCLASS(51,NumberTest);
         default: name = ""; break; //needed to end loop
     }
     if (exec) {
index 9848e5fd4dce1810acff6ea47121c6b650284f96..39f07ec2b3acc20e387069339c07b0a4833a6ace 100644 (file)
 using namespace icu::number;
 using namespace icu::number::impl;
 
+////////////////////////////////////////////////////////////////////////////////////////
+// INSTRUCTIONS:                                                                      //
+// To add new NumberFormat unit test classes, create a new class like the ones below, //
+// and then add it as a switch statement in NumberTest at the bottom of this file.    /////////
+// To add new methods to existing unit test classes, add the method to the class declaration //
+// below, and also add it to the class's implementation of runIndexedTest().                 //
+///////////////////////////////////////////////////////////////////////////////////////////////
+
 class AffixUtilsTest : public IntlTest {
   public:
     void testEscape();
@@ -154,3 +162,36 @@ class NumberStringBuilderTest : public IntlTest {
   private:
     void assertEqualsImpl(const UnicodeString &a, const NumberStringBuilder &b);
 };
+
+
+// NOTE: This macro is identical to the one in itformat.cpp
+#define TESTCLASS(id, TestClass)          \
+    case id:                              \
+        name = #TestClass;                \
+        if (exec) {                       \
+            logln(#TestClass " test---"); \
+            logln((UnicodeString)"");     \
+            TestClass test;               \
+            callTest(test, par);          \
+        }                                 \
+        break
+
+class NumberTest : public IntlTest {
+  public:
+    void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = 0) {
+        if (exec) {
+            logln("TestSuite NumberTest: ");
+        }
+
+        switch (index) {
+        TESTCLASS(0, AffixUtilsTest);
+        TESTCLASS(1, NumberFormatterApiTest);
+        TESTCLASS(2, DecimalQuantityTest);
+        TESTCLASS(3, ModifiersTest);
+        TESTCLASS(4, PatternModifierTest);
+        TESTCLASS(5, PatternStringTest);
+        TESTCLASS(6, NumberStringBuilderTest);
+        default: name = ""; break; // needed to end loop
+        }
+    }
+};
index 94dd384260e89664c3436614565c30a3fa9780a1..322480869efbd0e3c8ff9480175f324cb3c04943 100644 (file)
@@ -78,7 +78,7 @@ void DecimalQuantityTest::testDecimalQuantityBehaviorStandalone() {
     assertToStringAndHealth(fq, "<DecimalQuantity 5:2:-3:-6 long 987654321E-6>");
     fq.roundToInfinity();
     assertToStringAndHealth(fq, "<DecimalQuantity 5:2:-3:-6 long 987654321E-6>");
-    fq.roundToIncrement(0.005, RoundingMode::UNUM_ROUND_HALFEVEN, status);
+    fq.roundToIncrement(0.005, RoundingMode::UNUM_ROUND_HALFEVEN, 3, status);
     assertSuccess("Rounding to increment", status);
     assertToStringAndHealth(fq, "<DecimalQuantity 5:2:-3:-6 long 987655E-3>");
     fq.roundToMagnitude(-2, RoundingMode::UNUM_ROUND_HALFEVEN, status);