This is the mail archive of the
mauve-patches@sourceware.org
mailing list for the Mauve project.
FYI: DecimalFormat update
- From: Mario Torre <neugens at limasoftware dot net>
- To: Mauve Patch List <mauve-patches at sources dot redhat dot com>
- Date: Fri, 22 Sep 2006 22:33:58 +0200
- Subject: FYI: DecimalFormat update
These are a couple of test used to check the new (not yet finalized)
DecimalFormat class.
2006-09-22 Mario Torre <neugens@limasoftware.net>
* gnu/testlet/java/text/DecimalFormat/toPattern14.java:
new file; this test is an update of toPattern for 1.4.
* gnu/testlet/java/text/DecimalFormat/parse.java (test):
small fix to the last test to help debugging: now uses the
mauve check(results, expected) method.
* gnu/testlet/java/text/DecimalFormat/MaximumAndMinimumDigits.java:
new file.
* gnu/testlet/java/text/DecimalFormat/getPositivePrefix.java (test):
new tests
* gnu/testlet/java/text/DecimalFormat/formatExp.java (test):
new test added.
Mario
--
Lima Software, SO.PR.IND. s.r.l.
http://www.limasoftware.net/
pgp key: http://subkeys.pgp.net/
Proud GNU Classpath developer: http://www.classpath.org/
Read About us at: http://planet.classpath.org
Please, support open standards:
http://opendocumentfellowship.org/petition/
http://www.nosoftwarepatents.com/
### Eclipse Workspace Patch 1.0
#P mauve
Index: gnu/testlet/java/text/DecimalFormat/parse.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/java/text/DecimalFormat/parse.java,v
retrieving revision 1.11
diff -u -r1.11 parse.java
--- gnu/testlet/java/text/DecimalFormat/parse.java 29 Aug 2006 17:35:41 -0000 1.11
+++ gnu/testlet/java/text/DecimalFormat/parse.java 22 Sep 2006 20:25:47 -0000
@@ -192,6 +192,6 @@
apply (harness, df, "#,##0X");
num = parseIt (df, "3,110Y", pp);
harness.check (num == null);
- harness.check (pp.getErrorIndex() == 5);
+ harness.check (pp.getErrorIndex(), 5);
}
}
Index: gnu/testlet/java/text/DecimalFormat/formatExp.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/java/text/DecimalFormat/formatExp.java,v
retrieving revision 1.2
diff -u -r1.2 formatExp.java
--- gnu/testlet/java/text/DecimalFormat/formatExp.java 29 Aug 2006 17:35:41 -0000 1.2
+++ gnu/testlet/java/text/DecimalFormat/formatExp.java 22 Sep 2006 20:25:47 -0000
@@ -73,6 +73,7 @@
apply (harness, df, "00.###E0");
harness.check (df.format (12345), "12.345E3");
harness.check (df.format (1234), "12.34E2");
+ harness.check (df.format (0.00123), "12.3E-4");
apply(harness, df, "0E0");
harness.check(df.format(-1234.567), "-1E3");
Index: gnu/testlet/java/text/DecimalFormat/getPositivePrefix.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/java/text/DecimalFormat/getPositivePrefix.java,v
retrieving revision 1.1
diff -u -r1.1 getPositivePrefix.java
--- gnu/testlet/java/text/DecimalFormat/getPositivePrefix.java 13 Mar 2005 20:42:07 -0000 1.1
+++ gnu/testlet/java/text/DecimalFormat/getPositivePrefix.java 22 Sep 2006 20:25:47 -0000
@@ -43,6 +43,13 @@
DecimalFormat f1 = new DecimalFormat();
f1.setPositivePrefix("XYZ");
harness.check(f1.getPositivePrefix(), "XYZ");
+
+ // this means: "no one understand a thing here"
+ String longPrefix = "'#'1'.' ''nessuno ci capisce niente qui";
+ String longPrefixCheck = "#1. 'nessuno ci capisce niente qui";
+
+ DecimalFormat f2 = new DecimalFormat(longPrefix + "#0.00;(#0.00)");
+ harness.check(f2.getPositivePrefix(), longPrefixCheck);
}
}
Index: gnu/testlet/java/text/DecimalFormat/toPattern14.java
===================================================================
RCS file: gnu/testlet/java/text/DecimalFormat/toPattern14.java
diff -N gnu/testlet/java/text/DecimalFormat/toPattern14.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/text/DecimalFormat/toPattern14.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,141 @@
+//Tags: JDK1.4
+
+//Copyright (c) 1999 Cygnus Solutions
+//Written by Tom Tromey <tromey@cygnus.com>
+//Copyright (C) 2005 David Gilbert <david.gilbert@object-refinery.com>
+
+//This file is part of Mauve.
+
+//Mauve is free software; you can redistribute it and/or modify
+//it under the terms of the GNU General Public License as published by
+//the Free Software Foundation; either version 2, or (at your option)
+//any later version.
+
+//Mauve is distributed in the hope that it will be useful,
+//but WITHOUT ANY WARRANTY; without even the implied warranty of
+//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+//GNU General Public License for more details.
+
+//You should have received a copy of the GNU General Public License
+//along with Mauve; see the file COPYING. If not, write to
+//the Free Software Foundation, 59 Temple Place - Suite 330,
+//Boston, MA 02111-1307, USA.
+
+
+package gnu.testlet.java.text.DecimalFormat;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import java.text.DecimalFormat;
+import java.text.DecimalFormatSymbols;
+import java.util.Locale;
+
+/**
+ * Some checks for the toPattern() method in the {@link DecimalFormat} class.
+ */
+public class toPattern14
+ implements Testlet
+{
+
+ /**
+ * Runs the test using the specified harness.
+ *
+ * @param harness the test harness (<code>null</code> not permitted).
+ */
+ public void test(TestHarness harness)
+ {
+ test1(harness);
+ test2(harness);
+ test3(harness);
+ }
+
+ /**
+ * This test was formerly in the file topattern.java.
+ *
+ * @param harness the test harness.
+ */
+ public void test1(TestHarness harness)
+ {
+ // Just to be explicit: we're only testing the US locale here.
+ Locale loc = Locale.US;
+ Locale.setDefault(loc);
+
+ // There aren't really many tests we can do, since it doesn't
+ // seem like any canonical output format is documented.
+
+ DecimalFormat df = new DecimalFormat("0.##");
+ harness.check(df.toPattern(), "#0.##");
+ harness.check(df.toLocalizedPattern(), "#0.##");
+
+ DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();
+ dfs.setDecimalSeparator(',');
+ dfs.setZeroDigit('1');
+ dfs.setDigit('X');
+ dfs.setGroupingSeparator('!');
+ df.setDecimalFormatSymbols(dfs);
+
+ // dfs is only a copy of the internal
+ // symbols so pass symbols back to df
+ harness.check(df.toLocalizedPattern(), "X1,XX");
+
+ df.applyPattern("Fr #,##0.##");
+
+ String x1 = df.toPattern();
+ String x2 = df.toLocalizedPattern();
+ harness.check(x1.length(), x2.length());
+
+ boolean ok = x1.length() == x2.length();
+ for (int i = 0; i < x1.length(); ++i)
+ {
+ char c = x1.charAt(i);
+ if (c == '0')
+ c = '1';
+ else if (c == '#')
+ c = 'X';
+ else if (c == '.')
+ c = ',';
+ else if (c == ',')
+ c = '!';
+
+ if (c != x2.charAt(i))
+ {
+ ok = false;
+ harness.debug("failure at char " + i);
+ harness.debug("x1 = " + x1 + "\nx2 = " + x2);
+ break;
+ }
+ }
+ harness.check(ok);
+ }
+
+ public void test2(TestHarness harness)
+ {
+ DecimalFormat f1 = new DecimalFormat("#0.00;(#0.00)");
+ harness.check(f1.toPattern(), "#0.00;(#0.00)");
+
+ DecimalFormat f2 =
+ new DecimalFormat("'#'1'.' ''nessuno ci capisce niente qui #0.00;(#0.00)");
+ harness.check(f2.toPattern(),
+ "'#'1'.' ''nessuno ci capisce niente qui #0.00;(#0.00)");
+ }
+
+ public void test3(TestHarness harness)
+ {
+ DecimalFormat f1 = new DecimalFormat("0.00");
+ harness.check(f1.toPattern(), "#0.00");
+
+ f1.setMinimumIntegerDigits(0);
+ harness.check(f1.toPattern(), "#.00");
+
+ f1.setMaximumIntegerDigits(0);
+ harness.check(f1.toPattern(), "#.00");
+
+ DecimalFormat f2 = new DecimalFormat("#0.#E0");
+ harness.check(f2.toPattern(), "0.#E0");
+
+ DecimalFormat f3 = new DecimalFormat("0.#E0");
+ harness.check(f3.toPattern(), "0.#E0");
+ }
+}
+
Index: gnu/testlet/java/text/DecimalFormat/MaximumAndMinimumDigits.java
===================================================================
RCS file: gnu/testlet/java/text/DecimalFormat/MaximumAndMinimumDigits.java
diff -N gnu/testlet/java/text/DecimalFormat/MaximumAndMinimumDigits.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/text/DecimalFormat/MaximumAndMinimumDigits.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,138 @@
+/* MaximumAndMinimumDigits.java --
+ Copyright (C) 2006 Lima Software, SO.PR.IND. s.r.l.
+This file is part of Mauve.
+
+Mauve is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+Mauve is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Mauve; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+*/
+
+// Tags: JDK1.4
+
+package gnu.testlet.java.text.DecimalFormat;
+
+import java.text.DecimalFormat;
+import java.util.Locale;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+/**
+ * Test class for maximum and minimum integer and fraction digits getter/setter
+ * in class DecimalFormat.
+ *
+ * @author Mario Torre <neugens@limasoftware.net>
+ */
+public class MaximumAndMinimumDigits implements Testlet
+{
+ /** Test Harness */
+ private TestHarness harness = null;
+
+ /*
+ * @see gnu.testlet.Testlet#test(gnu.testlet.TestHarness)
+ */
+ public void test(TestHarness harness)
+ {
+ this.harness = harness;
+
+ Locale original = Locale.getDefault();
+ Locale.setDefault(Locale.US);
+
+ try
+ {
+ doTest();
+ }
+ finally
+ {
+ Locale.setDefault(original);
+ }
+ }
+
+ private void doTest()
+ {
+ // this value is invalid on the RI, as of 1.5.0_08,
+ // it should be 2147483647
+ int MAX = 309;
+
+ harness.checkPoint("default pattern");
+ DecimalFormat format = new DecimalFormat();
+ harness.check(format.getMaximumIntegerDigits(), MAX);
+ harness.check(format.getMinimumIntegerDigits(), 1);
+ harness.check(format.getMaximumFractionDigits(), 3);
+ harness.check(format.getMinimumFractionDigits(), 0);
+
+ harness.checkPoint("0.00E0");
+ format = new DecimalFormat("0.00E0");
+ harness.check(format.getMaximumIntegerDigits(), 1);
+ harness.check(format.getMinimumIntegerDigits(), 1);
+ harness.check(format.getMaximumFractionDigits(), 2);
+ harness.check(format.getMinimumFractionDigits(), 2);
+
+ harness.checkPoint("#,##0.0#");
+ format = new DecimalFormat("#,##0.0#");
+ harness.check(format.getMaximumIntegerDigits(), MAX);
+ harness.check(format.getMinimumIntegerDigits(), 1);
+ harness.check(format.getMaximumFractionDigits(), 2);
+ harness.check(format.getMinimumFractionDigits(), 1);
+
+ // check what happen if we force a different value
+ harness.checkPoint("maximum integer digits, checking format...");
+ format.setMaximumIntegerDigits(0);
+ harness.check(format.getMaximumIntegerDigits(), 0);
+ harness.check(format.format(123456.123456), ".12");
+
+ harness.checkPoint("#.");
+ format = new DecimalFormat("#.");
+ harness.check(format.getMaximumIntegerDigits(), MAX);
+ harness.check(format.getMinimumIntegerDigits(), 1);
+ harness.check(format.getMaximumFractionDigits(), 0);
+ harness.check(format.getMinimumFractionDigits(), 0);
+
+ harness.checkPoint("#.#");
+ format = new DecimalFormat("#.#");
+ harness.check(format.getMaximumIntegerDigits(), MAX);
+ harness.check(format.getMinimumIntegerDigits(), 1);
+ harness.check(format.getMaximumFractionDigits(), 1);
+ harness.check(format.getMinimumFractionDigits(), 0);
+
+ harness.checkPoint("#0000000000000,00000.###");
+ format = new DecimalFormat("#0000000000000,00000.###");
+ harness.check(format.getMaximumIntegerDigits(), MAX);
+ harness.check(format.getMinimumIntegerDigits(), 18);
+ harness.check(format.getMaximumFractionDigits(), 3);
+ harness.check(format.getMinimumFractionDigits(), 0);
+
+ harness.checkPoint("0E0");
+ format = new DecimalFormat("0E0");
+ harness.check(format.getMaximumIntegerDigits(), 1);
+ harness.check(format.getMinimumIntegerDigits(), 1);
+ harness.check(format.getMaximumFractionDigits(), 0);
+ harness.check(format.getMinimumFractionDigits(), 0);
+
+ harness.checkPoint("0.###E0");
+ format = new DecimalFormat("0.###E0");
+ harness.check(format.getMaximumIntegerDigits(), 1);
+ harness.check(format.getMinimumIntegerDigits(), 1);
+ harness.check(format.getMaximumFractionDigits(), 3);
+ harness.check(format.getMinimumFractionDigits(), 0);
+
+ harness.checkPoint(".00");
+ format = new DecimalFormat(".00");
+ harness.check(format.getMaximumIntegerDigits(), MAX);
+ harness.check(format.getMinimumIntegerDigits(), 0);
+ harness.check(format.getMaximumFractionDigits(), 2);
+ harness.check(format.getMinimumFractionDigits(), 2);
+ }
+}