本文整理汇总了C#中Calculator.Calculate方法的典型用法代码示例。如果您正苦于以下问题:C# Calculator.Calculate方法的具体用法?C# Calculator.Calculate怎么用?C# Calculator.Calculate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Calculator
的用法示例。
在下文中一共展示了Calculator.Calculate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestIncorrectExpressionsWithOperators
public void TestIncorrectExpressionsWithOperators(String input, double expectedResult)
{
Calculator calculator = new Calculator();
double result = calculator.Calculate(input);
Assert.Throws<InvalidOperationException>(() => calculator.Calculate(input));
}
示例2: Happy_day_Nth_op_builds_on_previous
public void Happy_day_Nth_op_builds_on_previous()
{
var sut = new Calculator();
sut.Calculate(2, "+");
var result = sut.Calculate(3, "+");
Assert.AreEqual(5, result);
}
示例3: Division_by_zero_does_not_affect_calculator_state
public void Division_by_zero_does_not_affect_calculator_state()
{
var sut = new Calculator();
sut.Calculate(8, "/");
Assert.Throws<DivideByZeroException>(() => sut.Calculate(0, "="));
Assert.AreEqual(4, sut.Calculate(2, "="));
}
示例4: Main
static void Main()
{
Calculator calc = new Calculator(new ExpressionTransformer(), new OnpAlgorithm());
Console.WriteLine(calc.Calculate("((2+7)/3+(14-3)*4)/2"));
Console.WriteLine(calc.Calculate("((2+7)/3+(14-3)*4)"));
Console.ReadLine();
}
示例5: NotEnoughDiamonds
public void NotEnoughDiamonds()
{
Calculator calculator = new Calculator();
Assert.AreEqual(0, calculator.Calculate(0, 0, 0));
Assert.AreEqual(0, calculator.Calculate(5, 0, 2));
Assert.AreEqual(0, calculator.Calculate(14, 0, 4));
}
示例6: OddCoordinates
public void OddCoordinates()
{
Calculator calculator = new Calculator();
Assert.AreEqual(0, calculator.Calculate(1, 1, 0));
Assert.AreEqual(0, calculator.Calculate(1, 2, 1));
Assert.AreEqual(0, calculator.Calculate(1, 2, 3));
}
示例7: Check_ops
public int Check_ops(string op)
{
var sut = new Calculator();
sut.Calculate(12, op);
return sut.Calculate(3, "=");
}
示例8: EnoughDiamonds
public void EnoughDiamonds()
{
Calculator calculator = new Calculator();
Assert.AreEqual(1, calculator.Calculate(1, 0, 0));
Assert.AreEqual(1, calculator.Calculate(6, -2, 0));
Assert.AreEqual(1, calculator.Calculate(6, 0, 2));
Assert.AreEqual(1, calculator.Calculate(6, 2, 0));
}
示例9: InsufficientDiamonds
public void InsufficientDiamonds()
{
Calculator calculator = new Calculator();
Assert.AreEqual(0, calculator.Calculate(0, 0, 0));
Assert.AreEqual(0, calculator.Calculate(1, -2, 0));
Assert.AreEqual(0, calculator.Calculate(1, 0, 2));
Assert.AreEqual(0, calculator.Calculate(1, 2, 0));
}
示例10: Equal_resets_previous_data
public void Equal_resets_previous_data()
{
var sut = new Calculator();
sut.Calculate(2, "+");
sut.Calculate(3, "=");
Assert.AreEqual(4, sut.Calculate(4, "*"));
Assert.AreEqual(8, sut.Calculate(2, "="));
}
示例11: TestIncorrectCalculations
public void TestIncorrectCalculations(String input, double expectedResult)
{
Calculator calculator = new Calculator();
double result = calculator.Calculate(input);
Assert.AreNotEqual(result, expectedResult, "Calculation is not correct for {0}", input);
}
示例12: TestCorrectExpressionsWithSpaces
public void TestCorrectExpressionsWithSpaces(String input, double expectedResult)
{
Calculator calculator = new Calculator();
double result = calculator.Calculate(input);
Assert.AreEqual(result, expectedResult, "Calculation is not correct for {0}", input);
}
示例13: Calculator_Should_Calculate_Test1
public void Calculator_Should_Calculate_Test1()
{
var calculator = new Calculator();
var result = calculator.Calculate("(5+3)*4");
result.Should().Be(32);
}
示例14: Calculator_Should_Calculate_Test2
public void Calculator_Should_Calculate_Test2()
{
var calculator = new Calculator();
var result = calculator.Calculate("(5+3)*(4-1)");
result.Should().Be(24);
}
示例15: Calculator_Should_Calculate_Test4
public void Calculator_Should_Calculate_Test4()
{
var calculator = new Calculator();
var result = calculator.Calculate("5+5*2-1");
result.Should().Be(14);
}