public void Calculate() { try { if (!string.IsNullOrEmpty(calculator.Display)) { calculator.SecondNumber = double.Parse(calculator.Display); } calculator.Result = calculator.Calculate(); calculator.Display = calculator.Result.ToString(); history.Enqueue(calculator.ToString()); calculator.FirstNumber = calculator.Result.Value; } catch (Exception ex) { if (!calculator.hasOperation) { error = "Please choose an operator before calculating"; } else { error = ex.Message; } } }
public void CalcTestTrue() { var calc = new CalculatorModel(new Model { X = 0, Y = 3 }); var result = calc.Calculate(); Assert.IsTrue(result == 3); }
private void Btn_TouchUpInside(object sender, EventArgs e) { var calc = new CalculatorModel(new Model { X = i, Y = i }); tv.Text = $"Result: {calc.Calculate()}"; i++; }
public ActionResult Calculate(CalculatorModel model) { if (ModelState.IsValid) { try { model.Calculate(); } catch (Exception e) { model.ModelException = e.Message; } } return(View("Index", model)); }
private void ExecuteCalculate(object param) { _historyIdx = 0; if (_model.Action == null) { return; } try { CalculatorOutput = (_model.Calculate(Array.ConvertAll(CalculatorInput, int.Parse))).ToString(); } catch { CalculatorOutput = "Неправильный ввод"; } _logger.Write(new LogEntry(CalculatorInput, _model.Action, CalculatorOutput)); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); Xamarin.Essentials.Platform.Init(this, savedInstanceState); // Set our view from the "main" layout resource SetContentView(Resource.Layout.activity_main); var tv = FindViewById <TextView>(Resource.Id.tv); var btn = FindViewById <Button>(Resource.Id.btn); int i = 0; btn.Click += (s, e) => { var calc = new CalculatorModel(new Model { X = i, Y = i }); tv.Text = $"Result: {calc.Calculate()}"; i++; }; }
public void Calculate() { CalculatorModel model = new CalculatorModel(view.NumberA, view.NumberB); model.Calculate(); }
public void Calculate() { CalculatorModel model = this.view.Model; model.Calculate(); }
public void Multiple() { calcModel.Calculate("5*5"); string result = calcModel.Result; Console.WriteLine(result); Assert.IsTrue(result.Equals("25")); }
public CalculatorViewModel() { CalculateCommand = new RelayCommand <string>(param => OutputText = IsValidInput(InputText) ? _model.Calculate(InputText) : "Invalid Input" ); InputCommand = new RelayCommand <string>(input => { InputText += input; InputTextBackground = IsValidInput(InputText) ? Brushes.White : Brushes.Crimson; }); EarseCommand = new RelayCommand <string>(param => InputText = ""); BackspaceCommand = new RelayCommand <string>(param => { if (InputText.Length > 0) { InputText = InputText.Remove(InputText.Length - 1); } InputTextBackground = IsValidInput(InputText) ? Brushes.White : Brushes.Crimson; }); _model = new CalculatorModel(); WindowCloseCommand = new RelayCommand <object>(o => _model.CloseService()); }