public void CheckDigit(int min, int max, int pow, double expected) { var sut = new Calculate(); var result = sut.Calc(min, max, pow); Assert.Equal(expected, result); }
/// <summary> /// To add the current number and the selected operation to the current expression /// </summary> public void SetBasicMathOperation(BasicMathOperations pressedOperation) { //If the expression was calculated and any basic math operation was pressed, except for "=" if (buttonsState.EqualBtnPressed && (pressedOperation != BasicMathOperations.Equal)) { currentData.CurrentExpression = clearData.ClearExpression(currentData.CurrentExpression); buttonsState.NumberPadBtnPressed_Change(true); buttonsState.AdditionalOperationBtnPressed_Change(false); buttonsState.EqualBtnPressed_Change(false); } currentData.CurrentExpression = NewCurrentExpression(pressedOperation); try { currentData.CurrentNumber = pressedOperation == BasicMathOperations.Equal ? calculate.Calc(currentData.CurrentExpression).ToString() : clearData.ClearNumber(currentData.CurrentNumber); } catch (DivideByZeroException) { currentData.CurrentNumber = "Division by zero"; } catch (OverflowException) { currentData.CurrentNumber = "NaN"; } if (pressedOperation == BasicMathOperations.Equal) { buttonsState.EqualBtnPressed_Change(true); } buttonsState.NumberPadBtnPressed_Change(false); buttonsState.AdditionalOperationBtnPressed_Change(false); }
public ActionResult Index(Poster poster) { if (!ModelState.IsValid) { ViewBag.Table = Calculate.GetTeable().ToList(); ViewBag.Error = "Данные для вычисления не полный!"; return(View(poster)); } var res = Calculate.Calc(poster); Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("Uz"); Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("Uz"); ViewBag.Result = Convert.ToDecimal(res).ToString("C"); ViewBag.Table = Calculate.GetTeable().ToList(); return(View(poster)); }
public void TestMethod2() { List <string> listRes = new List <string>(); string temp = "", tmp = ""; List <string> listExp = new List <string>() { "0", "0,283", "0,289", "0,194", "0", "0,323", "0,866", "1,984" }; listRes = Calculate.Calc(0.25, -1, 1, 1, listRes); for (int i = 0; i < 8; i++) { temp = listRes[i]; tmp = listExp[i]; Assert.AreEqual(temp, tmp); } }
public void TestMethod1() { List <string> listRes = new List <string>(); string temp = "", tmp = ""; List <string> listExp = new List <string>() { "0", "1,134", "1,155", "0,775", "0", "1,291", "3,464", "7,937" }; listRes = Calculate.Calc(1, -4, 4, 4, listRes); for (int i = 0; i < 8; i++) { temp = listRes[i]; tmp = listExp[i]; Assert.AreEqual(temp, tmp); } //CollectionAssert.AreEqual(listRes, listExp); }
/// <summary> /// To add the current number and the selected operation to the current expression /// </summary> public void SetBasicMathOperation(BasicMathOperations pressedOperation) { //If the expression was calculated and any basic math operation was pressed, except for "=" if (buttonsState.EqualBtnPressed && (pressedOperation != BasicMathOperations.Equal)) { currentData.CurrentExpression = clearData.ClearExpression(currentData.CurrentExpression); buttonsState.NumberPadBtnPressed_Change(true); buttonsState.AdditionalOperationBtnPressed_Change(false); buttonsState.EqualBtnPressed_Change(false); } currentData.CurrentExpression = NewCurrentExpression(pressedOperation); currentData.CurrentNumber = pressedOperation == BasicMathOperations.Equal ? calculate.Calc(currentData.CurrentExpression).ToString() : clearData.ClearNumber(currentData.CurrentNumber); if (double.IsNaN(double.Parse(currentData.CurrentNumber)) || double.IsPositiveInfinity(double.Parse(currentData.CurrentNumber)) || double.IsNegativeInfinity(double.Parse(currentData.CurrentNumber))) { currentData.CurrentNumber = "Calculation error"; } if (pressedOperation == BasicMathOperations.Equal) { buttonsState.EqualBtnPressed_Change(true); } buttonsState.NumberPadBtnPressed_Change(false); buttonsState.AdditionalOperationBtnPressed_Change(false); }
// Кнопка вычисления private void CalculateButton_Click(object sender, EventArgs e) { Calculate calc = new Calculate(); this.Output.Text = calc.Calc(this.UserInput.Text); }
public void TestCalcWF(double x, double y, string op, double res) { Assert.AreEqual(res, Calculate.Calc(x, y, op)); }