コード例 #1
0
ファイル: Program.cs プロジェクト: HairyQ/SpreadsheetClient
        /// <summary>
        /// Main basically just calls InvalidExpression() and ValidExpression() over and over, printing the result to the console so that I can determine which tests worked, and which ones didn't
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            Evaluator.Lookup fourDel = AlwaysFourDelegate;
            Console.WriteLine(ValidExpression("(2-3)", fourDel, -1));
            Console.WriteLine(ValidExpression("(3-2)", fourDel, 1));
            Console.WriteLine(ValidExpression("1 + 1", fourDel, 2));
            Console.WriteLine(ValidExpression("9               /        3", fourDel, 3));
            Console.WriteLine(ValidExpression("1000 /5", fourDel, 200));
            Console.WriteLine(ValidExpression("(94-22)/8", fourDel, 9));
            Console.WriteLine(ValidExpression("A2/2", fourDel, 2));
            Console.WriteLine(ValidExpression("(((A2/2)*45)/9)*10", fourDel, 100));
            Console.WriteLine(ValidExpression("5 + 6(/ (1 + 1))", fourDel, 8));
            Console.WriteLine(ValidExpression("() 17 + 3", fourDel, 20));
            Console.WriteLine(ValidExpression("17 + 3 ()", fourDel, 20));
            Console.WriteLine(ValidExpression("AhuASHBbvCA938274329834732894327483297438927483922222222222222 + 3", fourDel, 7));
            Console.WriteLine(ValidExpression("(((((14 / 2 )))))", fourDel, 7));
            Console.WriteLine(ValidExpression("2 / 3", fourDel, 0));
            Console.WriteLine(ValidExpression("18 / 14", fourDel, 1));
            Console.WriteLine(ValidExpression("(14 * 3) * (12/3)", fourDel, 168));
            Console.WriteLine(ValidExpression("2 + (12/4) - 67 + (14 * 3)", fourDel, -20));
            Console.WriteLine(ValidExpression("2 + (12/4) - 67 + (14 * 3) * (( 14 + (567 * 2)) - 10000)", fourDel, -371846));

            Console.WriteLine(InvalidExpression("*8", fourDel));
            Console.WriteLine(InvalidExpression("432 / 0", fourDel));
            Console.WriteLine(InvalidExpression("56 4 *3", fourDel));
            Console.WriteLine(InvalidExpression("5 * + 9", fourDel));
            Console.WriteLine(InvalidExpression("(3 + 5", fourDel));
            Console.WriteLine(InvalidExpression("b45z / 76", fourDel));
            Console.WriteLine(InvalidExpression("#", fourDel));
            Console.WriteLine(InvalidExpression("(3 + 5", fourDel));
            Console.WriteLine(InvalidExpression("3 + 56666666666", fourDel));
            Console.WriteLine(InvalidExpression("(3982 + 483))", fourDel));
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: jimibue/cs3505
 public static void testFail(string str, Evaluator.Lookup lookUpDel)
 {
     try
     {
         Console.Write(Evaluator.Evaluate(str, lookUpDel) + " ");
         Console.WriteLine("failed  " + str + "should throw argumentexception");
     }
     catch (ArgumentException e) { }
 }
コード例 #3
0
 /// <summary>
 /// A testing method that assumes the evaluation of the expression to
 /// happen successfully with an expected output.
 /// </summary>
 /// <param name="expr">The expression to evaluate</param>
 /// <param name="L">The lookup delegate</param>
 /// <param name="expected">The expected result after evaluation</param>
 /// <returns>True if the expression successfully evaluates to the expected value,
 /// false otherwise</returns>
 public static bool ValidTest(string expr, Evaluator.Lookup L, int expected)
 {
     try {
         return(Evaluator.Evaluate(expr, L) == expected);
     }
     catch (Exception) {
         return(false);
     }
 }
コード例 #4
0
 private static void TestEvaluate()
 {
     Console.WriteLine("\nTesting Evaluate Method");
     Evaluator.Lookup findVar = new Evaluator.Lookup(search);
     Console.WriteLine("5 + 10 + 50 * (10/5) + 5 = " + Evaluator.Evaluate("5 + 10 + 50 * (10/5) + 5", findVar));
     Console.WriteLine("10 / 5 + 20 * (50 * 10 + 5) + 5 = " + Evaluator.Evaluate("10 / 5 + 20 * (50 * 10 + 5) + 5", findVar));
     Console.WriteLine("50 / A10 = " + Evaluator.Evaluate("50 / A10", findVar));
     Console.WriteLine("50 + 10 - 5 * 10 = " + Evaluator.Evaluate("50 + 10 - 5 * 10", findVar));
     Console.WriteLine("10 * 50 + 5 - 7 * (10 - 10 + (5 + 5)) * 10 = " + Evaluator.Evaluate("10 * 50 + 5 - 7 * (10 - 10 + (5 + 5)) * 10", findVar));
 }
コード例 #5
0
ファイル: Program.cs プロジェクト: jimibue/cs3505
        public static void test(string str, int testNumber, Evaluator.Lookup lookUpDel)
        {
            int testNumber1 = Evaluator.Evaluate(str, lookUpDel);

            if (testNumber != testNumber1)
            {
                Console.WriteLine("fail on expression " + str + " : expected " + testNumber + " got " + testNumber1);
                Console.ReadLine();
            }
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: HairyQ/SpreadsheetClient
 /// <summary>
 /// Testing function for comparing the result of an evaluated string with its expected result
 /// </summary>
 /// <param name="expr">Expression the user inputs for evaluation by FormulaEvaluator</param>
 /// <param name="lookup">Delegate variable lookup object to be passed to FormulaEvaluator.Evaluate</param>
 /// <param name="expected">Expected int result, signifying the code works</param>
 /// <returns>True if the expected result is equal to the Evaluated expression's result, false otherwise</returns>
 private static bool ValidExpression(string expr, Evaluator.Lookup lookup, int expected)
 {
     try
     {
         return(Evaluator.Evaluate(expr, lookup) == expected);
     }
     catch (Exception)
     {
         return(false);
     }
 }
コード例 #7
0
 /// <summary>
 /// A testing method that assumes the evaluation of the expression to
 /// throw an ArgumentException.
 /// </summary>
 /// <param name="exp">The expression to evaluate</param>
 /// <param name="L">The lookup delegate</param>
 /// <returns>True if an ArgumentException is thrown, false otherwise</returns>
 public static bool InvalidTest(string exp, Evaluator.Lookup L)
 {
     try {
         Evaluator.Evaluate(exp, L);
         return(false);
     }
     catch (ArgumentException) {
         return(true);
     }
     catch (Exception) {
         return(false);
     }
 }
コード例 #8
0
ファイル: Program.cs プロジェクト: HairyQ/SpreadsheetClient
 /// <summary>
 /// Testing function that expects user inputs to return Argument Exceptions - cases where the program should throw an exception
 /// </summary>
 /// <param name="expr">Expression the user inpouts for evaluation by FormulaEvaluator</param>
 /// <param name="lookup">Delegate variable lookup object to be passed to FormulaEvaluator.Evaluate</param>
 /// <returns>true if the program throws the correct exception, false otherwise</returns>
 private static bool InvalidExpression(string expr, Evaluator.Lookup lookup)
 {
     try
     {
         Evaluator.Evaluate(expr, lookup);
         return(false);
     }
     catch (ArgumentException)
     {
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
コード例 #9
0
ファイル: Program.cs プロジェクト: jrhendley/3500-code
        static void Main(string[] args)
        {
            variables = new Dictionary <string, int>();
            variables.Add("X6", 6);
            variables.Add("D5", 5);
            variables.Add("SDFEWER95475", 1);
            variables.Add("T0", 9);
            variables.Add("VV78", 2);

            Evaluator.Lookup lookup = variableEvaluator;
            //Console.WriteLine(Evaluator.Evaluate("2 * 3 * )", variableEvaluator));
            Console.WriteLine(Evaluator.Evaluate("( 2 - SDFEWER95475 - T0 + ( 3 - X6 ) * 2)", variableEvaluator));
            Console.WriteLine((2 - 1 - 9 + (3 - 6) * 2));
            Console.WriteLine(Evaluator.Evaluate("( 20 * VV78 + T0 / 3 + X6 ) / 2", variableEvaluator));
            Console.WriteLine((20 * 2 + 9 / 3 + 6) / 2);

            Console.Read();
        }
コード例 #10
0
 /// <summary>
 /// Valid tests for valid expression
 /// </summary>
 /// <param name="expr"></param>
 /// <param name="L"></param>
 /// <param name="expected"></param>
 /// <returns></returns>
 public static bool ValidTest(string expr, Evaluator.Lookup L, int expected)
 {
     try
     {
         int a = Evaluator.Evaluate(expr, L);
         if (Evaluator.Evaluate(expr, L) == expected)
         {
             return(true);
         }
         else
         {
             Console.WriteLine(a);
             return(false);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }