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); }
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++; }
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); }
private void Calculate(MathCommand command) { logger.Append(command); command.Execute(); }