Classes | Static Public Member Functions | Static Package Attributes | Static Private Member Functions | Static Private Attributes

jscicalc.complex.Test Class Reference

This class is only used to test formatting. More...

Collaboration diagram for jscicalc.complex.Test:
Collaboration graph
[legend]

List of all members.

Classes

class  Pair
 Local class used by parseGeneral(). More...

Static Public Member Functions

static void main (String[] args)
 Call this function to process a test file.
static Pair parseStandard (String s, int radix, int e)
 Parses an integer.
static Pair parseGeneral (String s, int radix, int radix2)
 Parses a number.

Static Package Attributes

static final double DBL_EPSILON = 2.2204460492503131e-16
 Used for relative errors.

Static Private Member Functions

static Object parse (String expressionString, Base b)
 Used to try to create a Complex from a String expression.
static Object parse2 (String expressionString, Base b)
 Used to try to create a Complex from a String expression.
static boolean checkNumber (String expression, Complex z, Notation n, Base base)
 Compare expression and result strings.
static int sigDigits (String number)
 Find the number of significant digits in the number.
static int getRadix (Base b)
 Used to convert Base to corresponding int.
static int getRadix2 (Base b)
 Used to convert Base to corresponding int.
static boolean compare (double number, double rounded, double absolute, int sigDigits, int base)
 The main comparison function.
static boolean testRelative (double result, double expected, double relative_error)
 Test if result matches expected accurately.

Static Private Attributes

static final java.util.EnumSet
< Base
bases = java.util.EnumSet.of( Base.BINARY, Base.OCTAL, Base.DECIMAL, Base.HEXADECIMAL )
 Not used.
static final double e = Math.exp( 1 )
 The number e.
static final double p = 1.0 / 180
 Could be used for angles.
static Parser parser = new Parser()
 A Parser.
static final
java.util.regex.Pattern 
plus = java.util.regex.Pattern.compile( "^\\+" )
 Leading plus sign.
static final
java.util.regex.Pattern 
plus2 = java.util.regex.Pattern.compile( "\\+$" )
 Trailing plus sign.
static final
java.util.regex.Pattern 
minus = java.util.regex.Pattern.compile( "&#8722;" )
 HTML minus sign.
static final
java.util.regex.Pattern 
minus2 = java.util.regex.Pattern.compile( "-" )
 Java minus sign.
static final
java.util.regex.Pattern 
empty = java.util.regex.Pattern.compile( "" )
 Nothing.
static final
java.util.regex.Pattern 
J = java.util.regex.Pattern.compile( "i" )
 The number i.
static final
java.util.regex.Pattern 
html = java.util.regex.Pattern.compile( "</?html>" )
 Start or end html.
static final
java.util.regex.Pattern 
esymbol = java.util.regex.Pattern.compile( "e<sup>" )
 Polar representation start of exponent.
static final
java.util.regex.Pattern 
decexp = java.util.regex.Pattern.compile( "<sup>" )
 Scientific representation start of exponent.
static final
java.util.regex.Pattern 
sup = java.util.regex.Pattern.compile( "</sup>" )
 End of exponent.
static final
java.util.regex.Pattern 
dec = java.util.regex.Pattern.compile( "[+-]?[0-9A-F]*\\.?[0-9A-F]*(e[+-]?[0-9A-F]+)?" )
 A number (originally decimal but now any).
static final
java.util.regex.Pattern 
deci
 A number (originally decimal but now any) follwoed by i.
static final
java.util.regex.Pattern 
begin = java.util.regex.Pattern.compile( "[+-]?0?\\.0*" )
 Start of number smaller than 1 in size.
static final
java.util.regex.Pattern 
end = java.util.regex.Pattern.compile( "e[+-]?[0-9A-F]+" )
 End of number.
static final
java.util.regex.Pattern 
trailingzero = java.util.regex.Pattern.compile( "0*$" )
 Trailing zero.
static final
java.util.regex.Pattern 
digit = java.util.regex.Pattern.compile( "[0-9A-F]" )
 Any digit.
static final
java.util.regex.Pattern 
octothorp = java.util.regex.Pattern.compile( "^#" )
 Octothorp (hash): used for comments.
static final
java.util.regex.Pattern 
calc = java.util.regex.Pattern.compile( "^.*, " )
 Used to identify if there is more than one expression on a line.
static final
java.util.regex.Pattern 
comma = java.util.regex.Pattern.compile( ", $" )
 Used to identify comma.
static final
java.util.regex.Pattern 
overflow = java.util.regex.Pattern.compile( "^overflow$" )
 Used to identify overflow (from Parser).
static final
java.util.regex.Pattern 
basepoint = java.util.regex.Pattern.compile( "\\." )
 The base point.
static final
java.util.regex.Pattern 
esymbol2 = java.util.regex.Pattern.compile( "e" )
 The exponent symbol e.
static final
java.util.regex.Pattern 
exponent2 = java.util.regex.Pattern.compile( "e[+-]?[0-9A-F]+" )
 An exponent.
static final
java.util.regex.Pattern 
hex = java.util.regex.Pattern.compile( "^Hex " )
 Start of hexadecimal expression.
static final
java.util.regex.Pattern 
bin = java.util.regex.Pattern.compile( "^Bin " )
 Start of binary expression.
static final
java.util.regex.Pattern 
oct = java.util.regex.Pattern.compile( "^Oct " )
 Start of octal expression.
static AngleType angleType
 AngleType.

Detailed Description

This class is only used to test formatting.

Author:
J. D. Lamb
Version:
Revision:
1.8

Member Function Documentation

static boolean jscicalc.complex.Test.checkNumber ( String  expression,
Complex  z,
Notation  n,
Base  base 
) [static, private]
static boolean jscicalc.complex.Test.compare ( double  number,
double  rounded,
double  absolute,
int  sigDigits,
int  base 
) [static, private]

The main comparison function.

This compares a number with an approximation to it. The comparison considers numbers to sigDigits significat digits in the approximation, but also allows the absolute difference between two numbers to be considered and if the difference exceeds absolute, the numbers are considered the same.

Parameters:
number The number
rounded An approximation to the number
absolute The allowable absolute difference between the number and approximation.
sigDigits The number of digits that should match
base The base: 2, 8, 10 or 16
Returns:
true or false according as the numbers match or not

Referenced by jscicalc.complex.Test.checkNumber().

static int jscicalc.complex.Test.getRadix ( Base  b  )  [static, private]

Used to convert Base to corresponding int.

Parameters:
b A Base
Returns:
The base as an integer: 2, 8, 10 or 16.

Referenced by jscicalc.complex.Test.checkNumber(), and jscicalc.complex.Test.getRadix2().

static int jscicalc.complex.Test.getRadix2 ( Base  b  )  [static, private]

Used to convert Base to corresponding int.

Differs from getRadix() by returning 10 if b is Base.Binary. Hence appropriate for evaluating output strings.

Parameters:
b A Base
Returns:
The base as an integer: 8, 10 or 16.

References jscicalc.complex.Test.getRadix().

Referenced by jscicalc.complex.Test.checkNumber().

static void jscicalc.complex.Test.main ( String[]  args  )  [static]

Call this function to process a test file.

The file should be called test.jsc, located in the build directory and the function called as java jscicalc/complex/Test. The function reads a number of numbers, together with a base, denoted Bin, Oct, Hex or nothing for binary, octal, hexadecimal or decimal formats. All eight possible combinations of notation are tested for the number and for each both input/internal and input/output checks are done.

Parameters:
args Standard argument: not used

References jscicalc.complex.Complex.abs(), jscicalc.complex.Test.angleType, jscicalc.complex.Test.bin, jscicalc.complex.Test.calc, jscicalc.complex.Test.checkNumber(), jscicalc.complex.Test.comma, jscicalc.complex.Test.DBL_EPSILON, jscicalc.complex.Test.e, jscicalc.complex.Test.hex, jscicalc.complex.Complex.imaginary(), jscicalc.complex.Test.oct, jscicalc.complex.Test.octothorp, jscicalc.complex.Test.parse(), jscicalc.complex.Test.parse2(), jscicalc.complex.Complex.real(), jscicalc.Notation.setComplex(), jscicalc.Notation.setNonComplex(), jscicalc.Notation.setPolar(), jscicalc.Notation.setRectangular(), jscicalc.Notation.setScientific(), jscicalc.Notation.setStandard(), and jscicalc.complex.Test.testRelative().

static Object jscicalc.complex.Test.parse ( String  expressionString,
Base  b 
) [static, private]

Used to try to create a Complex from a String expression.

Used internally. A base is needed to be sure the expression is interpreted correctly.

Parameters:
expressionString The expression
b The Base
Returns:
An Object, hopefully a Complex

References jscicalc.Parser.add(), jscicalc.complex.Test.angleType, jscicalc.Parser.base, jscicalc.Parser.clearExpression(), jscicalc.Parser.evaluate(), and jscicalc.complex.Test.parser.

Referenced by jscicalc.complex.Test.main().

static Object jscicalc.complex.Test.parse2 ( String  expressionString,
Base  b 
) [static, private]

Used to try to create a Complex from a String expression.

Used internally. A base is needed to be sure the expression is interpreted correctly.

Parameters:
expressionString The expression
b The Base
Returns:
An Object, hopefully a Complex

References jscicalc.Parser.add(), jscicalc.complex.Test.angleType, jscicalc.Parser.base, jscicalc.Parser.clearExpression(), jscicalc.Parser.evaluate(), and jscicalc.complex.Test.parser.

Referenced by jscicalc.complex.Test.main().

static Pair jscicalc.complex.Test.parseGeneral ( String  s,
int  radix,
int  radix2 
) [static]

Parses a number.

The base to use is given by radix.

Parameters:
s The integer as a string
radix Used for the base
radix2 Used for the base
Returns:
A number and its number of significant digits

References jscicalc.complex.Test.e, jscicalc.complex.Test.empty, jscicalc.complex.Test.esymbol2, jscicalc.complex.Test.exponent2, jscicalc.complex.Test.minus2, jscicalc.complex.Test.parseStandard(), and jscicalc.complex.Test.plus.

Referenced by jscicalc.complex.Test.checkNumber().

static Pair jscicalc.complex.Test.parseStandard ( String  s,
int  radix,
int  e 
) [static]

Parses an integer.

The base to use is given by radix and e is used to handle exponents.

Parameters:
s The integer as a string
radix Used for the base
e Used for exponent
Returns:
A number and its number of significant digits
See also:
parseGeneral()

References jscicalc.complex.Test.basepoint.

Referenced by jscicalc.complex.Test.parseGeneral().

static int jscicalc.complex.Test.sigDigits ( String  number  )  [static, private]

Find the number of significant digits in the number.

Parameters:
number A string representation (including e )
Returns:
The number of significant digits

References jscicalc.complex.Test.begin, jscicalc.complex.Test.digit, jscicalc.complex.Test.end, and jscicalc.complex.Test.trailingzero.

Referenced by jscicalc.complex.Test.checkNumber().

static boolean jscicalc.complex.Test.testRelative ( double  result,
double  expected,
double  relative_error 
) [static, private]

Test if result matches expected accurately.

Based on functions in the GNU scientific library.

Parameters:
result The result of a calculation
expected The expected result
relative_error The relative error in the calculation
Returns:
true or false according as result matches expected

Referenced by jscicalc.complex.Test.main().


Member Data Documentation

final java.util.regex.Pattern jscicalc.complex.Test.basepoint = java.util.regex.Pattern.compile( "\\." ) [static, private]

The base point.

Referenced by jscicalc.complex.Test.parseStandard().

final java.util.EnumSet<Base> jscicalc.complex.Test.bases = java.util.EnumSet.of( Base.BINARY, Base.OCTAL, Base.DECIMAL, Base.HEXADECIMAL ) [static, private]

Not used.

final java.util.regex.Pattern jscicalc.complex.Test.begin = java.util.regex.Pattern.compile( "[+-]?0?\\.0*" ) [static, private]

Start of number smaller than 1 in size.

Referenced by jscicalc.complex.Test.sigDigits().

final java.util.regex.Pattern jscicalc.complex.Test.bin = java.util.regex.Pattern.compile( "^Bin " ) [static, private]

Start of binary expression.

Referenced by jscicalc.complex.Test.main().

final java.util.regex.Pattern jscicalc.complex.Test.calc = java.util.regex.Pattern.compile( "^.*, " ) [static, private]

Used to identify if there is more than one expression on a line.

Referenced by jscicalc.complex.Test.main().

final java.util.regex.Pattern jscicalc.complex.Test.comma = java.util.regex.Pattern.compile( ", $" ) [static, private]

Used to identify comma.

Referenced by jscicalc.complex.Test.main().

final double jscicalc.complex.Test.DBL_EPSILON = 2.2204460492503131e-16 [static, package]

Used for relative errors.

Referenced by jscicalc.complex.Test.main().

final java.util.regex.Pattern jscicalc.complex.Test.dec = java.util.regex.Pattern.compile( "[+-]?[0-9A-F]*\\.?[0-9A-F]*(e[+-]?[0-9A-F]+)?" ) [static, private]

A number (originally decimal but now any).

Referenced by jscicalc.complex.Test.checkNumber().

final java.util.regex.Pattern jscicalc.complex.Test.decexp = java.util.regex.Pattern.compile( "<sup>" ) [static, private]

Scientific representation start of exponent.

Referenced by jscicalc.complex.Test.checkNumber().

final java.util.regex.Pattern jscicalc.complex.Test.deci [static, private]
Initial value:
 java.util.regex.Pattern
    .compile( "[+-]?[0-9A-F]*\\.?[0-9A-F]*(e[+-]?[0-9A-F]+)?i" )

A number (originally decimal but now any) follwoed by i.

Referenced by jscicalc.complex.Test.checkNumber().

final java.util.regex.Pattern jscicalc.complex.Test.digit = java.util.regex.Pattern.compile( "[0-9A-F]" ) [static, private]

Any digit.

Referenced by jscicalc.complex.Test.sigDigits().

final double jscicalc.complex.Test.e = Math.exp( 1 ) [static, private]
final java.util.regex.Pattern jscicalc.complex.Test.empty = java.util.regex.Pattern.compile( "" ) [static, private]
final java.util.regex.Pattern jscicalc.complex.Test.end = java.util.regex.Pattern.compile( "e[+-]?[0-9A-F]+" ) [static, private]

End of number.

Referenced by jscicalc.complex.Test.sigDigits().

final java.util.regex.Pattern jscicalc.complex.Test.esymbol = java.util.regex.Pattern.compile( "e<sup>" ) [static, private]

Polar representation start of exponent.

Referenced by jscicalc.complex.Test.checkNumber().

final java.util.regex.Pattern jscicalc.complex.Test.esymbol2 = java.util.regex.Pattern.compile( "e" ) [static, private]

The exponent symbol e.

Referenced by jscicalc.complex.Test.parseGeneral().

final java.util.regex.Pattern jscicalc.complex.Test.exponent2 = java.util.regex.Pattern.compile( "e[+-]?[0-9A-F]+" ) [static, private]

An exponent.

Referenced by jscicalc.complex.Test.parseGeneral().

final java.util.regex.Pattern jscicalc.complex.Test.hex = java.util.regex.Pattern.compile( "^Hex " ) [static, private]

Start of hexadecimal expression.

Referenced by jscicalc.complex.Test.main().

final java.util.regex.Pattern jscicalc.complex.Test.html = java.util.regex.Pattern.compile( "</?html>" ) [static, private]

Start or end html.

Referenced by jscicalc.complex.Test.checkNumber().

final java.util.regex.Pattern jscicalc.complex.Test.J = java.util.regex.Pattern.compile( "i" ) [static, private]

The number i.

Referenced by jscicalc.complex.Test.checkNumber().

final java.util.regex.Pattern jscicalc.complex.Test.minus = java.util.regex.Pattern.compile( "&#8722;" ) [static, private]

HTML minus sign.

Referenced by jscicalc.complex.Test.checkNumber().

final java.util.regex.Pattern jscicalc.complex.Test.minus2 = java.util.regex.Pattern.compile( "-" ) [static, private]
final java.util.regex.Pattern jscicalc.complex.Test.oct = java.util.regex.Pattern.compile( "^Oct " ) [static, private]

Start of octal expression.

Referenced by jscicalc.complex.Test.main().

final java.util.regex.Pattern jscicalc.complex.Test.octothorp = java.util.regex.Pattern.compile( "^#" ) [static, private]

Octothorp (hash): used for comments.

Referenced by jscicalc.complex.Test.main().

final java.util.regex.Pattern jscicalc.complex.Test.overflow = java.util.regex.Pattern.compile( "^overflow$" ) [static, private]

Used to identify overflow (from Parser).

Referenced by jscicalc.complex.Test.checkNumber().

final double jscicalc.complex.Test.p = 1.0 / 180 [static, private]

Could be used for angles.

Referenced by jscicalc.complex.Test.checkNumber().

Parser jscicalc.complex.Test.parser = new Parser() [static, private]

A Parser.

Used to evaluate expressions: hence automatic testing.

Referenced by jscicalc.complex.Test.parse(), and jscicalc.complex.Test.parse2().

final java.util.regex.Pattern jscicalc.complex.Test.plus = java.util.regex.Pattern.compile( "^\\+" ) [static, private]
final java.util.regex.Pattern jscicalc.complex.Test.plus2 = java.util.regex.Pattern.compile( "\\+$" ) [static, private]

Trailing plus sign.

Referenced by jscicalc.complex.Test.checkNumber().

final java.util.regex.Pattern jscicalc.complex.Test.sup = java.util.regex.Pattern.compile( "</sup>" ) [static, private]

End of exponent.

Referenced by jscicalc.complex.Test.checkNumber().

final java.util.regex.Pattern jscicalc.complex.Test.trailingzero = java.util.regex.Pattern.compile( "0*$" ) [static, private]

Trailing zero.

Referenced by jscicalc.complex.Test.sigDigits().


The documentation for this class was generated from the following file: