當前位置: 首頁>>代碼示例>>C#>>正文


C# SimpleCalculator.Parse類代碼示例

本文整理匯總了C#中SimpleCalculator.Parse的典型用法代碼示例。如果您正苦於以下問題:C# Parse類的具體用法?C# Parse怎麽用?C# Parse使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Parse類屬於SimpleCalculator命名空間,在下文中一共展示了Parse類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ParseCanGetOperand

 public void ParseCanGetOperand()
 {
     Parse parse = new Parse("3 + 4");
     char actual = parse.operand;
     char expected = '+';
     Assert.AreEqual(expected, actual);
 }
開發者ID:tombler,項目名稱:SimpleCalculator,代碼行數:7,代碼來源:ParseTests.cs

示例2: EvalCanRetrieveConstantAssignmentThroughLists

 public void EvalCanRetrieveConstantAssignmentThroughLists()
 {
     Parse input = new Parse("x = 3");
     Evaluate eval = new Evaluate(input);
     int expected = eval.ListOfConstantAssignmentsUsed[0];
     Assert.AreEqual(expected, 3);
 }
開發者ID:tombler,項目名稱:SimpleCalculator,代碼行數:7,代碼來源:EvaluateTests.cs

示例3: ParseEnsureICanGetTheOperatorType

 public void ParseEnsureICanGetTheOperatorType()
 {
     Parse value = new Parse();
     char actualChar = value.OperatorType("2/2");
     char expectedChar = '/';
     Assert.AreEqual(expectedChar, actualChar);
 }
開發者ID:ddbunc2,項目名稱:simpleCalculatorJuniper,代碼行數:7,代碼來源:ParseTests.cs

示例4: EvaluateCanExecuteBasicOperation

 public void EvaluateCanExecuteBasicOperation()
 {
     Parse parse = new Parse("1 + 5");
     Evaluate eval = new Evaluate(parse);
     eval.Execute();
     Assert.AreEqual("6", eval.Answer);
 }
開發者ID:BrendonPierson,項目名稱:simpleCalculatorJuniper,代碼行數:7,代碼來源:EvaluateTests.cs

示例5: EvalCanAddTwoNumbers

 public void EvalCanAddTwoNumbers()
 {
     Parse input = new Parse("3 + 4");
     Evaluate eval = new Evaluate(input);
     int expected = eval.result;
     Assert.AreEqual(expected, 7);
 }
開發者ID:tombler,項目名稱:SimpleCalculator,代碼行數:7,代碼來源:EvaluateTests.cs

示例6: Main

        static void Main(string[] args)
        {
            Console.WriteLine("What is your name?");
            string userName = Console.ReadLine();
            Parse p = new Parse();
            Evaluate e = new Evaluate();
            bool run = true;

            while (run)
            {
                Console.WriteLine(userName + " Define your mathematical operation");
                string input = Console.ReadLine();
                if (input.ToUpper() == "LASTQ")
                {
                    Console.WriteLine(e.lastExpression());
                    run = false;
                    break;
                }
                string oper = p.getOperator(input);
                int num1 = p.getNumberOne(input);
                int num2 = p.getNumberTwo(input);
                int answer = e.ExecuteMethod(num1, num2, oper);
                Console.WriteLine("The answer to your operation is: " + answer);
            }
            Console.WriteLine("Press any key to exit");
            Console.ReadLine();
        }
開發者ID:sethdorris,項目名稱:simpleCalculatorJuniper,代碼行數:27,代碼來源:Program.cs

示例7: CalculateMath

        public int CalculateMath(Parse parse)
        {
            int first_term = parse.terms[0];
            int second_term = parse.terms[1];
            math_expression = parse.mathOperator;

            if (math_expression == "+")
            {
                DoAddition(first_term, second_term);
            }
            else if (math_expression == "-")
            {
                DoSubtraction(first_term, second_term);
            }
            else if (math_expression == "/")
            {
                DoDivision(first_term, second_term);
            }
            else if (math_expression == "*")
            {
                DoMultiplication(first_term, second_term);
            }
            else if (math_expression == "%")
            {
                DoModulus(first_term, second_term);
            }
            else
            {
                throw new InvalidOperationException();
            }
            return last;
        }
開發者ID:rachyllmorgan,項目名稱:simpleCalculatorJuniper,代碼行數:32,代碼來源:Evaluate.cs

示例8: ParseCanPullOutTwoArgumentNumbers

 public void ParseCanPullOutTwoArgumentNumbers()
 {
     Parse parse = new Parse("1 + -2");
     parse.PullOutArguments();
     Assert.AreEqual(1, parse.FirstNumArg);
     Assert.AreEqual(-2, parse.SecondNumArg);
 }
開發者ID:BrendonPierson,項目名稱:simpleCalculatorJuniper,代碼行數:7,代碼來源:ParseTests.cs

示例9: ParseCanFindSecondNum

 public void ParseCanFindSecondNum()
 {
     Parse twoPlusThree = new Parse("2 + 3");
     twoPlusThree.setOperatorIndex();
     twoPlusThree.firstNum();
     Assert.AreEqual(3, twoPlusThree.secondNum());
 }
開發者ID:C-Stein,項目名稱:simpleCalculatorJuniper,代碼行數:7,代碼來源:ParseTests.cs

示例10: ParseCanFindCommands

 public void ParseCanFindCommands()
 {
     Parse parse = new Parse("last");
     parse.CheckForCommand();
     Assert.AreEqual("last", parse.Command);
     Assert.IsTrue(parse.IsCommand);
 }
開發者ID:BrendonPierson,項目名稱:simpleCalculatorJuniper,代碼行數:7,代碼來源:ParseTests.cs

示例11: ParseCanPullOutnumberAndConstant

 public void ParseCanPullOutnumberAndConstant()
 {
     Parse parse = new Parse("c + -2");
     parse.PullOutArguments();
     Assert.AreEqual("c", parse.FirstConstArg);
     Assert.AreEqual(-2, parse.SecondNumArg);
 }
開發者ID:BrendonPierson,項目名稱:simpleCalculatorJuniper,代碼行數:7,代碼來源:ParseTests.cs

示例12: Calculation

 public static int Calculation(string input)
 {
     Parse val = new Parse();
     string[] inputParsed = val.Equation(input);
     char operation = val.OperatorType(input);
     int[] inputToInt = val.ValuesToInt(inputParsed);
     if (operation == '+')
     {
         return Add(inputToInt);
     }
     else if (operation == '-')
     {
         return Subtract(inputToInt);
     }
     else if (operation == '*')
     {
         return Multi(inputToInt);
     }
     else if (operation == '/')
     {
         return Divide(inputToInt);
     }
     else if (operation == '%')
     {
         return Modulo(inputToInt);
     }
     else
     {
         throw new InvalidOperationException("Error: Calculations must only use +, -, *, /, or %");
     }
 }
開發者ID:ddbunc2,項目名稱:simpleCalculatorJuniper,代碼行數:31,代碼來源:Evaluate.cs

示例13: ParseCanParseWithNegativeLast

 public void ParseCanParseWithNegativeLast()
 {
     Parse parse = new Parse("3 + -4");
     char actual = parse.operand;
     char expected = '+';
     Assert.AreEqual(expected, actual);
 }
開發者ID:tombler,項目名稱:SimpleCalculator,代碼行數:7,代碼來源:ParseTests.cs

示例14: ParseCanGetOperandWithNegativeFirst

 public void ParseCanGetOperandWithNegativeFirst()
 {
     Parse parse = new Parse("-3 + 4");
     char actual = parse.operand;
     char expected = '+';
     Assert.AreEqual(expected, actual);
 }
開發者ID:tombler,項目名稱:SimpleCalculator,代碼行數:7,代碼來源:ParseTests.cs

示例15: Main

        static void Main(string[] args)
        {
            int count = 0;
            Constant currentConstant = new Constant();
            Evaluate expression;

            while (true)
            {
                Console.Write("[{0}]> ", count);
                string input = Console.ReadLine();
                expression = new Evaluate(input, currentConstant);
                if (input.ToLower() == "exit" || input.ToLower() == "quit")
                {
                    break;
                }
                else if (input.IndexOf("=")> -1)
                {
                    //set variable

                    Parse addConstant = new Parse(input, currentConstant);
                    addConstant.setOperatorIndex();
                    currentConstant.addConst(addConstant.StringFirst(), addConstant.secondNum());
                    // = saved 'x' as '3'
                    Console.WriteLine("= saved '" + addConstant.StringFirst() + "' as '" + addConstant.secondNum() + "'");

                }
                else
                {
                    int answer = expression.doMath();
                    Console.WriteLine("   = {0}", answer);
                    count++;

                }
            }
        }
開發者ID:C-Stein,項目名稱:simpleCalculatorJuniper,代碼行數:35,代碼來源:Program.cs


注:本文中的SimpleCalculator.Parse類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。