public void ShouldDisplayStack()
        {
            CalculatorContainer container = new CalculatorContainer();

            container.PushItem(5);
            container.PushItem(7);

            Assert.AreEqual("5;7", container.PrettyDisplay());
        }
        public void ShouldCleanEmptyStack()
        {
            CalculatorContainer container = new CalculatorContainer();

            container.PushItem(5);
            container.PushItem(5);
            Assert.That(container.Count() > 0);
            container.Clean();
            Assert.That(container.Count() == 0);
        }
        public void ShouldCoutStack()
        {
            CalculatorContainer container = new CalculatorContainer();

            Assert.AreEqual(0, container.Count());
            container.PushItem(5);
            container.PushItem(7);
            Assert.AreEqual(2, container.Count());
            container.PushItem(19);
            Assert.AreEqual(3, container.Count());
        }
示例#4
0
        public void ShouldApplyOperatorRaiseExceptionWhenOperatorInvalid()
        {
            CalculatorContainer container = new CalculatorContainer();
            CalculatorExecutor  executor  = new CalculatorExecutor();

            container.PushItem(5);
            container.PushItem(5);
            container.PushItem(5);

            InvalidOperationException ex = Assert.Throws <InvalidOperationException>(() => executor.ApplyOperator(container, ":"));

            Assert.That(ex.Message, Is.EqualTo("The symbol ':' is not recognised as a valid operator. Accepted operators are: (+, -, *, /)"));
        }
示例#5
0
        public void ShouldApplyOperatorSuccefully()
        {
            CalculatorContainer container = new CalculatorContainer();
            CalculatorExecutor  executor  = new CalculatorExecutor();

            container.PushItem(5);
            container.PushItem(7);
            container.PushItem(8);
            executor.ApplyOperator(container, "+");
            Assert.AreEqual("5;15", container.PrettyDisplay());
            container.PushItem(10);
            executor.ApplyOperator(container, "-");
            Assert.AreEqual("5;-5", container.PrettyDisplay());
            executor.ApplyOperator(container, "*");
            Assert.AreEqual("-25", container.PrettyDisplay());
        }
        public void ShouldPushItemToStack()
        {
            CalculatorContainer container = new CalculatorContainer();

            container.PushItem(5);
            Assert.That(container.Count() == 1);
            var lastItem = container.PopItem();

            Assert.AreEqual(5, lastItem);
        }
示例#7
0
        public void ShouldApplyOperatorRaiseExceptionWhenStackEmpty()
        {
            CalculatorContainer container = new CalculatorContainer();
            CalculatorExecutor  executor  = new CalculatorExecutor();

            container.PushItem(5);

            InvalidOperationException ex = Assert.Throws <InvalidOperationException>(() => executor.ApplyOperator(container, "+"));

            Assert.That(ex.Message, Is.EqualTo("The stack must have at least two items to apply an operator"));
        }
示例#8
0
 public void Push(double item)
 {
     CalculatorContainer.PushItem(item);
 }