public inbox for mauve-patches@sourceware.org
 help / color / mirror / Atom feed
* Double.parseDouble()/valueOf() - bug 10491
@ 2004-10-07 16:12 David Gilbert
  2004-10-15 22:35 ` Mark Wielaard
  0 siblings, 1 reply; 2+ messages in thread
From: David Gilbert @ 2004-10-07 16:12 UTC (permalink / raw)
  To: mauve-patches

[-- Attachment #1: Type: text/plain, Size: 2504 bytes --]

The attached tests include checks for the problems reported in bug
10491.  I get these results:

dgilbert@linux42:~/workspace/mauve> java14 -classpath .
gnu.testlet.SimpleTestHarness -file CurrentTests.txt -debug
0 of 54 tests failed
dgilbert@linux42:~/workspace/mauve> java15 -classpath .
gnu.testlet.SimpleTestHarness -file CurrentTests.txt -debug
0 of 54 tests failed
dgilbert@linux42:~/workspace/mauve> jamvm -classpath .
gnu.testlet.SimpleTestHarness -file CurrentTests.txt -debug
FAIL: gnu.testlet.java.lang.Double.parseDouble (number 16)
java.lang.NumberFormatException: unable to parse double
   at java.lang.Double.parseDouble (Native Method)
   at gnu.testlet.java.lang.Double.parseDouble.testInfinities
(parseDouble.java:134)
   at gnu.testlet.java.lang.Double.parseDouble.test
(parseDouble.java:39)
   at gnu.testlet.SimpleTestHarness.runtest (SimpleTestHarness.java:266)
   at gnu.testlet.SimpleTestHarness.main (SimpleTestHarness.java:394)
FAIL: gnu.testlet.java.lang.Double.parseDouble (number 19)
java.lang.NumberFormatException: unable to parse double
   at java.lang.Double.parseDouble (Native Method)
   at gnu.testlet.java.lang.Double.parseDouble.testNaN
(parseDouble.java:158)
   at gnu.testlet.java.lang.Double.parseDouble.test
(parseDouble.java:40)
   at gnu.testlet.SimpleTestHarness.runtest (SimpleTestHarness.java:266)
   at gnu.testlet.SimpleTestHarness.main (SimpleTestHarness.java:394)
FAIL: gnu.testlet.java.lang.Double.valueOf (number 16)
java.lang.NumberFormatException: unable to parse double
   at java.lang.Double.parseDouble (Native Method)
   at java.lang.Double.valueOf (Double.java:194)
   at gnu.testlet.java.lang.Double.valueOf.testInfinities
(valueOf.java:134)
   at gnu.testlet.java.lang.Double.valueOf.test (valueOf.java:39)
   at gnu.testlet.SimpleTestHarness.runtest (SimpleTestHarness.java:266)
   at gnu.testlet.SimpleTestHarness.main (SimpleTestHarness.java:394)
FAIL: gnu.testlet.java.lang.Double.valueOf (number 19)
java.lang.NumberFormatException: unable to parse double
   at java.lang.Double.parseDouble (Native Method)
   at java.lang.Double.valueOf (Double.java:194)
   at gnu.testlet.java.lang.Double.valueOf.testNaN (valueOf.java:158)
   at gnu.testlet.java.lang.Double.valueOf.test (valueOf.java:40)
   at gnu.testlet.SimpleTestHarness.runtest (SimpleTestHarness.java:266)
   at gnu.testlet.SimpleTestHarness.main (SimpleTestHarness.java:394)
4 of 38 tests failed

Similar tests for Float to follow.

Regards,

Dave Gilbert
http://www.jfree.org

[-- Attachment #2: parseDouble.java --]
[-- Type: text/x-java, Size: 4534 bytes --]

// Tags: JDK1.2

// Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>

// 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.lang.Double;

import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;

/**
 * Some checks for the parseDouble() method in the {@link Double} class.
 */
public class parseDouble implements Testlet 
{

  /**
   * Runs the test using the specified harness.
   * 
   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness)      
  {
    testRegular(harness);
    testInfinities(harness);
    testNaN(harness);
  }

  /**
   * Tests some regular values.
   * 
   * @param harness  the test harness.
   */
  public void testRegular(TestHarness harness) 
  {
    harness.check(Double.parseDouble("1.0"), 1.0);
    harness.check(Double.parseDouble("+1.0"), 1.0);
    harness.check(Double.parseDouble("-1.0"), -1.0);
    harness.check(Double.parseDouble(" 1.0 "), 1.0);
    harness.check(Double.parseDouble(" -1.0 "), -1.0);
    
    harness.check(Double.parseDouble("2."), 2.0);
    harness.check(Double.parseDouble(".3"), 0.3);
    harness.check(Double.parseDouble("1e-9"), 1e-9);
    harness.check(Double.parseDouble("1e137"), 1e137);    

    // test some bad formats
    try
    {
      /* double d = */ Double.parseDouble("");
      harness.check(false);
    }
    catch (NumberFormatException e) 
    {
      harness.check(true);
    }

    try
    {
      /* double d = */ Double.parseDouble("X");
      harness.check(false);
    }
    catch (NumberFormatException e) 
    {
      harness.check(true);
    }

    try
    {
      /* double d = */ Double.parseDouble("e");
      harness.check(false);
    }
    catch (NumberFormatException e) 
    {
      harness.check(true);
    }

    try
    {
      /* double d = */ Double.parseDouble("+ 1.0");
      harness.check(false);
    }
    catch (NumberFormatException e) 
    {
      harness.check(true);
    }

    try
    {
      /* double d = */ Double.parseDouble("- 1.0");
      harness.check(false);
    }
    catch (NumberFormatException e) 
    {
      harness.check(true);
    }       
    
    // null argument should throw NullPointerException
    try
    {
      /* double d = */ Double.parseDouble(null);
      harness.check(false);        
    }
    catch (NullPointerException e) 
    {
      harness.check(true);
    }
  }
  
  /**
   * Some checks for values that should parse to Double.POSITIVE_INFINITY
   * or Double.NEGATIVE_INFINITY.
   * 
   * @param harness  the test harness.
   */
  public void testInfinities(TestHarness harness) 
  {
    try 
    {
      harness.check(Double.parseDouble("Infinity"), Double.POSITIVE_INFINITY);
      harness.check(Double.parseDouble("+Infinity"), Double.POSITIVE_INFINITY);
      harness.check(Double.parseDouble("-Infinity"), Double.NEGATIVE_INFINITY);
      harness.check(Double.parseDouble(" +Infinity "), Double.POSITIVE_INFINITY);
      harness.check(Double.parseDouble(" -Infinity "), Double.NEGATIVE_INFINITY);
    }
    catch (Exception e) 
    {
      harness.check(false);
      harness.debug(e);
    }
    harness.check(Double.parseDouble("1e1000"), Double.POSITIVE_INFINITY);
    harness.check(Double.parseDouble("-1e1000"), Double.NEGATIVE_INFINITY);
  }
  
  /**
   * Some checks for 'NaN' values.
   * 
   * @param harness  the test harness.
   */
  public void testNaN(TestHarness harness) 
  {
    try
    {
      harness.check(Double.isNaN(Double.parseDouble("NaN")));
      harness.check(Double.isNaN(Double.parseDouble("+NaN")));
      harness.check(Double.isNaN(Double.parseDouble("-NaN")));
      harness.check(Double.isNaN(Double.parseDouble(" +NaN ")));
      harness.check(Double.isNaN(Double.parseDouble(" -NaN ")));
    }
    catch (Exception e) 
    {
      harness.check(false);
      harness.debug(e);
    }
  }
  
}


[-- Attachment #3: valueOf.java --]
[-- Type: text/x-java, Size: 4680 bytes --]

// Tags: JDK1.2

// Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>

// 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.lang.Double;

import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;

/**
 * Some checks for the valueOf() method in the {@link Double} class.
 */
public class valueOf implements Testlet 
{

  /**
   * Runs the test using the specified harness.
   * 
   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness)      
  {
    testRegular(harness);
    testInfinities(harness);
    testNaN(harness);
  }

  /**
   * Tests some regular values.
   * 
   * @param harness  the test harness.
   */
  public void testRegular(TestHarness harness) 
  {
    harness.check(Double.valueOf("1.0"), new Double(1.0));
    harness.check(Double.valueOf("+1.0"), new Double(1.0));
    harness.check(Double.valueOf("-1.0"), new Double(-1.0));
    harness.check(Double.valueOf(" 1.0 "), new Double(1.0));
    harness.check(Double.valueOf(" -1.0 "), new Double(-1.0));
    
    harness.check(Double.valueOf("2."), new Double(2.0));
    harness.check(Double.valueOf(".3"), new Double(0.3));
    harness.check(Double.valueOf("1e-9"), new Double(1e-9));
    harness.check(Double.valueOf("1e137"), new Double(1e137));    

    // test some bad formats
    try
    {
      /* Double d = */ Double.valueOf("");
      harness.check(false);
    }
    catch (NumberFormatException e) 
    {
      harness.check(true);
    }

    try
    {
      /* Double d = */ Double.valueOf("X");
      harness.check(false);
    }
    catch (NumberFormatException e) 
    {
      harness.check(true);
    }

    try
    {
      /* Double d = */ Double.valueOf("e");
      harness.check(false);
    }
    catch (NumberFormatException e) 
    {
      harness.check(true);
    }

    try
    {
      /* Double d = */ Double.valueOf("+ 1.0");
      harness.check(false);
    }
    catch (NumberFormatException e) 
    {
      harness.check(true);
    }

    try
    {
      /* Double d = */ Double.valueOf("- 1.0");
      harness.check(false);
    }
    catch (NumberFormatException e) 
    {
      harness.check(true);
    }       
    
    // null argument should throw NullPointerException
    try
    {
      /* Double d = */ Double.valueOf(null);
      harness.check(false);        
    }
    catch (NullPointerException e) 
    {
      harness.check(true);
    }
  }
  
  /**
   * Some checks for values that should parse to Double.POSITIVE_INFINITY
   * or Double.NEGATIVE_INFINITY.
   * 
   * @param harness  the test harness.
   */
  public void testInfinities(TestHarness harness) 
  {
    try 
    {
      harness.check(Double.valueOf("Infinity"), new Double(Double.POSITIVE_INFINITY));
      harness.check(Double.valueOf("+Infinity"), new Double(Double.POSITIVE_INFINITY));
      harness.check(Double.valueOf("-Infinity"), new Double(Double.NEGATIVE_INFINITY));
      harness.check(Double.valueOf(" +Infinity "), new Double(Double.POSITIVE_INFINITY));
      harness.check(Double.valueOf(" -Infinity "), new Double(Double.NEGATIVE_INFINITY));
    }
    catch (Exception e) 
    {
      harness.check(false);
      harness.debug(e);
    }
    harness.check(Double.valueOf("1e1000"), new Double(Double.POSITIVE_INFINITY));
    harness.check(Double.valueOf("-1e1000"), new Double(Double.NEGATIVE_INFINITY));
  }
  
  /**
   * Some checks for 'NaN' values.
   * 
   * @param harness  the test harness.
   */
  public void testNaN(TestHarness harness) 
  {
    try
    {
      harness.check(Double.isNaN(Double.valueOf("NaN").doubleValue()));
      harness.check(Double.isNaN(Double.valueOf("+NaN").doubleValue()));
      harness.check(Double.isNaN(Double.valueOf("-NaN").doubleValue()));
      harness.check(Double.isNaN(Double.valueOf(" +NaN ").doubleValue()));
      harness.check(Double.isNaN(Double.valueOf(" -NaN ").doubleValue()));
    }
    catch (Exception e) 
    {
      harness.check(false);
      harness.debug(e);
    }
  }
  
}


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Double.parseDouble()/valueOf() - bug 10491
  2004-10-07 16:12 Double.parseDouble()/valueOf() - bug 10491 David Gilbert
@ 2004-10-15 22:35 ` Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2004-10-15 22:35 UTC (permalink / raw)
  To: David Gilbert; +Cc: mauve-patches

[-- Attachment #1: Type: text/plain, Size: 611 bytes --]

Hi,

On Thu, 2004-10-07 at 18:15, David Gilbert wrote:
> The attached tests include checks for the problems reported in bug
> 10491. Similar tests for Float to follow.

Thanks. I added them as follows:

2004-10-15  David Gilbert  <david.gilbert@object-refinery.com>

        * gnu/testlet/java/lang/Double/parseDouble.java: New tests.
        * gnu/testlet/java/lang/Double/valueOf.java: Likewise.
        * gnu/testlet/java/lang/Float/parseFloat.java: Likewise.
        * gnu/testlet/java/lang/Float/valueOf.java: Likewise.

Recent fixes in GNU Classpath made them all pass.

Thanks,

Mark

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-10-15 22:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-07 16:12 Double.parseDouble()/valueOf() - bug 10491 David Gilbert
2004-10-15 22:35 ` Mark Wielaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).