package edu.pdx.cs410J.whitlock;

import org.junit.Ignore;
import org.junit.Test;

import java.util.List;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.fail;

public class RPNCalculatorTest
{

  @Test
  public void emptyExpressionEvaluatesToZero() {
    RPNCalculator calculator = new RPNCalculator();
    assertThat(calculator.evaluate(""), equalTo(0));
  }

  @Test
  public void nonNumberIssuesError() {
    String invalid = "QQQ";
    RPNCalculator calculator = new RPNCalculator();
    try {
      calculator.evaluate(invalid);
      fail();

    } catch (InvalidRPNExpressionException ex) {
      assertThat(ex.getMessage(), containsString("Invalid expression: " + invalid));
    }
  }

  @Test
  public void canParseNumbers() {
    List list = new RPNCalculator().parseExpression("1 2");
    assertThat(list.get(0), equalTo(1));
    assertThat(list.get(1), equalTo(2));
  }

  @Test
  public void canParseAdditionOperator() {
    List list = new RPNCalculator().parseExpression("+");
    assertThat(list.get(0), equalTo(RPNCalculator.Operation.ADDITION));
  }

  @Test
  public void canParseOperators() {
    List list = new RPNCalculator().parseExpression("+ - * /");
    assertThat(list.get(0), equalTo(RPNCalculator.Operation.ADDITION));
    assertThat(list.get(1), equalTo(RPNCalculator.Operation.SUBTRACT));
    assertThat(list.get(2), equalTo(RPNCalculator.Operation.MULTIPLY));
    assertThat(list.get(3), equalTo(RPNCalculator.Operation.DIVIDE));
  }

  @Test
  public void canPerformAddition() {
    RPNCalculator calculator = new RPNCalculator();
    assertThat(calculator.evaluate("1 2 +"), equalTo(3));
  }

  @Test
  public void canPerformSubtraction() {
    RPNCalculator calculator = new RPNCalculator();
    assertThat(calculator.evaluate("3 1 -"), equalTo(2));
  }

  @Test
  public void canPerformMultiplication() {
    RPNCalculator calculator = new RPNCalculator();
    assertThat(calculator.evaluate("3 2 *"), equalTo(6));
  }

  @Test
  public void canPerformDivision() {
    RPNCalculator calculator = new RPNCalculator();
    assertThat(calculator.evaluate("6 3 /"), equalTo(2));
  }

  @Ignore
  @Test
  public void oneOperandIssuesError() {
    RPNCalculator calculator = new RPNCalculator();
    try {
      calculator.evaluate("1");
      fail();

    } catch (InvalidRPNExpressionException ex) {
      assertThat(ex.getMessage(), containsString("Missing operator"));
    }
  }

}

@@ -1919,32 +1919,215 @@
 ualTo(2));%0A  %7D%0A%0A
+  @Test%0A  public void canPerformMultipleOperations() %7B%0A    RPNCalculator calculator = new RPNCalculator();%0A    assertThat(calculator.evaluate(%221 2 3 4 5 + + + +%22), equalTo(15));%0A  %7D%0A%0A
   @Test%0A  public

Make sure that we can perform multiple operations.