/*
*******************************************************************************
- * Copyright (C) 2007-2010, International Business Machines Corporation and *
+ * Copyright (C) 2007-2013, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
new PluralFormatTest().run(args);
}
- private void helperTestRules(String localeIDs, String testPattern, Map changes) {
+ private void helperTestRules(String localeIDs, String testPattern, Map<Integer,String> changes) {
String[] locales = Utility.split(localeIDs, ',');
// Create example outputs for all supported locales.
log("plf: " + plf);
String expected = (String) changes.get(new Integer(0));
for (int n = 0; n < 200; ++n) {
- if (changes.get(new Integer(n)) != null) {
- expected = (String) changes.get(new Integer(n));
+ String value = changes.get(n);
+ if (value != null) {
+ expected = value;
}
assertEquals("Locale: " + locales[i] + ", number: " + n,
expected, plf.format(n));
}
public void TestSingular1Locales() {
- String localeIDs = "bem,da,de,el,en,eo,es,et,fi,fo,he,it,nb,nl,nn,no,pt,pt_PT,sv,af,bg,bn,ca,eu,fur,fy,gu,ha,is,ku,lb,ml," +
- "mr,nah,ne,om,or,pa,pap,ps,so,sq,sw,ta,te,tk,ur,zu,mn,gsw,rm";
+ String localeIDs = "bem,da,de,el,en,eo,es,et,fi,fo,he,it,nb,nl,nn,no,pt,pt_PT,sv,af,bg,ca,eu,fur,fy,ha,ku,lb,ml," +
+ "nah,ne,om,or,pap,ps,so,sq,sw,ta,te,tk,ur,mn,gsw,rm";
String testPattern = "one{one} other{other}";
Map changes = new HashMap();
changes.put(new Integer(0), "other");
}
public void TestSingular01Locales() {
- String localeIDs = "ff,fr,kab";
+ String localeIDs = "ff,fr,kab,gu,mr,pa,zu,bn";
String testPattern = "one{one} other{other}";
Map changes = new HashMap();
changes.put(new Integer(0), "one");
Map changes = new HashMap();
changes.put(new Integer(0), "zero");
changes.put(new Integer(1), "one");
- changes.put(new Integer(2), "other");
for (int i = 2; i < 20; ++i) {
+ if (i < 10) {
+ changes.put(new Integer(i), "other");
+ } else {
+ changes.put(new Integer(i), "zero");
+ }
+ changes.put(new Integer(i*10), "zero");
if (i == 11) {
- continue;
+ changes.put(new Integer(i*10 + 1), "zero");
+ changes.put(new Integer(i*10 + 2), "zero");
+ } else {
+ changes.put(new Integer(i*10 + 1), "one");
+ changes.put(new Integer(i*10 + 2), "other");
}
- changes.put(new Integer(i*10 + 1), "one");
- changes.put(new Integer(i*10 + 2), "other");
}
helperTestRules(localeIDs, testPattern, changes);
}
}
public void TestPaucalExcept11_14() {
- String localeIDs = "hr,ru,sr,uk";
+ String localeIDs = "hr,sr,uk";
String testPattern = "one{one} few{few} other{other}";
Map changes = new HashMap();
changes.put(new Integer(0), "other");
helperTestRules(localeIDs, testPattern, changes);
}
+ public void TestPaucalRu() {
+ String localeIDs = "ru";
+ String testPattern = "one{one} many{many} other{other}";
+ Map changes = new HashMap();
+ for (int i = 0; i < 200; i+=10) {
+ if (i == 10 || i == 110) {
+ put(i, 0, 9, "many", changes);
+ continue;
+ }
+ put(i, 0, "many", changes);
+ put(i, 1, "one", changes);
+ put(i, 2, 4, "other", changes);
+ put(i, 5, 9, "many", changes);
+ }
+ helperTestRules(localeIDs, testPattern, changes);
+ }
+
+ public <T> void put(int base, int start, int end, T value, Map<Integer, T> m) {
+ for (int i = start; i <= end; ++i) {
+ if (m.containsKey(base + i)) {
+ throw new IllegalArgumentException();
+ }
+ m.put(base + i, value);
+ }
+ }
+
+ public <T> void put(int base, int start, T value, Map<Integer, T> m) {
+ put(base, start, start, value, m);
+ }
+
public void TestSingularPaucal() {
String localeIDs = "cs,sk";
String testPattern = "one{one} few{few} other{other}";