public void InfixTestShouldGive14() { var RPC = new ReversePolishCalculator(); RPC.InitOperations(); Assert.AreEqual(14d, RPC.InfixCalculation("( 5 + ( ( 1 + 2 ) * 4 ) ) - 3")); }
public void Calculate_SingleAdd() { var target = new ReversePolishCalculator(); var result = target.Calculate("5 6 +"); result.Should().Be(11); }
public void Calculate_SingleSubtract() { var target = new ReversePolishCalculator(); var result = target.Calculate("5 6 -"); result.Should().Be(-1); }
public void Calculate_NestedAdd() { var target = new ReversePolishCalculator(); var result = target.Calculate("1 2 + 3 4 + +"); result.Should().Be(10); }
public void Calculate_SingleValue() { var target = new ReversePolishCalculator(); var result = target.Calculate("5"); result.Should().Be(5); }
public void Calculate_SingleMultiply() { var target = new ReversePolishCalculator(); var result = target.Calculate("5 6 *"); result.Should().Be(30); }
public void InfixTestPowBeforeX() { var RPC = new ReversePolishCalculator(); Assert.AreEqual(1d, RPC.InfixCalculation("1 ^ 2 * 3")); Assert.AreEqual(8d, RPC.InfixCalculation("1 * 2 ^ 3")); }
public void InfixTestNothingAndNull() { var RPC = new ReversePolishCalculator(); Assert.AreEqual(0d, RPC.InfixCalculation("")); Assert.AreEqual(0d, RPC.InfixCalculation(null)); }
public void Calculate_SingleDivide() { var target = new ReversePolishCalculator(); var result = target.Calculate("20 5 /"); result.Should().Be(4); }
public void InfixTestComplexExpressions() { var RPC = new ReversePolishCalculator(); Assert.AreEqual(2d, RPC.InfixCalculation("( 2 + 2 ) - 2")); Assert.AreEqual(9d, RPC.InfixCalculation("( ( 3 - 2 ) + 2 ) * 3")); Assert.AreEqual(6d, RPC.InfixCalculation("( ( 3 * 3 ) + ( 5 - 2 ) ) / 2")); }
public void InfixTestXBeforePlus() { var RPC = new ReversePolishCalculator(); Assert.AreEqual(7d, RPC.InfixCalculation("1 + 2 * 3")); Assert.AreEqual(5d, RPC.InfixCalculation("1 * 2 + 3")); Assert.AreEqual(33d, RPC.InfixCalculation("5 + ( 1 + 2 * 3 ) * 4")); }
public void Calculate_Mixed() { // (1 + 2) * (15 / 5) = 9 var target = new ReversePolishCalculator(); var result = target.Calculate("1 2 + 15 5 / *"); result.Should().Be(9); }
public void InfixTestAllOperaters() { var RPC = new ReversePolishCalculator(); Assert.AreEqual(4d, RPC.InfixCalculation("2 + 2")); Assert.AreEqual(1d, RPC.InfixCalculation("3 - 2")); Assert.AreEqual(9d, RPC.InfixCalculation("3 * 3")); Assert.AreEqual(1d, RPC.InfixCalculation("3 / 3")); Assert.AreEqual(81d, RPC.InfixCalculation("3 ^ 4")); }
public void TestNothingAndNull() { var RPC = new ReversePolishCalculator(); RPC.InitOperations(); Assert.AreEqual(0d, RPC.Calculation("")); Assert.AreEqual(0d, RPC.Calculation(null)); }
public void TestComplexExpressions() { var RPC = new ReversePolishCalculator(); RPC.InitOperations(); Assert.AreEqual(2d, RPC.Calculation("2 2 + 2 -")); Assert.AreEqual(9d, RPC.Calculation("3 2 - 2 + 3 *")); Assert.AreEqual(6d, RPC.Calculation("3 3 * 5 2 - + 2 /")); }
public void Compute_Pow2To8_Return256() { ReversePolishCalculator.Compute("2 8 pow").Should().Be(256); }
public void Compute_InvalidExpression2_ThrowsException() { Action act = () => ReversePolishCalculator.Compute("+ 1"); act.Should().Throw <ArgumentException>(); }
public void Compute_WithEmptyString_ReturnZero() { ReversePolishCalculator.Compute("").Should().Be(0); }
public void Compute_Sqrt16_Return4() { ReversePolishCalculator.Compute("16 sqrt").Should().Be(4); }
public void Compute_WithDivisionOfTwoNumbers_ReturnTheQuotient() { ReversePolishCalculator.Compute("10 5 /").Should().Be(2); }
public void TestAllOperaters() { var RPC = new ReversePolishCalculator(); Assert.AreEqual(4d, RPC.reversePolishNotation("2 2 +")); Assert.AreEqual(1d, RPC.reversePolishNotation("3 2 -")); Assert.AreEqual(9d, RPC.reversePolishNotation("3 3 *")); Assert.AreEqual(1d, RPC.reversePolishNotation("3 3 /")); Assert.AreEqual(81d, RPC.reversePolishNotation("3 4 ^")); }
public void Compute_WithSubstractionOfTwoNumbers_ReturnTheDifference() { ReversePolishCalculator.Compute("7 5 -").Should().Be(2); }
public void Compute_WithMultiplicationOfTwoNumbers_ReturnTheProduct() { ReversePolishCalculator.Compute("7 5 *").Should().Be(35); }
public void TestShouldGive14() { var RPC = new ReversePolishCalculator(); RPC.InitOperations(); Assert.AreEqual(14d, RPC.Calculation("5 1 2 + 4 * + 3 -")); }
public void SetUp() { rpCalculator = new ReversePolishCalculator(); }
public void Compute_WithNullString_ReturnZero() { ReversePolishCalculator.Compute(null).Should().Be(0); }
public void TestAllOperaters() { var RPC = new ReversePolishCalculator(); RPC.InitOperations(); Assert.AreEqual(4d, RPC.Calculation("2 2 +")); Assert.AreEqual(1d, RPC.Calculation("3 2 -")); Assert.AreEqual(9d, RPC.Calculation("3 3 *")); Assert.AreEqual(1d, RPC.Calculation("3 3 /")); Assert.AreEqual(81d, RPC.Calculation("3 4 ^")); Assert.AreEqual(2d, RPC.Calculation("2 4 - abs")); Assert.AreEqual(3d, RPC.Calculation("9 sqrt")); }
public void Compute_WithNumberRaisedToExponent_ReturnThePower() { ReversePolishCalculator.Compute("10 5 ^").Should().Be(100000); }
// Helper methods // to make the tests more readable private int Calculate(string expression) { return(ReversePolishCalculator.Compute(ShuntingYard.Parse(expression))); }
public void Compute_512Plus4TimesPlus3Minus_Return14() { ReversePolishCalculator.Compute("5 1 2 + 4 * + 3 -").Should().Be(14); }
public void Compute_WithSingleNumber_ReturnTheNumber() { ReversePolishCalculator.Compute("7").Should().Be(7); }
public void Setup() { reversePolishCalculator = new ReversePolishCalculator(); }
public void Setup() { _calculator = new ReversePolishCalculator(); }
public void Compute_WithAdditionOfTwoNumbers_ReturnTheSum() { ReversePolishCalculator.Compute("7 5 +").Should().Be(12); }