public void EvaluatorTest() { PostfixEvaluator.Evaluate(2, 3, '+').Should().Be(5); PostfixEvaluator.Evaluate(2, 3, '^').Should().Be(8); PostfixEvaluator.Evaluate(10, -3, '*').Should().Be(-30); PostfixEvaluator.Evaluate(10, 5, '/').Should().Be(2); }
public void Deve_avaliar_operador_soma_com_dois_operandos() { var eval = new PostfixEvaluator(); var result = eval.Evaluate("2 2 +"); result.Should().Be(4.0); }
public void Expression_tree_complexa() { var eval = new PostfixEvaluator(); // 3 + 4 * 2 / ( 1 - 5 ) ^ 2 ^ 3 var result = eval.BuildExpressionTree("3 4 2 * 1 5 - 2 3 ^ ^ / +"); result.Should().Be(10.4); }
public void Deve_avaliar_operador_soma_multiplicacao_com_dois_operandos() { var eval = new PostfixEvaluator(); // 2 ^ 4 / (5 * 8) + 10 var result = eval.Evaluate("2 4 ^ 5 8 * / 10 +"); result.Should().Be(10.4); }
public void PostfixEvaluatorTest() { // 3 + 4 * 5 = 23 var queue = ShuntingYardAlgorithm.ShuntingYard("3+4*5"); PostfixEvaluator.EvaluatePostfix(queue).Should().Be(23); // 3 * (4 + 5) = 27 queue = ShuntingYardAlgorithm.ShuntingYard("3*(4+5)"); PostfixEvaluator.EvaluatePostfix(queue).Should().Be(27); }
private void TbInfix_TextChanged(object sender, TextChangedEventArgs e) { QueueUsingDoublyLinkedList <string> temp = InfixToPostfixConverter.ConvertToPostfix(TbInfix.Text); QueueUsingDoublyLinkedList <string> postfix = new QueueUsingDoublyLinkedList <string>(); var sb = new StringBuilder(); int count = temp.Count; for (int x = 0; x < count; x++) { var y = temp.Dequeue(); postfix.Enqueue(y); sb.Append(y); } TbPostfix.Text = sb.ToString(); TbResult.Text = PostfixEvaluator.EvaluatePostFixExpression(postfix).ToString(); }