本文整理汇总了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");
}