Example #1
0
        public void OperatorCommandInClearStateShouldBeInvariantTest()
        {
            var calc  = CalculatorFactory.BuildNew();
            var state = new ClearState(calc);

            state.Notify(new OperatorCommand("+"));
            Assert.IsTrue(calc.State is ClearState);
        }
Example #2
0
        public void PointCommandInClearStateShouldChangeToAccumulatorStateTest()
        {
            var calc  = CalculatorFactory.BuildNew();
            var state = new ClearState(calc);

            state.Notify(PointCommand.Instance);
            Assert.IsTrue(calc.State is AccumulatorState);
        }
Example #3
0
        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);
        }
Example #4
0
        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.");
        }
Example #5
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.");
        }
Example #6
0
        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.");
        }
Example #7
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);
        }
Example #8
0
        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");
        }
Example #9
0
        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");
        }
Example #10
0
        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");
        }
Example #11
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);
        }
Example #12
0
        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);
        }
Example #13
0
        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() == "+");
        }
Example #14
0
        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() == "+");
        }