package esimene; import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.*; import org.junit.Test; public class RpnCalculatorTest { @Test public void newCalculatorHasZeroInAccumulator() { RpnCalculator calc = new RpnCalculator(); assertThat(calc.getAccumulator(), is(0)); } @Test public void accumulatorCanBeSet() { RpnCalculator calc = new RpnCalculator(); calc.setAccumulator(1); assertEquals(calc.getAccumulator(), 1); } @Test public void calculatorSupportsEnter() { RpnCalculator calc = new RpnCalculator(); calc.setAccumulator(1); calc.enter(); calc.setAccumulator(2); calc.plus(); assertEquals(calc.getAccumulator(), 3); } @Test public void calculatorSupportsAddition() { RpnCalculator calc = new RpnCalculator(); calc.setAccumulator(1); calc.enter(); calc.setAccumulator(2); calc.plus(); calc.enter(); calc.setAccumulator(3); calc.multiply(); assertEquals(calc.getAccumulator(), 9); } /* @Test public void stackTest(){ RpnCalculator calc = new RpnCalculator(); calc.setAccumulator(1); calc.enter(); calc.setAccumulator(2); calc.plus(); calc.setAccumulator(3); calc.enter(); calc.setAccumulator(4); calc.plus(); assertEquals(new Integer(7), calc.st.pop()); assertEquals(new Integer(3), calc.st.pop()); //assertEquals(new Integer(3), calc.st.pop()); assertTrue(calc.st.size()==0); } */ @Test public void calculatorSupportsAdditionAndMultiplication() { RpnCalculator calc = new RpnCalculator(); calc.setAccumulator(1); calc.enter(); calc.setAccumulator(2); calc.plus(); calc.enter(); calc.setAccumulator(3); calc.enter(); calc.setAccumulator(4); calc.plus(); calc.multiply(); assertEquals(calc.getAccumulator(), 21); } @Test public void calculatorSupportsStringCalculation() { RpnCalculator calc = new RpnCalculator(); calc.calculate("1 2 + 3 *"); assertEquals(calc.getAccumulator(), 9); } }