Ejemplo n.º 1
0
 //valid:
 /// <summary>
 /// test method of the type described in the lectures, i did not actually use this though.
 /// </summary>
 /// <param name="expression">input string to be evaluated</param>
 /// <param name="L">the lookup delegate</param>
 /// <param name="expected">expected answer, if after being evaluated the input string and lookup do not equal this then throw an exception</param>
 /// <returns></returns>
 public static bool ValidTest(string expression, FormulaEvaluatorPS1.Evaluator.Lookup L, int expected)//i don't think that Lookup<string, string> is of the correct form, Lookup alone gives an error,
 {
     try
     {
         return(FormulaEvaluatorPS1.Evaluator.Evaluate(expression, L) == expected);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Ejemplo n.º 2
0
        //and then will want to run this test like:
        //ValidTest("1+7", "A4/5",...,"(3-4)/0"); and so on

        //invalid tests:
        /// <summary>
        /// invalidity test, also not acutally used, designed to make sure that invalid input does return false and is not permitted to pass
        /// </summary>
        /// <param name="exp">inputed expression</param>
        /// <param name="L">lookup</param>
        /// <returns></returns>
        public static bool InvalidTest(string exp, FormulaEvaluatorPS1.Evaluator.Lookup L)
        {
            try
            {
                FormulaEvaluatorPS1.Evaluator.Evaluate(exp, L);
                return(false);
            }
            catch (ArgumentException)
            {
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }