public void OperatorCommandInClearStateShouldBeInvariantTest() { var calc = CalculatorFactory.BuildNew(); var state = new ClearState(calc); state.Notify(new OperatorCommand("+")); Assert.IsTrue(calc.State is ClearState); }
public void PointCommandInClearStateShouldChangeToAccumulatorStateTest() { var calc = CalculatorFactory.BuildNew(); var state = new ClearState(calc); state.Notify(PointCommand.Instance); Assert.IsTrue(calc.State is AccumulatorState); }
public void BinaryOperatorCommandShouldNotChangeStateTest() { Calculator calc = CalculatorFactory.BuildNew(); calc.Notify(new DigitCommand(1)); Assert.IsTrue(calc.State is AccumulatorState); calc.Notify(new OperatorCommand("+")); Assert.IsTrue(calc.State is AccumulatorState); }
public void PointCommandShouldSetAccumulatorTest() { var calc = CalculatorFactory.BuildNew(); var state = new ClearState(calc); Assert.IsTrue(calc.CPU.Accumulator.IsEmpty); state.Notify(PointCommand.Instance); Assert.IsTrue(calc.State is AccumulatorState); Assert.IsTrue(calc.CPU.Accumulator.ToString() == "0."); }
public void PointCommandWithIntergerValueShouldAppendDotTest() { Calculator calc = CalculatorFactory.BuildNew(); calc.Notify(new DigitCommand(1)); Assert.IsTrue(calc.State is AccumulatorState); Assert.IsTrue(calc.CPU.Accumulator.ToString() == "1"); calc.Notify(PointCommand.Instance); Assert.IsTrue(calc.CPU.Accumulator.ToString() == "1."); }
public void PointCommandWithDecimalValueShouldBeIgnoredTest() { Calculator calc = CalculatorFactory.BuildNew(); calc.Notify(PointCommand.Instance); Assert.IsTrue(calc.State is AccumulatorState); Assert.IsTrue(calc.CPU.Accumulator.ToString() == "0."); calc.Notify(PointCommand.Instance); Assert.IsTrue(calc.CPU.Accumulator.ToString() == "0."); }
public void PointCommandShouldNotChangeStateTest() { Calculator calc = CalculatorFactory.BuildNew(); calc.Notify(new DigitCommand(1)); Assert.IsTrue(calc.State is AccumulatorState); calc.Notify(PointCommand.Instance); Assert.IsTrue(calc.State is AccumulatorState); }
public void AnyDigitWithNonZeroAccumulatorShouldAppendDigitTest() { Calculator calc = CalculatorFactory.BuildNew(); calc.Notify(new DigitCommand(1)); Assert.IsTrue(calc.State is AccumulatorState); Assert.IsTrue(calc.CPU.Accumulator.ToString() == "1"); calc.Notify(new DigitCommand(2)); Assert.IsTrue(calc.CPU.Accumulator.ToString() == "12"); }
public void NonZeroDigitWithZeroAccumulatorShouldReplaceValueTest() { Calculator calc = CalculatorFactory.BuildNew(); calc.Notify(new DigitCommand(0)); Assert.IsTrue(calc.State is AccumulatorState); Assert.IsTrue(calc.CPU.Accumulator.ToString() == "0"); calc.Notify(new DigitCommand(1)); Assert.IsTrue(calc.CPU.Accumulator.ToString() == "1"); }
public void ZeroDigitWithZeroAccumulatorIsInvariantTest() { Calculator calc = CalculatorFactory.BuildNew(); calc.Notify(new DigitCommand(0)); Assert.IsTrue(calc.State is AccumulatorState); Assert.IsTrue(calc.CPU.Accumulator.ToString() == "0"); calc.Notify(new DigitCommand(0)); Assert.IsTrue(calc.CPU.Accumulator.ToString() == "0"); }
public void EqualsCommandShouldChangeStateToResultStateTest() { Calculator calc = CalculatorFactory.BuildNew(); calc.Notify(new DigitCommand(1)); Assert.IsTrue(calc.State is AccumulatorState); calc.Notify(new EqualsCommand()); Assert.IsTrue(calc.State is ResultState); }
public void EqualsCommandShouldPushAccumulatorToStack() { Calculator calc = CalculatorFactory.BuildNew(); calc.Notify(new DigitCommand(5)); Assert.IsTrue(calc.State is AccumulatorState); Assert.IsTrue(calc.CPU.Accumulator.ToString() == "5"); Assert.IsTrue(calc.CPU.OperandStack.Count == 0); calc.Notify(new EqualsCommand()); Assert.IsTrue(calc.CPU.Accumulator.IsEmpty); Assert.IsTrue(calc.CPU.OperandStack.Count == 1); Assert.IsTrue(calc.CPU.OperandStack.Peek() == 5); }
public void EqualsCommandWithTwoOperandShouldIgnoreRegisterTest() { Calculator calc = CalculatorFactory.BuildNew(); calc.Notify(new DigitCommand(5)); Assert.IsTrue(calc.State is AccumulatorState); calc.Notify(new OperatorCommand("+")); calc.Notify(new DigitCommand(6)); calc.Notify(new EqualsCommand()); Assert.IsTrue(calc.CPU.OperandStack.Count == 1); Assert.IsTrue(calc.CPU.OperandStack.Peek() == 11); Assert.IsTrue(calc.CPU.OperatorStack.Count == 1); Assert.IsTrue(calc.CPU.OperatorStack.Peek() == "+"); }
public void SequentialEqualsCommandWithSingleOperandShouldReuseFirstOperandRegisterTest() { Calculator calc = CalculatorFactory.BuildNew(); calc.Notify(new DigitCommand(5)); Assert.IsTrue(calc.State is AccumulatorState); calc.Notify(new OperatorCommand("+")); calc.Notify(new EqualsCommand()); calc.Notify(new EqualsCommand()); Assert.IsTrue(calc.CPU.OperandStack.Count == 1); Assert.IsTrue(calc.CPU.OperandStack.Peek() == 15); Assert.IsTrue(calc.CPU.OperatorStack.Count == 1); Assert.IsTrue(calc.CPU.OperatorStack.Peek() == "+"); }