public void SumPositiveAndNegativeInteger() { var rpn = parser.Parse("1+(-6)"); var result = RPNCalculator.Calculate(rpn); Assert.AreEqual(0, result.CompareTo(-5)); }
public void SubtractionDouble() { var rpn = parser.Parse("5.1-8.2"); var result = RPNCalculator.Calculate(rpn); Assert.AreEqual(0, result.CompareTo(3.1)); }
public void FactorialInteger() { var rpn = parser.Parse("6!"); var result = RPNCalculator.Calculate(rpn); Assert.AreEqual(0, result.CompareTo(720)); }
public void SubtractionInteger() { var rpn = parser.Parse("6-4"); var result = RPNCalculator.Calculate(rpn); Assert.AreEqual(0, result.CompareTo(2)); }
public void CompoundExpression2Double() { var rpn = parser.Parse("9/6/2/10"); var result = RPNCalculator.Calculate(rpn); Assert.AreEqual(0, result.CompareTo(0.075)); }
public void CompoundDegreeDouble() { var rpn = parser.Parse("2.5^1.8^1.1"); var result = RPNCalculator.Calculate(rpn); Assert.AreEqual(0, result.CompareTo(5.7498521724779302)); }
public void CompoundExpressionDouble() { var rpn = parser.Parse("-2.8+7.1-5.9+(7.4+8)*(9.2^7*(5.1-3+Foo(-10))-4.123)+45.2378+(-2.321)+((4.908)^(1)*(6)-(2)+(9))"); var result = RPNCalculator.Calculate(rpn); Assert.AreEqual(0, result.CompareTo(-215233591)); }
public void ParenthesisDouble() { var rpn = parser.Parse("(6.0+4.3)*5.2"); var result = RPNCalculator.Calculate(rpn); Assert.AreEqual(0, result.CompareTo(53.56)); }
public void MultiplySumInteger() { var rpn = parser.Parse("6+4*5"); var result = RPNCalculator.Calculate(rpn); Assert.AreEqual(0, result.CompareTo(26)); }
public void OneNegativeDouble() { var rpn = parser.Parse("-6.1"); var result = RPNCalculator.Calculate(rpn); Assert.AreEqual(0, result.CompareTo(-6.1)); }
public void SumDouble() { var rpn = parser.Parse("6.356+4.9"); var result = RPNCalculator.Calculate(rpn); Assert.AreEqual(0, result.CompareTo(11.256)); }
public void CompoundExpression4Integer() { var rpn = parser.Parse("-2+7-5+(7+8)*(9^7*(5-3+Foo(-10))-4)"); var result = RPNCalculator.Calculate(rpn); Assert.AreEqual(0, result.CompareTo(-215233665)); }
public void OneInteger() { var rpn = parser.Parse("6"); var result = RPNCalculator.Calculate(rpn); Assert.AreEqual(0, result.CompareTo(6)); }
public void CompoundExpressionInteger() { var rpn = parser.Parse("-2+7-5+(7+8)*(9^7*(5-3+Foo(-10))-4)+45+(-2)+((4)^(1)*(6)-(2)+(9))"); var result = RPNCalculator.Calculate(rpn); Assert.AreEqual(0, result.CompareTo(-215233591)); }
public void CompoundExpression3Integer() { var rpn = parser.Parse("((4)^(1)*(6)-(2)+(9))"); var result = RPNCalculator.Calculate(rpn); Assert.AreEqual(0, result.CompareTo(31)); }
public void CompoundDegreeInteger() { var rpn = parser.Parse("2^3^4"); var result = RPNCalculator.Calculate(rpn); Assert.AreEqual(0, result.CompareTo(2417851639229258349412352.0)); }
public void UserFunctionInteger() { var rpn = parser.Parse("6+Foo(5)"); var result = RPNCalculator.Calculate(rpn); Assert.AreEqual(0, result.CompareTo(16)); }
public void ParenthesisInteger() { var rpn = parser.Parse("(6+4)*5"); var result = RPNCalculator.Calculate(rpn); Assert.AreEqual(0, result.CompareTo(50)); }
public void CompoundExpression3Double() { var rpn = parser.Parse("9/(6*5+4)/2/10"); var result = RPNCalculator.Calculate(rpn); Assert.AreEqual(0, result.CompareTo(0.0132352941176471)); }
public void MultiplySumDouble() { var rpn = parser.Parse("6.0+4.3*5.2"); var result = RPNCalculator.Calculate(rpn); Assert.AreEqual(0, result.CompareTo(28.36)); }
public void OneDouble() { var rpn = parser.Parse("6.4"); var result = RPNCalculator.Calculate(rpn); Assert.AreEqual(0, result.CompareTo(6.4)); }
public void SumPositiveAndNegativeDouble() { var rpn = parser.Parse("1.3+(-6.4)"); var result = RPNCalculator.Calculate(rpn); Assert.AreEqual(0, result.CompareTo(-5.1)); }
public void MultiplicationCalculationGivesRightResults() { var values = new string[] { "2", "3", "*" }; var rpnCalculator = new RPNCalculator(values); var result = rpnCalculator.Calculate(); Assert.AreEqual(result, 6); }
public void PercentageCalculationGivesRightResults() { var values = new string[] { "2", "%" }; var rpnCalculator = new RPNCalculator(values); var result = rpnCalculator.Calculate(); Assert.AreEqual(result, decimal.Parse(0.02.ToString())); }
public void FactorialCalculationGivesRightResults() { var values = new string[] { "4", "!" }; var rpnCalculator = new RPNCalculator(values); var result = rpnCalculator.Calculate(); Assert.AreEqual(result, 24); }
public void DivisionCalculationGivesRightResults() { var values = new string[] { "2", "3", "/" }; var rpnCalculator = new RPNCalculator(values); var result = rpnCalculator.Calculate(); Assert.AreEqual(result, decimal.Parse(1.5.ToString())); }
public void DecimalCalculationGivesRightResults() { var values = new string[] { "2.5", "3.5", "+" }; var rpnCalculator = new RPNCalculator(values); var result = rpnCalculator.Calculate(); Assert.AreEqual(result, 6); }
public void CalculateTest() { Assert.AreEqual(RPNCalculator.Calculate("2 3 +"), 5); Assert.AreEqual(RPNCalculator.Calculate("5 4 *"), 20); Assert.AreEqual(RPNCalculator.Calculate("4 2 /"), 2); Assert.AreEqual(RPNCalculator.Calculate("11 3 -"), 8); Assert.AreEqual(RPNCalculator.Calculate("6 2 ^"), 36); Assert.AreEqual(RPNCalculator.Calculate("3 1 7 + *"), 24); Assert.AreEqual(RPNCalculator.Calculate("5 3 8 12 + * -"), -55); Assert.AreEqual(RPNCalculator.Calculate("4 2 + 9 *"), 54); Assert.AreEqual(RPNCalculator.Calculate("3 1 - 7 *"), 14); }
public void Calculate_TwoOperationsInsideWithSamePriorityBrackets_SholdReturnSuccess() { //arrange var calculator = new RPNCalculator(); string input = "4*(5+2-1)"; var rightAnswer = 24; //act var answer = calculator.Calculate(input); //assert double eps = 0.000001; Assert.True(Math.Abs(rightAnswer - answer) < eps); }
public void Calculate_TwoOperationsWithLargerPriorityInSecondOperation_SholdReturnSuccess() { //arrange var calculator = new RPNCalculator(); string input = "4+5*2"; double rightAnswer = 14; //act var answer = calculator.Calculate(input); //assert double eps = 0.000001; Assert.True(Math.Abs(rightAnswer - answer) < eps); }