com.ibm.math
Class DiagBigDecimal

java.lang.Object
  |
  +--com.ibm.math.DiagBigDecimal

public class DiagBigDecimal
extends java.lang.Object

The DiagBigDecimal class forms a standalone test suite for the com.ibm.math.BigDecimal and com.ibm.math.MathContext classes (or, by changing the package statement, other classes of the same names and definition in other packages). It may also be used as a constructed object to embed the tests in an external test harness.

The tests are collected into groups, each corresponding to a tested method or a more general grouping. By default, when run from the static main(java.lang.String[]) method, the run will end if any test fails in a group. The continue argument may be specified to force the tests to run to completion.

Two minor (inner) classes are used; DiagBigDecimal.DiagException is used to signal the failure of a test group, and DiagBigDecimal.Test, a dependent minor class, is used to register tests so that a summary of failures (or success) can be presented as each group is completed.

Version:
1.00 2000.03.27
Author:
Mike Cowlishaw
See Also:
BigDecimal, MathContext

Inner Class Summary
static class DiagBigDecimal.DiagException
          The DiagException class is used to signal the failure of a test group.
 class DiagBigDecimal.Test
          The Test class is used to record a specific test.
 
Constructor Summary
DiagBigDecimal()
          Constructs a DiagBigDecimal test suite.
 
Method Summary
 void diagabs()
          Test the BigDecimal.abs() method.
 void diagadd()
          Test the BigDecimal.add(com.ibm.math.BigDecimal) method.
 void diagbyteValue()
          Test the BigDecimal.byteValue() method.
 void diagcompareto()
          Test the BigDecimal.compareTo(BigDecimal) method.
 void diagcomparetoObj()
          Test the BigDecimal.compareTo(java.lang.Object) method.
 void diagconstructors()
          Test constructors (and Object.toString() for equalities).
 void diagdivide()
          Test the BigDecimal.divide(com.ibm.math.BigDecimal) method.
 void diagdivideInteger()
          Test the BigDecimal.divideInteger(com.ibm.math.BigDecimal) method.
 void diagdoublevalue()
          Test the BigDecimal.doubleValue() method.
 void diagequals()
          Test the BigDecimal.equals(java.lang.Object) method.
 void diagfloatvalue()
          Test the BigDecimal.floatValue() method.
 void diagformat()
          Test the BigDecimal.format(int, int) method.
 void diaghashcode()
          Test the BigDecimal.hashCode() method.
 void diagintvalue()
          Test the BigDecimal.intValue() method.
 void diaglongvalue()
          Test the BigDecimal.longValue() method.
 void diagmath()
          Test general arithmetic (base operators).
 void diagmathcontext()
          Test the MathContext class.
 void diagmax()
          Test the BigDecimal.max(com.ibm.math.BigDecimal) method.
 void diagmin()
          Test the BigDecimal.min(com.ibm.math.BigDecimal) method.
 void diagmovepointleft()
          Test the BigDecimal.movePointLeft(int) method.
 void diagmovepointright()
          Test the BigDecimal.movePointRight(int) method.
 void diagmultiply()
          Test the BigDecimal.multiply(com.ibm.math.BigDecimal) method.
 void diagmutation()
          Mutation tests (checks that contents of constant objects are unchanged).
 void diagnegate()
          Test the BigDecimal.negate() method.
 void diagplus()
          Test the BigDecimal.plus() method.
 void diagpow()
          Test the BigDecimal.pow(com.ibm.math.BigDecimal) method.
 void diagremainder()
          Test the BigDecimal.remainder(com.ibm.math.BigDecimal) method.
 int diagrun(boolean isContinue)
          Run the tests in the test suite.
 void diagscale()
          Test the BigDecimal.scale() method.
 void diagsetscale()
          Test the BigDecimal.setScale(int) method.
 void diagshortvalue()
          Test the BigDecimal.shortValue() method.
 void diagsignum()
          Test the BigDecimal.signum() method.
 void diagsubtract()
          Test the BigDecimal.subtract(com.ibm.math.BigDecimal) method.
 void diagtobigdecimal()
          Test the BigDecimal.toBigDecimal() method.
 void diagtobiginteger()
          Test the BigDecimal.toBigInteger() method.
 void diagtochararray()
          Test the BigDecimal.toCharArray() method.
 void diagtostring()
          Test the BigDecimal.toString() method.
 void diagunscaledvalue()
          Test the BigDecimal.unscaledValue() method.
 void diagvalueof()
          Test the BigDecimal.valueOf(double) method [long and double].
static void main(java.lang.String[] args)
          Entry point for stand-alone run.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DiagBigDecimal

public DiagBigDecimal()
Constructs a DiagBigDecimal test suite.

Invoke its diagrun(boolean) method to run the tests.

Method Detail

diagrun

public int diagrun(boolean isContinue)
Run the tests in the test suite.
Parameters:
isContinue - The boolean which determines whether to stop running after a group fails. If 1 (true) then the tests should be run to completion if possible; if 0 (false) then the run will end if a group fails.
Returns:
an int which is 0 if all tests were successful, >0 (the count of failures) if some failures were detected, or <0 if an unexpected Exception was signalled.

diagconstructors

public void diagconstructors()
Test constructors (and Object.toString() for equalities).

diagmutation

public void diagmutation()
Mutation tests (checks that contents of constant objects are unchanged).

diagabs

public void diagabs()
Test the BigDecimal.abs() method.

diagadd

public void diagadd()
Test the BigDecimal.add(com.ibm.math.BigDecimal) method.

diagcompareto

public void diagcompareto()
Test the BigDecimal.compareTo(BigDecimal) method.

diagdivide

public void diagdivide()
Test the BigDecimal.divide(com.ibm.math.BigDecimal) method.

diagdivideInteger

public void diagdivideInteger()
Test the BigDecimal.divideInteger(com.ibm.math.BigDecimal) method.

diagmax

public void diagmax()
Test the BigDecimal.max(com.ibm.math.BigDecimal) method.

diagmin

public void diagmin()
Test the BigDecimal.min(com.ibm.math.BigDecimal) method.

diagmultiply

public void diagmultiply()
Test the BigDecimal.multiply(com.ibm.math.BigDecimal) method.

diagnegate

public void diagnegate()
Test the BigDecimal.negate() method.

diagplus

public void diagplus()
Test the BigDecimal.plus() method.

diagpow

public void diagpow()
Test the BigDecimal.pow(com.ibm.math.BigDecimal) method.

diagremainder

public void diagremainder()
Test the BigDecimal.remainder(com.ibm.math.BigDecimal) method.

diagsubtract

public void diagsubtract()
Test the BigDecimal.subtract(com.ibm.math.BigDecimal) method.

diagbyteValue

public void diagbyteValue()
Test the BigDecimal.byteValue() method.

diagcomparetoObj

public void diagcomparetoObj()
Test the BigDecimal.compareTo(java.lang.Object) method.

diagdoublevalue

public void diagdoublevalue()
Test the BigDecimal.doubleValue() method.

diagequals

public void diagequals()
Test the BigDecimal.equals(java.lang.Object) method.

diagfloatvalue

public void diagfloatvalue()
Test the BigDecimal.floatValue() method.

diagformat

public void diagformat()
Test the BigDecimal.format(int, int) method.

diaghashcode

public void diaghashcode()
Test the BigDecimal.hashCode() method.

diagintvalue

public void diagintvalue()
Test the BigDecimal.intValue() method.

diaglongvalue

public void diaglongvalue()
Test the BigDecimal.longValue() method.

diagmovepointleft

public void diagmovepointleft()
Test the BigDecimal.movePointLeft(int) method.

diagmovepointright

public void diagmovepointright()
Test the BigDecimal.movePointRight(int) method.

diagscale

public void diagscale()
Test the BigDecimal.scale() method.

diagsetscale

public void diagsetscale()
Test the BigDecimal.setScale(int) method.

diagshortvalue

public void diagshortvalue()
Test the BigDecimal.shortValue() method.

diagsignum

public void diagsignum()
Test the BigDecimal.signum() method.

diagtobigdecimal

public void diagtobigdecimal()
Test the BigDecimal.toBigDecimal() method.

diagtobiginteger

public void diagtobiginteger()
Test the BigDecimal.toBigInteger() method.

diagtochararray

public void diagtochararray()
Test the BigDecimal.toCharArray() method.

diagtostring

public void diagtostring()
Test the BigDecimal.toString() method.

diagunscaledvalue

public void diagunscaledvalue()
Test the BigDecimal.unscaledValue() method.

diagvalueof

public void diagvalueof()
Test the BigDecimal.valueOf(double) method [long and double].

diagmathcontext

public void diagmathcontext()
Test the MathContext class.

diagmath

public void diagmath()
Test general arithmetic (base operators).

Unlike the specific method tests, these tests were randomly generated by an IBM Object Rexx procedure, then manually corrected for known differences from ANSI X3-274. These differences are:

  1. the trigger point in exponential notation is fixed in ANSI X3-274 but varies with DIGITS in Classic and Object Rexx
  2. some trailing zeros were missing (e.g., 1.3 + 1E-60 should show seven trailing zeros)
  3. the power operator is less accurate in Object Rexx
  4. ANSI X3-274 [errata 1999] rounds input numbers to DIGITS (rather than truncating to DIGITS+1).

main

public static void main(java.lang.String[] args)
Entry point for stand-alone run. It constructs a DiagBigDecimal object and then invokes its diagrun(boolean) method to run the test suite.
Parameters:
args - The command line argument string array. if the first word is 'continue' then try and run all tests, otherwise stop after the first failing test group.


Copyright (c) 1998-2000 IBM Corporation and others.