Back to index

wims  3.65+svn20090927
Static Package Functions | Static Package Attributes | Static Private Member Functions
org.javia.arity.TestEval Class Reference
Collaboration diagram for org.javia.arity.TestEval:
Collaboration graph
[legend]

List of all members.

Static Package Functions

static boolean testEval () throws ArityException
static boolean testEval () throws ArityException

Static Package Attributes

static EvalCase cases []

Static Private Member Functions

static boolean equal (double a, double b)
static boolean equal (double a, double b)

Detailed Description

Definition at line 31 of file UnitTest.java.


Member Function Documentation

static boolean org.javia.arity.TestEval.equal ( double  a,
double  b 
) [inline, static, private]

Definition at line 80 of file UnitTest.java.

                                                     {
        return Math.abs(a-b) < 1E-15 ||
            Double.doubleToLongBits(a) == Double.doubleToLongBits(b);
    }

Here is the caller graph for this function:

static boolean org.javia.arity.TestEval.equal ( double  a,
double  b 
) [inline, static, private]

Definition at line 80 of file UnitTest.java.

                                                     {
        return Math.abs(a-b) < 1E-15 ||
            Double.doubleToLongBits(a) == Double.doubleToLongBits(b);
    }
static boolean org.javia.arity.TestEval.testEval ( ) throws ArityException [inline, static, package]

Definition at line 85 of file UnitTest.java.

                                                    {
        final String spaces = "                                           ";
        boolean allOk = true;
        Symbols symbols = new Symbols();
        for (int i = 0; i < cases.length; ++i) {
            EvalCase c = cases[i];
            String strResult;
            boolean ok;
            try {
                double actual;
                if (Symbols.isDefinition(c.expr)) {
                    FunctionAndName fan = symbols.compile(c.expr);
                    symbols.define(fan);
                    Function f = fan.function;
                    actual = f.arity()==0 ? f.eval() : EvalCase.FUN;
                    strResult = (f.arity()==0 ? Util.doubleToString(actual, 1) : f.toString());
                } else {
                    actual = symbols.eval(c.expr);
                    strResult = Util.doubleToString(actual, 1);
                }
                ok = equal(c.result, actual);
            } catch (SyntaxException e) {
                strResult = e.toString();
                ok = c.result == EvalCase.ERR;
            }
            System.out.println((ok ? "" : "failed (expected " + c.result + "): ")
                               + c.expr
                               + spaces.substring(0, Math.max(15-c.expr.length(), 0)) + " = " 
                               + strResult);
            if (!ok) {
                allOk = false;
            }
        }
        return allOk;
    }

Here is the call graph for this function:

static boolean org.javia.arity.TestEval.testEval ( ) throws ArityException [inline, static, package]

Definition at line 85 of file UnitTest.java.

                                                    {
        final String spaces = "                                           ";
        boolean allOk = true;
        Symbols symbols = new Symbols();
        for (int i = 0; i < cases.length; ++i) {
            EvalCase c = cases[i];
            String strResult;
            boolean ok;
            try {
                double actual;
                if (Symbols.isDefinition(c.expr)) {
                    FunctionAndName fan = symbols.compile(c.expr);
                    symbols.define(fan);
                    Function f = fan.function;
                    actual = f.arity()==0 ? f.eval() : EvalCase.FUN;
                    strResult = (f.arity()==0 ? Util.doubleToString(actual, 1) : f.toString());
                } else {
                    actual = symbols.eval(c.expr);
                    strResult = Util.doubleToString(actual, 1);
                }
                ok = equal(c.result, actual);
            } catch (SyntaxException e) {
                strResult = e.toString();
                ok = c.result == EvalCase.ERR;
            }
            System.out.println((ok ? "" : "failed (expected " + c.result + "): ")
                               + c.expr
                               + spaces.substring(0, Math.max(15-c.expr.length(), 0)) + " = " 
                               + strResult);
            if (!ok) {
                allOk = false;
            }
        }
        return allOk;
    }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

static EvalCase org.javia.arity.TestEval.cases [static, package]

Definition at line 32 of file UnitTest.java.


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