コード例 #1
0
        public void OperatorCommandInClearStateShouldBeInvariantTest()
        {
            var calc  = CalculatorFactory.BuildNew();
            var state = new ClearState(calc);

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

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