Search in sources :

Example 1 with TimeConstrainedEvaluator

use of org.matheclipse.core.eval.TimeConstrainedEvaluator in project symja_android_library by axkr.

the class PatternMatchingTestCase method check.

public void check(EvalEngine engine, boolean configMode, IAST ast, String strResult) {
    try {
        StringWriter buf = new StringWriter();
        Config.SERVER_MODE = configMode;
        if (Config.SERVER_MODE) {
            IAST inExpr = ast;
            TimeConstrainedEvaluator utility = new TimeConstrainedEvaluator(engine, false, Config.FOREVER);
            utility.constrainedEval(buf, inExpr);
        } else {
            if (ast != null) {
                OutputFormFactory off = OutputFormFactory.get();
                off.setIgnoreNewLine(true);
                OutputFormFactory.get().convert(buf, ast);
            }
        }
        assertEquals(buf.toString(), strResult);
    } catch (Exception e) {
        e.printStackTrace();
        assertEquals(e, "");
    }
}
Also used : TimeConstrainedEvaluator(org.matheclipse.core.eval.TimeConstrainedEvaluator) StringWriter(java.io.StringWriter) IAST(org.matheclipse.core.interfaces.IAST) OutputFormFactory(org.matheclipse.core.form.output.OutputFormFactory)

Example 2 with TimeConstrainedEvaluator

use of org.matheclipse.core.eval.TimeConstrainedEvaluator in project symja_android_library by axkr.

the class AbstractTestCase method check.

public void check(EvalEngine engine, boolean configMode, IAST ast, String strResult) {
    boolean mode = Config.SERVER_MODE;
    try {
        StringWriter buf = new StringWriter();
        Config.SERVER_MODE = configMode;
        if (Config.SERVER_MODE) {
            IAST inExpr = ast;
            TimeConstrainedEvaluator utility = new TimeConstrainedEvaluator(engine, false, Config.FOREVER);
            utility.constrainedEval(buf, inExpr);
        } else {
            if (ast != null) {
                OutputFormFactory off = OutputFormFactory.get();
                off.setIgnoreNewLine(true);
                off.convert(buf, ast);
            }
        }
        assertEquals(strResult, buf.toString());
    } catch (Exception e) {
        e.printStackTrace();
        assertEquals("", e);
    } finally {
        Config.SERVER_MODE = mode;
    }
}
Also used : TimeConstrainedEvaluator(org.matheclipse.core.eval.TimeConstrainedEvaluator) StringWriter(java.io.StringWriter) IAST(org.matheclipse.core.interfaces.IAST) OutputFormFactory(org.matheclipse.core.form.output.OutputFormFactory)

Example 3 with TimeConstrainedEvaluator

use of org.matheclipse.core.eval.TimeConstrainedEvaluator in project symja_android_library by axkr.

the class MainTestCase method check.

public void check(EvalEngine engine, boolean configMode, IAST ast, String strResult) {
    boolean mode = Config.SERVER_MODE;
    try {
        StringWriter buf = new StringWriter();
        Config.SERVER_MODE = configMode;
        if (Config.SERVER_MODE) {
            IAST inExpr = ast;
            TimeConstrainedEvaluator utility = new TimeConstrainedEvaluator(engine, false, Config.FOREVER, true);
            utility.constrainedEval(buf, inExpr);
        } else {
            if (ast != null) {
                OutputFormFactory off = OutputFormFactory.get();
                off.setIgnoreNewLine(true);
                off.convert(buf, ast);
            }
        }
        assertEquals(buf.toString(), strResult);
    } catch (Exception e) {
        e.printStackTrace();
        assertEquals(e.getMessage(), "");
    } finally {
        Config.SERVER_MODE = mode;
    }
}
Also used : TimeConstrainedEvaluator(org.matheclipse.core.eval.TimeConstrainedEvaluator) StringWriter(java.io.StringWriter) IAST(org.matheclipse.core.interfaces.IAST) OutputFormFactory(org.matheclipse.core.form.output.OutputFormFactory)

Example 4 with TimeConstrainedEvaluator

use of org.matheclipse.core.eval.TimeConstrainedEvaluator in project symja_android_library by axkr.

the class PatternMatchingTestCase method check.

public void check(EvalEngine engine, boolean configMode, String strEval, String strResult, boolean relaxedSyntax) {
    try {
        if (strEval.length() == 0 && strResult.length() == 0) {
            return;
        }
        IExpr result;
        StringWriter buf = new StringWriter();
        // configMode;
        Config.SERVER_MODE = configMode;
        if (Config.SERVER_MODE) {
            Parser parser = new Parser(relaxedSyntax);
            ASTNode node = parser.parse(strEval);
            IExpr inExpr = AST2Expr.CONST.convert(node);
            TimeConstrainedEvaluator utility = new TimeConstrainedEvaluator(engine, false, Config.FOREVER, relaxedSyntax);
            result = utility.constrainedEval(buf, inExpr);
        } else {
            Parser parser = new Parser(relaxedSyntax);
            ASTNode node = parser.parse(strEval);
            IExpr inExpr = AST2Expr.CONST.convert(node);
            result = util.evaluate(inExpr);
            if ((result != null) && !result.equals(F.Null)) {
                OutputFormFactory off = OutputFormFactory.get(relaxedSyntax);
                off.setIgnoreNewLine(true);
                off.convert(buf, result);
            }
        }
        assertEquals(buf.toString(), strResult);
    } catch (Exception e) {
        e.printStackTrace();
        assertEquals(e, "");
    }
}
Also used : TimeConstrainedEvaluator(org.matheclipse.core.eval.TimeConstrainedEvaluator) StringWriter(java.io.StringWriter) ASTNode(org.matheclipse.parser.client.ast.ASTNode) IExpr(org.matheclipse.core.interfaces.IExpr) OutputFormFactory(org.matheclipse.core.form.output.OutputFormFactory) Parser(org.matheclipse.parser.client.Parser)

Aggregations

StringWriter (java.io.StringWriter)4 TimeConstrainedEvaluator (org.matheclipse.core.eval.TimeConstrainedEvaluator)4 OutputFormFactory (org.matheclipse.core.form.output.OutputFormFactory)4 IAST (org.matheclipse.core.interfaces.IAST)3 IExpr (org.matheclipse.core.interfaces.IExpr)1 Parser (org.matheclipse.parser.client.Parser)1 ASTNode (org.matheclipse.parser.client.ast.ASTNode)1