本文整理匯總了C#中SimpleCalculator.Parse.Equation方法的典型用法代碼示例。如果您正苦於以下問題:C# Parse.Equation方法的具體用法?C# Parse.Equation怎麽用?C# Parse.Equation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類SimpleCalculator.Parse
的用法示例。
在下文中一共展示了Parse.Equation方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: 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 %");
}
}
示例2: ParseEnsureInputStringSplitAtOperator
public void ParseEnsureInputStringSplitAtOperator()
{
Parse value = new Parse();
string[] actualString = value.Equation("2+3");
string[] expectedString = new string[] { "2", "3" };
Assert.AreEqual(expectedString[0], actualString[0]);
Assert.AreEqual(expectedString[1], actualString[1]);
}
示例3: ParseEnsureInputReturnAsInt
public void ParseEnsureInputReturnAsInt()
{
Parse value = new Parse();
string[] actualString = value.Equation("2 + 3");
int[] intArray = value.ValuesToInt(actualString);
int expected2 = 2;
int expected3 = 3;
Assert.AreEqual(expected2, intArray[0]);
Assert.AreEqual(expected3, intArray[1]);
}
示例4: ParseEnsureIThrowExceptionIfOperationIsOutOfOrderOrDoesntMakeSense
public void ParseEnsureIThrowExceptionIfOperationIsOutOfOrderOrDoesntMakeSense()
{
Parse value = new Parse();
value.Equation("+22");
}
示例5: ParseEnsureIThrowExceptionIfEquasionDoesntContainOperator
public void ParseEnsureIThrowExceptionIfEquasionDoesntContainOperator()
{
Parse value = new Parse();
value.Equation("22");
}