This is the mail archive of the mauve-patches@sources.redhat.com mailing list for the Mauve project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

BigInteger tests


Please find attached some "not too taxing but better than no tests at
all" tests for the BigInteger class.  All tests pass for me with both
Classpath and JDK 1.4:

dgilbert@linux42:~/workspace/mauve> jamvm -classpath .
gnu.testlet.SimpleTestHarness -file CurrentTests.txt -debug
0 of 110 tests failed
dgilbert@linux42:~/workspace/mauve> java -classpath .
gnu.testlet.SimpleTestHarness -file CurrentTests.txt -debug
0 of 110 tests failed

Regards,

Dave Gilbert
www.jfree.org


// Tags: JDK1.1

// 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.math.BigInteger;

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

import java.math.BigInteger;

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

  /**
   * Runs the test using the specified harness.
   * 
   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness)   
  {
    BigInteger a = new BigInteger("-123456789012345678901234567890");
    BigInteger b = new BigInteger("-1");
    BigInteger c = new BigInteger("0");
    BigInteger d = new BigInteger("1");
    BigInteger e = new BigInteger("123456789012345678901234567890");

    harness.check(a.abs().equals(e));
    harness.check(b.abs().equals(d));
    harness.check(c.abs().equals(c));
    harness.check(d.abs().equals(d));
    harness.check(e.abs().equals(e));
  }

}
// Tags: JDK1.1

// 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.math.BigInteger;

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

import java.math.BigInteger;

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

  /**
   * Runs the test using the specified harness.
   * 
   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness)   
  {
    // a few simple cases
    BigInteger i1 = new BigInteger("-1");
    BigInteger i2 = new BigInteger("0");
    BigInteger i3 = new BigInteger("1");
    BigInteger i4 = new BigInteger("2");
    
    harness.check(i1.add(i2).equals(i1));
    harness.check(i1.add(i3).equals(i2));
    harness.check(i1.add(i4).equals(i3));
    harness.check(i3.add(i3).equals(i4));
    
    // some larger numbers
    BigInteger x = new BigInteger("123456789012345678901234567890");
    BigInteger y = new BigInteger("987654321098765432109876543210");
    harness.check(x.add(y).equals(new BigInteger("1111111110111111111011111111100")));
    
    // check a null argument
    boolean pass = false;
    try 
    {
      i1.add(null);
    }
    catch (NullPointerException e)
    {
      pass = true;
    }
    harness.check(pass);
  }

}
// Tags: JDK1.1

// 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.math.BigInteger;

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

import java.math.BigInteger;

/**
 * Some checks for the compareTo() method in the {@link BigInteger} class.
 */
public class compareTo implements Testlet 
{
  /**
   * Runs the test using the specified harness.
   * 
   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness)   
  {
    BigInteger a = new BigInteger("-987654321098765432109876543210");
    BigInteger b = new BigInteger("-1");
    BigInteger c = new BigInteger("0");
    BigInteger d = new BigInteger("1");
    BigInteger e = new BigInteger("987654321098765432109876543210");
    
    harness.check(a.compareTo(a) == 0);
    harness.check(a.compareTo(b) < 0);
    harness.check(a.compareTo(c) < 0);
    harness.check(a.compareTo(d) < 0);
    harness.check(a.compareTo(e) < 0);

    harness.check(b.compareTo(a) > 0);
    harness.check(b.compareTo(b) == 0);
    harness.check(b.compareTo(c) < 0);
    harness.check(b.compareTo(d) < 0);
    harness.check(b.compareTo(e) < 0);

    harness.check(c.compareTo(a) > 0);
    harness.check(c.compareTo(b) > 0);
    harness.check(c.compareTo(c) == 0);
    harness.check(c.compareTo(d) < 0);
    harness.check(c.compareTo(e) < 0);

    harness.check(d.compareTo(a) > 0);
    harness.check(d.compareTo(b) > 0);
    harness.check(d.compareTo(c) > 0);
    harness.check(d.compareTo(d) == 0);
    harness.check(d.compareTo(e) < 0);

    harness.check(e.compareTo(a) > 0);
    harness.check(e.compareTo(b) > 0);
    harness.check(e.compareTo(c) > 0);
    harness.check(e.compareTo(d) > 0);
    harness.check(e.compareTo(e) == 0);
    
    // try the compareTo(Object) method
    boolean pass = false;
    try
    {
      a.compareTo(new Integer(1));
    }
    catch (ClassCastException ee) 
    {
      pass = true;
    }
    harness.check(pass);
    
    // try a null argument
    pass = false;
    try 
    {
      a.compareTo(null);
    }
    catch (NullPointerException ee) 
    {
      pass = true;
    }
    harness.check(pass);
  }

}
// Tags: JDK1.1

// 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.math.BigInteger;

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

import java.math.BigInteger;

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

  /**
   * Runs the test using the specified harness.
   * 
   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness)   
  {
    // some really simple cases
    BigInteger p1 = new BigInteger("1");
    BigInteger p2 = new BigInteger("2");
    BigInteger p3 = new BigInteger("3");
    BigInteger p4 = new BigInteger("4");
    BigInteger m1 = new BigInteger("-1");
    BigInteger m2 = new BigInteger("-2");
    BigInteger m3 = new BigInteger("-3");
    BigInteger m4 = new BigInteger("-4");
    
    harness.check(p4.divide(p2).equals(p2));
    harness.check(m4.divide(p2).equals(m2));
    harness.check(p4.divide(m2).equals(m2));
    harness.check(m4.divide(m2).equals(p2));

    harness.check(p1.divide(p2).equals(BigInteger.ZERO));
    harness.check(m1.divide(p2).equals(BigInteger.ZERO));
    harness.check(p1.divide(m2).equals(BigInteger.ZERO));
    harness.check(m1.divide(m2).equals(BigInteger.ZERO));
    
    harness.check(p3.divide(p2).equals(BigInteger.ONE));
    harness.check(m3.divide(p2).equals(BigInteger.ONE.negate()));
    harness.check(p3.divide(m2).equals(BigInteger.ONE.negate()));
    harness.check(m3.divide(m2).equals(BigInteger.ONE));
   
    // some bigger numbers
    BigInteger bp1 = new BigInteger("12345678901234567890123456789012345678901234567890");
    BigInteger bp2 = new BigInteger("987654321098765432198765");
    BigInteger bm1 = new BigInteger("-12345678901234567890123456789012345678901234567890");
    BigInteger bm2 = new BigInteger("-987654321098765432198765");
    BigInteger resultp = new BigInteger("12499999886093750000298833");
    BigInteger resultm = new BigInteger("-12499999886093750000298833");
    
    harness.check(bp1.divide(bp2).equals(resultp));
    harness.check(bm1.divide(bp2).equals(resultm));
    harness.check(bp1.divide(bm2).equals(resultm));
    harness.check(bm1.divide(bm2).equals(resultp));

    // check null argument
    boolean pass = false;
    try 
    {
      p1.divide(null);
    }
    catch (NullPointerException e)
    {
      pass = true;
    }
    harness.check(pass);
    
    // check zero argument
    pass = false;
    try 
    {
      p1.divide(BigInteger.ZERO);    
    }
    catch (ArithmeticException e)  
    {
      pass = true;
    }
  }

}
// Tags: JDK1.1

// 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.math.BigInteger;

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

import java.math.BigInteger;

/**
 * Some checks for the equals() method in the {@link BigInteger} class.
 */
public class equals implements Testlet 
{
  /**
   * Runs the test using the specified harness.
   * 
   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness)   
  {
    BigInteger a = new BigInteger("-987654321098765432109876543210");
    BigInteger b = new BigInteger("-1");
    BigInteger c = new BigInteger("0");
    BigInteger d = new BigInteger("1");
    BigInteger e = new BigInteger("987654321098765432109876543210");
 
    BigInteger aa = new BigInteger("-987654321098765432109876543210");
    BigInteger bb = new BigInteger("-1");
    BigInteger cc = new BigInteger("0");
    BigInteger dd = new BigInteger("1");
    BigInteger ee = new BigInteger("987654321098765432109876543210");

    harness.check(a.equals(aa));
    harness.check(!a.equals(bb));
    harness.check(!a.equals(cc));
    harness.check(!a.equals(dd));
    harness.check(!a.equals(ee));
    harness.check(!a.equals(null));

    harness.check(!b.equals(aa));
    harness.check(b.equals(bb));
    harness.check(!b.equals(cc));
    harness.check(!b.equals(dd));
    harness.check(!b.equals(ee));
    harness.check(!b.equals(null));
    harness.check(!b.equals(new Integer(-1)));

    harness.check(!c.equals(aa));
    harness.check(!c.equals(bb));
    harness.check(c.equals(cc));
    harness.check(!c.equals(dd));
    harness.check(!c.equals(ee));
    harness.check(!c.equals(null));
    harness.check(!c.equals(new Integer(0)));

    harness.check(!d.equals(aa));
    harness.check(!d.equals(bb));
    harness.check(!d.equals(cc));
    harness.check(d.equals(dd));
    harness.check(!d.equals(ee));
    harness.check(!d.equals(null));
    harness.check(!d.equals(new Integer(1)));

    harness.check(!e.equals(aa));
    harness.check(!e.equals(bb));
    harness.check(!e.equals(cc));
    harness.check(!e.equals(dd));
    harness.check(e.equals(ee));
    harness.check(!e.equals(null));

 
  }

}

Attachment: multiply.class
Description: application/java-byte-code

// Tags: JDK1.1

// 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.math.BigInteger;

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

import java.math.BigInteger;

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

  /**
   * Runs the test using the specified harness.
   * 
   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness)   
  {
    BigInteger a = new BigInteger("-123456789012345678901234567890");
    BigInteger b = new BigInteger("-1");
    BigInteger c = new BigInteger("0");
    BigInteger d = new BigInteger("1");
    BigInteger e = new BigInteger("123456789012345678901234567890");

    harness.check(a.signum() == -1);
    harness.check(b.signum() == -1);
    harness.check(c.signum() == 0);
    harness.check(d.signum() == 1);
    harness.check(e.signum() == 1);

  }

}
// Tags: JDK1.1

// 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.math.BigInteger;

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

import java.math.BigInteger;

/**
 * Some checks for the toString() method in the {@link BigInteger} class.
 */
public class toString implements Testlet 
{
  /**
   * Runs the test using the specified harness.
   * 
   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness)   
  {
    harness.check(new BigInteger("12345678901234567890").toString().equals("12345678901234567890"));
    harness.check(new BigInteger("-12345678901234567890").toString().equals("-12345678901234567890"));
    harness.check(new BigInteger("0").toString().equals("0"));
  }

}
// Tags: JDK1.1

// 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.math.BigInteger;

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

import java.math.BigInteger;

/**
 * Some checks for the valueOf() method in the {@link BigInteger} 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)   
  {
    // can't think of any obvious candidates to test, but...
    harness.check(BigInteger.valueOf(0).equals(new BigInteger("0")));
    harness.check(BigInteger.valueOf(1).equals(new BigInteger("1")));
    harness.check(BigInteger.valueOf(-1).equals(new BigInteger("-1")));
    harness.check(BigInteger.valueOf(Long.MAX_VALUE).equals(new BigInteger("9223372036854775807")));
    harness.check(BigInteger.valueOf(Long.MIN_VALUE).equals(new BigInteger("-9223372036854775808")));    
  }

}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]