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) {
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) {
if (affixPattern.length() == 0) {
return false;
}
- AffixTag tag = {0};
+ AffixTag tag;
while (hasNext(tag, affixPattern)) {
tag = nextToken(tag, affixPattern, status);
if (tag.type == type) {
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) {
if (affixPattern.length() == 0) {
return output;
};
- AffixTag tag = {0};
+ AffixTag tag;
while (hasNext(tag, affixPattern)) {
tag = nextToken(tag, affixPattern, status);
if (tag.type == type) {
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)
}
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();
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) {
* @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).
void
MutablePatternModifier::setSymbols(const DecimalFormatSymbols *symbols, const CurrencyUnit ¤cy,
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(),
const MicroPropsGenerator *parent;
// Transient CharSequence fields
- bool inCharSequenceMode;
+ bool inCharSequenceMode = false;
int32_t fFlags;
int32_t fLength;
bool prependSign;
}
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;
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) {
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();
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
+ }
+ }
+};
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);