本文整理汇总了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);
}
示例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);
}
示例3: ParseEnsureICanGetTheOperatorType
public void ParseEnsureICanGetTheOperatorType()
{
Parse value = new Parse();
char actualChar = value.OperatorType("2/2");
char expectedChar = '/';
Assert.AreEqual(expectedChar, actualChar);
}
示例4: EvaluateCanExecuteBasicOperation
public void EvaluateCanExecuteBasicOperation()
{
Parse parse = new Parse("1 + 5");
Evaluate eval = new Evaluate(parse);
eval.Execute();
Assert.AreEqual("6", eval.Answer);
}
示例5: EvalCanAddTwoNumbers
public void EvalCanAddTwoNumbers()
{
Parse input = new Parse("3 + 4");
Evaluate eval = new Evaluate(input);
int expected = eval.result;
Assert.AreEqual(expected, 7);
}
示例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();
}
示例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;
}
示例8: ParseCanPullOutTwoArgumentNumbers
public void ParseCanPullOutTwoArgumentNumbers()
{
Parse parse = new Parse("1 + -2");
parse.PullOutArguments();
Assert.AreEqual(1, parse.FirstNumArg);
Assert.AreEqual(-2, parse.SecondNumArg);
}
示例9: ParseCanFindSecondNum
public void ParseCanFindSecondNum()
{
Parse twoPlusThree = new Parse("2 + 3");
twoPlusThree.setOperatorIndex();
twoPlusThree.firstNum();
Assert.AreEqual(3, twoPlusThree.secondNum());
}
示例10: ParseCanFindCommands
public void ParseCanFindCommands()
{
Parse parse = new Parse("last");
parse.CheckForCommand();
Assert.AreEqual("last", parse.Command);
Assert.IsTrue(parse.IsCommand);
}
示例11: ParseCanPullOutnumberAndConstant
public void ParseCanPullOutnumberAndConstant()
{
Parse parse = new Parse("c + -2");
parse.PullOutArguments();
Assert.AreEqual("c", parse.FirstConstArg);
Assert.AreEqual(-2, parse.SecondNumArg);
}
示例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 %");
}
}
示例13: ParseCanParseWithNegativeLast
public void ParseCanParseWithNegativeLast()
{
Parse parse = new Parse("3 + -4");
char actual = parse.operand;
char expected = '+';
Assert.AreEqual(expected, actual);
}
示例14: ParseCanGetOperandWithNegativeFirst
public void ParseCanGetOperandWithNegativeFirst()
{
Parse parse = new Parse("-3 + 4");
char actual = parse.operand;
char expected = '+';
Assert.AreEqual(expected, actual);
}
示例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++;
}
}
}