当前位置: 首页>>代码示例>>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;未经允许,请勿转载。