static void Main(string[] args) { try { var CalcActions = new Dictionary<string, ICalculatorAction>() { {"+", new AdditionCalculatorAction() }, {"-", new SubtractionCalculatorAction() }, {"*", new MultiplicationCalculatorAction() }, {"/", new DivisionCalculatorAction() } }; var Calc = new Calculator(0); var Strategy = new CalculateStrategy(CalcActions, Calc, new DataInput()); if (DoCalculate(Strategy, Calc)) Console.WriteLine("\nВычисления завершены. Окончательное значение: {0}\n", Calc.CurrentValue); else Console.WriteLine("Вычисления отменены"); } catch (Exception E) { Console.WriteLine("Во время работы программы произошла ошибка: {0}", E.Message); } Console.Write("Нажмите ENTER для завершения работы..."); Console.ReadLine(); }
static void Main() { var calc = new Calculator(); calc.ErrorOperation += (sender, args) => Console.WriteLine(args.Message); calc.DoCalculation("/", 1, 0); //calc.AddOperation("%", (x,y) =>x % y); }
public void MultiplyTest() { //arrange Calculator calc = new Calculator(); int number1 = 5; int number2 = 7; int expected = 35; //act int actual = calc.Multiply(number1, number2); //assert Assert.AreEqual(expected, actual); }
public void AddTest() { //arrange Calculator calc = new Calculator(); int number1 = 5; int number2 = 7; int expected = 12; //act int actual = calc.Add(number2, number1); //assert Assert.AreEqual(expected, actual); }
public void OneActionTest() { var Calc = new Calculator(0); var Action = new Mock<ICalculatorAction>(); Action.SetupGet(t => t.Unary).Returns(false); Action.Setup(t => t.Calculate(It.IsAny<double>(), It.IsAny<double?>())).Returns(200); Calc.InputAction(Action.Object); Calc.InputNumber(50); Assert.AreEqual(200, Calc.CurrentValue); Action.Verify(a => a.Unary, Times.AtLeastOnce()); Action.Verify(a => a.Calculate(It.Is<double>(d => d == 0), It.Is<double?>(d => d.HasValue && d.Value == 50)), Times.Once()); }
public void UnaryActionTest() { var Calc = new Calculator(0); var Action = new Mock<ICalculatorAction>(); Action.SetupGet(t => t.Unary).Returns(true); Action.Setup(t => t.Calculate(It.IsAny<double>(), It.IsAny<double?>())).Returns(200); Calc.InputAction(Action.Object); Assert.AreEqual(200, Calc.CurrentValue); Assert.AreEqual(WaitedInput.Action, Calc.InputWaited); Action.Verify(a => a.Unary, Times.AtLeastOnce()); Action.Verify(a => a.Calculate(It.Is<double>(d => d == 0), It.Is<double?>(d => !d.HasValue)), Times.Once()); }
public void handleParens(object sender, CommandEventArgs args) { Calculator.HandleParens(args.CommandArgument); calcInput.Text = Calculator.expression; }