From 95e854506afbb09092c84409333cd108fd81fff7 Mon Sep 17 00:00:00 2001 From: Shane Carr Date: Fri, 23 Jun 2017 06:51:04 +0000 Subject: [PATCH] ICU-13151 Removing obsolete assertion from PluralFormat.java X-SVN-Rev: 40199 --- .../src/com/ibm/icu/text/PluralFormat.java | 2 - .../icu/dev/test/format/PluralFormatTest.java | 54 +++++++++++-------- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/PluralFormat.java b/icu4j/main/classes/core/src/com/ibm/icu/text/PluralFormat.java index c9dc1ff6dd..1918283dc5 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/PluralFormat.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/PluralFormat.java @@ -19,7 +19,6 @@ import java.util.Map; import com.ibm.icu.impl.Utility; import com.ibm.icu.text.PluralRules.FixedDecimal; import com.ibm.icu.text.PluralRules.IFixedDecimal; -import com.ibm.icu.text.PluralRules.Operand; import com.ibm.icu.text.PluralRules.PluralType; import com.ibm.icu.util.ULocale; import com.ibm.icu.util.ULocale.Category; @@ -557,7 +556,6 @@ public class PluralFormat extends UFormat { @Override public String select(Object context, double number) { IFixedDecimal dec = (IFixedDecimal) context; - assert dec.getPluralOperand(Operand.n) == Math.abs(number); return pluralRules.select(dec); } } diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/PluralFormatTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/PluralFormatTest.java index 55a253673e..96fbcf4e86 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/PluralFormatTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/PluralFormatTest.java @@ -9,6 +9,7 @@ package com.ibm.icu.dev.test.format; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import org.junit.Test; @@ -16,6 +17,7 @@ import org.junit.Test; import com.ibm.icu.dev.test.TestFmwk; import com.ibm.icu.impl.Utility; import com.ibm.icu.text.CurrencyPluralInfo; +import com.ibm.icu.text.NumberFormat; import com.ibm.icu.text.PluralFormat; import com.ibm.icu.util.ULocale; @@ -26,13 +28,13 @@ import com.ibm.icu.util.ULocale; public class PluralFormatTest extends TestFmwk { private void helperTestRules(String localeIDs, String testPattern, Map changes) { String[] locales = Utility.split(localeIDs, ','); - + // Create example outputs for all supported locales. /* System.out.println("\n" + localeIDs); String lastValue = (String) changes.get(new Integer(0)); - int lastNumber = 0; - + int lastNumber = 0; + for (int i = 1; i < 199; ++i) { if (changes.get(new Integer(i)) != null) { if (lastNumber == i-1) { @@ -51,7 +53,7 @@ public class PluralFormatTest extends TestFmwk { try { PluralFormat plf = new PluralFormat(new ULocale(locales[i]), testPattern); log("plf: " + plf); - String expected = (String) changes.get(new Integer(0)); + String expected = changes.get(new Integer(0)); for (int n = 0; n < 200; ++n) { String value = changes.get(n); if (value != null) { @@ -65,7 +67,7 @@ public class PluralFormatTest extends TestFmwk { } } } - + @Test public void TestOneFormLocales() { String localeIDs = "ja,ko,tr,vi"; @@ -74,7 +76,7 @@ public class PluralFormatTest extends TestFmwk { changes.put(new Integer(0), "other"); helperTestRules(localeIDs, testPattern, changes); } - + @Test public void TestSingular1Locales() { String localeIDs = "bem,da,de,el,en,eo,es,et,fi,fo,he,it,nb,nl,nn,no,sv,af,bg,ca,eu,fur,fy,ha,ku,lb,ml," + @@ -86,7 +88,7 @@ public class PluralFormatTest extends TestFmwk { changes.put(new Integer(2), "other"); helperTestRules(localeIDs, testPattern, changes); } - + @Test public void TestSingular01Locales() { String localeIDs = "ff,fr,kab,gu,mr,pa,pt,pt_PT,zu,bn"; @@ -96,7 +98,7 @@ public class PluralFormatTest extends TestFmwk { changes.put(new Integer(2), "other"); helperTestRules(localeIDs, testPattern, changes); } - + @Test public void TestZeroSingularLocales() { String localeIDs = "lv"; @@ -121,7 +123,7 @@ public class PluralFormatTest extends TestFmwk { } helperTestRules(localeIDs, testPattern, changes); } - + @Test public void TestSingularDual() { String localeIDs = "ga"; @@ -133,7 +135,7 @@ public class PluralFormatTest extends TestFmwk { changes.put(new Integer(3), "other"); helperTestRules(localeIDs, testPattern, changes); } - + @Test public void TestSingularZeroSome() { String localeIDs = "ro"; @@ -147,7 +149,7 @@ public class PluralFormatTest extends TestFmwk { changes.put(new Integer(120), "other"); helperTestRules(localeIDs, testPattern, changes); } - + @Test public void TestSpecial12_19() { String localeIDs = "lt"; @@ -167,7 +169,7 @@ public class PluralFormatTest extends TestFmwk { } helperTestRules(localeIDs, testPattern, changes); } - + @Test public void TestPaucalExcept11_14() { String localeIDs = "hr,sr,uk"; @@ -187,7 +189,7 @@ public class PluralFormatTest extends TestFmwk { } helperTestRules(localeIDs, testPattern, changes); } - + @Test public void TestPaucalRu() { String localeIDs = "ru"; @@ -205,7 +207,7 @@ public class PluralFormatTest extends TestFmwk { } helperTestRules(localeIDs, testPattern, changes); } - + public void put(int base, int start, int end, T value, Map m) { for (int i = start; i <= end; ++i) { if (m.containsKey(base + i)) { @@ -214,11 +216,11 @@ public class PluralFormatTest extends TestFmwk { m.put(base + i, value); } } - + public void put(int base, int start, T value, Map m) { put(base, start, start, value, m); } - + @Test public void TestSingularPaucal() { String localeIDs = "cs,sk"; @@ -230,7 +232,7 @@ public class PluralFormatTest extends TestFmwk { changes.put(new Integer(5), "other"); helperTestRules(localeIDs, testPattern, changes); } - + @Test public void TestPaucal1_234() { String localeIDs = "pl"; @@ -249,7 +251,7 @@ public class PluralFormatTest extends TestFmwk { } helperTestRules(localeIDs, testPattern, changes); } - + @Test public void TestPaucal1_2_34() { String localeIDs = "sl"; @@ -266,7 +268,7 @@ public class PluralFormatTest extends TestFmwk { changes.put(new Integer(105), "other"); helperTestRules(localeIDs, testPattern, changes); } - + /* Tests the method public PluralRules getPluralRules() */ @Test public void TestGetPluralRules() { @@ -289,7 +291,7 @@ public class PluralFormatTest extends TestFmwk { errln("CurrencyPluralInfo.getLocale() was not suppose to return true " + "when passing a different ULocale"); } } - + /* Tests the method public void setLocale(ULocale loc) */ @Test public void TestSetLocale() { @@ -302,7 +304,7 @@ public class PluralFormatTest extends TestFmwk { errln("CurrencyPluralInfo.setLocale() was not suppose to return true when passing a different ULocale"); } } - + /* Tests the method public boolean equals(Object a) */ @Test public void TestEquals(){ @@ -317,4 +319,14 @@ public class PluralFormatTest extends TestFmwk { errln("CurrencyPluralInfo.equals(Object) was not suppose to return true when comparing to an invalid object for string 0."); } } + + /* Test for http://bugs.icu-project.org/trac/ticket/13151 */ + @Test + public void TestFractionRounding() { + NumberFormat nf = NumberFormat.getInstance(Locale.ENGLISH); + nf.setMaximumFractionDigits(0); + PluralFormat pf = new PluralFormat(ULocale.ENGLISH, "one{#kg}other{#kgs}"); + pf.setNumberFormat(nf); + assertEquals("1.2kg", "1kg", pf.format(1.2)); + } }