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

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

            state.Notify(PointCommand.Instance);
            Assert.IsTrue(calc.State is AccumulatorState);
        }
Exemple #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);
        }
Exemple #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.");
        }
Exemple #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.");
        }
Exemple #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.");
        }
Exemple #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);
        }
Exemple #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");
        }
Exemple #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");
        }
Exemple #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");
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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() == "+");
        }
Exemple #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() == "+");
        }