Back to index

wims  3.65+svn20090927
Static Public Member Functions | Static Package Functions | Static Package Attributes | Static Private Member Functions | Static Private Attributes
org.javia.arity.UnitTest Class Reference

Runs unit-tests. More...

List of all members.

Static Public Member Functions

static void main (String argv[]) throws SyntaxException, ArityException
 Takes a single command-line argument, an expression; compiles and prints it.
static void main (String argv[]) throws SyntaxException, ArityException
 Takes a single command-line argument, an expression; compiles and prints it.

Static Package Functions

static void profile (Symbols symbols, String str) throws SyntaxException, ArityException
static void runUnitTests ()
static void cheq (double v1, double v2)
static void check (boolean cond)
static void profile (Symbols symbols, String str) throws SyntaxException, ArityException
static void runUnitTests ()
static void cheq (double v1, double v2)
static void check (boolean cond)

Static Package Attributes

static boolean allOk = true
static int checkCounter = 0

Static Private Member Functions

static void profile ()
static void profile ()

Static Private Attributes

static final String profileCases []

Detailed Description

Runs unit-tests.

Usage: java -jar arity.jar

Definition at line 209 of file UnitTest.java.


Member Function Documentation

static void org.javia.arity.UnitTest.check ( boolean  cond) [inline, static, package]

Definition at line 335 of file UnitTest.java.

                                    {
        ++checkCounter;
        if (!cond) {
            allOk = false;
            //Log.log("check " + checkCounter + " failed");
        }
    }
static void org.javia.arity.UnitTest.check ( boolean  cond) [inline, static, package]

Definition at line 335 of file UnitTest.java.

                                    {
        ++checkCounter;
        if (!cond) {
            allOk = false;
            //Log.log("check " + checkCounter + " failed");
        }
    }
static void org.javia.arity.UnitTest.cheq ( double  v1,
double  v2 
) [inline, static, package]

Definition at line 327 of file UnitTest.java.

                                           {
        ++checkCounter;
        if (v1 != v2 && !(Double.isNaN(v1) && Double.isNaN(v2))) {
            allOk = false;
            //Log.log("check equal " + checkCounter + " failed: " + v1 + " " + v2);
        }
    }
static void org.javia.arity.UnitTest.cheq ( double  v1,
double  v2 
) [inline, static, package]

Definition at line 327 of file UnitTest.java.

                                           {
        ++checkCounter;
        if (v1 != v2 && !(Double.isNaN(v1) && Double.isNaN(v2))) {
            allOk = false;
            //Log.log("check equal " + checkCounter + " failed: " + v1 + " " + v2);
        }
    }
static void org.javia.arity.UnitTest.main ( String  argv[]) throws SyntaxException, ArityException [inline, static]

Takes a single command-line argument, an expression; compiles and prints it.

Without arguments, runs the unit tests.

Exceptions:
SyntaxExceptionif there are errors compiling the expression.

Definition at line 215 of file UnitTest.java.

                                                                                  {
        int size = argv.length;
        if (size == 0) {
            runUnitTests();
            profile();
        } else if (size == 1 && argv[0].equals("-profile")) {
            profile();
        } else {
            Symbols symbols = new Symbols();
            for (int i = 0; i < size; ++i) {
                FunctionAndName fan = symbols.compile(argv[i]);
                symbols.define(fan);
            }
            profile(symbols, argv[size-1]);
        }
    }

Here is the call graph for this function:

static void org.javia.arity.UnitTest.main ( String  argv[]) throws SyntaxException, ArityException [inline, static]

Takes a single command-line argument, an expression; compiles and prints it.

Without arguments, runs the unit tests.

Exceptions:
SyntaxExceptionif there are errors compiling the expression.

Definition at line 215 of file UnitTest.java.

                                                                                  {
        int size = argv.length;
        if (size == 0) {
            runUnitTests();
            profile();
        } else if (size == 1 && argv[0].equals("-profile")) {
            profile();
        } else {
            Symbols symbols = new Symbols();
            for (int i = 0; i < size; ++i) {
                FunctionAndName fan = symbols.compile(argv[i]);
                symbols.define(fan);
            }
            profile(symbols, argv[size-1]);
        }
    }

Here is the call graph for this function:

static void org.javia.arity.UnitTest.profile ( Symbols  symbols,
String  str 
) throws SyntaxException, ArityException [inline, static, package]

Definition at line 232 of file UnitTest.java.

                                                                                            {
        Function f = symbols.compile(str).function;
        System.out.println("\n" + str + ": " + f);

        Runtime runtime = Runtime.getRuntime();        

        runtime.gc();
        /*
        long m1 = runtime.freeMemory();
        for (int i = 0; i < 200; ++i) {
            symbols.compile(str);
        }
        long m2 = runtime.freeMemory();
        System.out.println("compilation memory: " + (m1 - m2)/200 + " bytes");
        */
        
        runtime.gc();
        long t1 = System.currentTimeMillis();
        for (int i = 0; i < 1000; ++i) {
            symbols.compile(str);
        }
        long t2 = System.currentTimeMillis();
        System.out.println("compilation time: " + (t2 - t1) + " us");
        
        double args[] = new double[f.arity()];
        /*
        runtime.gc();
        m1 = runtime.freeMemory();
        f.eval(args);
        m2 = runtime.freeMemory();
        if (m2 != m1) {
            System.out.println("execution memory: " + (m1 - m2) + " bytes");
        }
        */
  
        runtime.gc();
        t1 = System.currentTimeMillis();
        for (int i = 0; i < 100000; ++i) {
            f.eval(args);
        }
        t2 = System.currentTimeMillis();
        long delta = t2 - t1;        
        System.out.println("execution time: " + (delta > 100 ? ""+delta/100.+" us" :  ""+delta+" ns"));
    }

Here is the call graph for this function:

static void org.javia.arity.UnitTest.profile ( Symbols  symbols,
String  str 
) throws SyntaxException, ArityException [inline, static, package]

Definition at line 232 of file UnitTest.java.

                                                                                            {
        Function f = symbols.compile(str).function;
        System.out.println("\n" + str + ": " + f);

        Runtime runtime = Runtime.getRuntime();        

        runtime.gc();
        /*
        long m1 = runtime.freeMemory();
        for (int i = 0; i < 200; ++i) {
            symbols.compile(str);
        }
        long m2 = runtime.freeMemory();
        System.out.println("compilation memory: " + (m1 - m2)/200 + " bytes");
        */
        
        runtime.gc();
        long t1 = System.currentTimeMillis();
        for (int i = 0; i < 1000; ++i) {
            symbols.compile(str);
        }
        long t2 = System.currentTimeMillis();
        System.out.println("compilation time: " + (t2 - t1) + " us");
        
        double args[] = new double[f.arity()];
        /*
        runtime.gc();
        m1 = runtime.freeMemory();
        f.eval(args);
        m2 = runtime.freeMemory();
        if (m2 != m1) {
            System.out.println("execution memory: " + (m1 - m2) + " bytes");
        }
        */
  
        runtime.gc();
        t1 = System.currentTimeMillis();
        for (int i = 0; i < 100000; ++i) {
            f.eval(args);
        }
        t2 = System.currentTimeMillis();
        long delta = t2 - t1;        
        System.out.println("execution time: " + (delta > 100 ? ""+delta/100.+" us" :  ""+delta+" ns"));
    }

Here is the call graph for this function:

static void org.javia.arity.UnitTest.profile ( ) [inline, static, private]

Definition at line 285 of file UnitTest.java.

                                  {
        String cases[] = profileCases;
        Symbols symbols = new Symbols();
        try {
            for (int i = 0; i < cases.length; ++i) {
                symbols.define(symbols.compile(cases[i]));
                profile(symbols, cases[i]);
            }
        } catch (Exception e) {
            throw new Error("" + e);
        }
    }

Here is the call graph for this function:

static void org.javia.arity.UnitTest.profile ( ) [inline, static, private]

Definition at line 285 of file UnitTest.java.

                                  {
        String cases[] = profileCases;
        Symbols symbols = new Symbols();
        try {
            for (int i = 0; i < cases.length; ++i) {
                symbols.define(symbols.compile(cases[i]));
                profile(symbols, cases[i]);
            }
        } catch (Exception e) {
            throw new Error("" + e);
        }
    }

Here is the call graph for this function:

static void org.javia.arity.UnitTest.runUnitTests ( ) [inline, static, package]

Definition at line 298 of file UnitTest.java.

                               {
        checkCounter = 0;

        cheq(MoreMath.log(-1), Double.NaN);
        cheq(MoreMath.log(-0.03), Double.NaN);
        cheq(MoreMath.intLog10(-0.03), 0);
        cheq(MoreMath.intLog10(0.03), -2);
        cheq(MoreMath.intExp10(3), 1000);
        cheq(MoreMath.intExp10(-1), 0.1);
        cheq(Util.shortApprox( 1.235, 0.02),  1.24);
        cheq(Util.shortApprox( 1.235, 0.4),   1.2000000000000002);
        cheq(Util.shortApprox(-1.235, 0.02), -1.24);
        cheq(Util.shortApprox(-1.235, 0.4),  -1.2000000000000002);

        check(TestFormat.testFormat());
        try {
            check(TestEval.testEval());
        } catch (ArityException e) {
            System.out.println(""+e);
        }

        if (!allOk) {
            System.out.println("\n*** Some tests FAILED ***\n");
            System.exit(1);
        } else {
            System.out.println("\n*** All tests passed OK ***\n");
        }
    }

Here is the call graph for this function:

static void org.javia.arity.UnitTest.runUnitTests ( ) [inline, static, package]

Definition at line 298 of file UnitTest.java.

                               {
        checkCounter = 0;

        cheq(MoreMath.log(-1), Double.NaN);
        cheq(MoreMath.log(-0.03), Double.NaN);
        cheq(MoreMath.intLog10(-0.03), 0);
        cheq(MoreMath.intLog10(0.03), -2);
        cheq(MoreMath.intExp10(3), 1000);
        cheq(MoreMath.intExp10(-1), 0.1);
        cheq(Util.shortApprox( 1.235, 0.02),  1.24);
        cheq(Util.shortApprox( 1.235, 0.4),   1.2000000000000002);
        cheq(Util.shortApprox(-1.235, 0.02), -1.24);
        cheq(Util.shortApprox(-1.235, 0.4),  -1.2000000000000002);

        check(TestFormat.testFormat());
        try {
            check(TestEval.testEval());
        } catch (ArityException e) {
            System.out.println(""+e);
        }

        if (!allOk) {
            System.out.println("\n*** Some tests FAILED ***\n");
            System.exit(1);
        } else {
            System.out.println("\n*** All tests passed OK ***\n");
        }
    }

Here is the call graph for this function:


Member Data Documentation

static boolean org.javia.arity.UnitTest.allOk = true [static, package]

Definition at line 343 of file UnitTest.java.

static int org.javia.arity.UnitTest.checkCounter = 0 [static, package]

Definition at line 344 of file UnitTest.java.

static final String org.javia.arity.UnitTest.profileCases [static, private]
Initial value:
 {
        
        "(100.5 + 20009.999)*(7+4+3)/(5/2)^3!)*2",
        "fun1(x)=(x+2)*(x+3)",
        "otherFun(x)=(fun1(x-1)*x+1)*(fun1(2-x)+10)",
        "log(x+30.5, 3)^.7*sin(x+.5)"
    }

Definition at line 277 of file UnitTest.java.


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