Exemplo n.º 1
0
        public override UnitTestReport Test()
        {
            var report = new UnitTestReport();

            foreach (var exp in Samples)
            {
                var calc = new AscCalc(exp);
                try
                {
                    calc.Compute();
                }
                catch (Exception e)
                {
                    report.Add(exp, e.Message);
                }
            }
            return(report);
        }
Exemplo n.º 2
0
        public void Process(string expr)
        {
            Exception exc      = null;
            var       calcTask = new Thread(() =>
            {
                try
                {
                    if (!Security.ExprSecure(Expression))
                    {
                        throw new SecurityException();
                    }
                    AscCalc calc = new AscCalc(Expression, latex: true);
                    CalcResult cr;
                    cr = calc.Compute();
                    PlainCalcResponse = cr.Result;
                    CalcResponse      = cr.LatexResult;
                    InterpretedAs     = string.Join("<br>", cr.InterpretedAs);
                }
                catch (Exception e)
                {
                    exc = e;
                }
            });

            calcTask.Start();

            if (!calcTask.Join(millisecondsTimeout: Const.LIMIT_CALC_EXECUTE_MS))
            {
                throw new TimeOutException();
            }
            if (exc != null)
            {
                throw exc;
            }
            // TO DO
            // @"\[x = {-b \pm \sqrt{b^2-4ac} \over 2a}.\] change this in Procees(Expression) method for latex expression";
        }
Exemplo n.º 3
0
        // returns true if line was caught by function
        private bool ProcessMSLOutput(Process process, string line)
        {
            if (line.StartsWith(Const.PREFIX_MSL_CALC_EXECUTE))
            {
                line = line.Remove(0, Const.PREFIX_MSL_CALC_EXECUTE.Length);
                try
                {
                    if (!Security.ExprSecure(line))
                    {
                        throw new SecurityException();
                    }

                    string result = new AscCalc(line).Compute().SolidResult.Split('\n')[0];
                    process.StandardInput.WriteLine(result);
                    return(true);
                }
                catch (Exception e)
                {
                    process.StandardInput.WriteLine(Const.ERMSG_PREOUTPUT + e.Message);
                    return(true);
                }
            }
            return(false);
        }