コード例 #1
0
        public void Run_ThrowsException_InputStackIsIncorrect()
        {
            // Arrange
            string         operation = "+";
            CommandContext context   = new CommandContext();

            context.PushStack(new MutableKeyValuePair <string, object>("var1", 5));

            var math = new MathCommand(operation, context);

            // Act
            void result() => math.Run();

            // Assert
            Assert.Throws <CommandExecutionException>(result);
        }
コード例 #2
0
 public void Append(MathCommand command)
 {
     if (Level < commands.Count)
     {
         commands[Level] = command;
         while (commands.Count > Level + 1)
         {
             commands.RemoveAt(Level + 1);
         }
     }
     else
     {
         commands.Add(command);
     }
     Level++;
 }
コード例 #3
0
        public void Run_SqrtOfVariable_InputOperationIsSqrt()
        {
            // Arrange
            string         operation = "SQRT";
            CommandContext context   = new CommandContext();

            context.PushStack(new MutableKeyValuePair <string, object>("var1", 25));

            double expectedNumber = 5;
            var    expectedName   = "ans";
            var    math           = new MathCommand(operation, context);

            // Act
            math.Run();

            // Assert
            Assert.Equal(expectedNumber, context.Stack.Peek().Value);
            Assert.Equal(expectedName, context.PeekLastStackElement().Id);
        }
コード例 #4
0
 private void Calculate(MathCommand command)
 {
     logger.Append(command);
     command.Execute();
 }