public void IfStackEmptyThenOperationShouldApplyToAccumulatorTest() { var cpu = new SimpleCpu(); cpu.Accumulator.SetValue(10); var operation = cpu.FindOperation("negate"); operation.Execute(); Assert.IsTrue(cpu.OperandStack.Count == 0); Assert.IsTrue(cpu.Accumulator.ToString() == "-10"); }
public void IfAccumulatorEmptyThenOperationShouldApplyToOperandStackTest() { var cpu = new SimpleCpu(); cpu.OperandStack.Push(10); var operation = cpu.FindOperation("negate"); operation.Execute(); Assert.IsTrue(cpu.OperandStack.Count == 1); Assert.IsTrue(cpu.OperandStack.Peek() == -10); }
public void TwoOperandWithoutExistingOperatorShouldEvaulateTest() { var cpu = new SimpleCpu(); cpu.OperandStack.Push(5); cpu.OperandStack.Push(6); var op = cpu.FindOperation("+"); op.Execute(); Assert.IsTrue(cpu.OperandStack.Count == 1); Assert.IsTrue(cpu.OperandStack.Peek() == 11); Assert.IsTrue(cpu.OperatorStack.Count == 0); }
public void SingleOperandShouldQueueOperationTest() { var cpu = new SimpleCpu(); cpu.OperandStack.Push(5); var op = cpu.FindOperation("+"); op.Execute(); Assert.IsTrue(cpu.OperandStack.Count == 1); Assert.IsTrue(cpu.OperandStack.Peek() == 5); Assert.IsTrue(cpu.OperatorStack.Count == 1); Assert.IsTrue(cpu.OperatorStack.Peek() == "+"); }