Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
        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);
            }
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        /// <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);
        }
Ejemplo n.º 7
0
        // Кнопка вычисления
        private void CalculateButton_Click(object sender, EventArgs e)
        {
            Calculate calc = new Calculate();

            this.Output.Text = calc.Calc(this.UserInput.Text);
        }
Ejemplo n.º 8
0
 public void TestCalcWF(double x, double y, string op, double res)
 {
     Assert.AreEqual(res, Calculate.Calc(x, y, op));
 }