コード例 #1
0
        public ActionResult Index(
            double firstNumber,
            double secondNumber,
            string operation)
        {
            string[] arr = { "Mult", "Div", "Plus", "Minus", "Max" };
            double   result;

            if (arr.Contains(operation))
            {
                ITwoArgCalculator calculator = TwoArgFactory.CreateObjectOrientedCalculator(operation);
                result = calculator.Calculate(firstNumber, secondNumber);
            }
            else
            {
                IOneArgCalculator calculator = OneArgFactory.CreateObjectOrientedCalculator(operation);
                result = calculator.Calculate(firstNumber);
            }

            ViewBag.Result    = result;
            ViewBag.Operation = new SelectListItem[]
            {
                new SelectListItem()
                {
                    Value = "Mult", Text = "Multiply"
                },
                new SelectListItem()
                {
                    Value = "Plus", Text = "Sum"
                },
                new SelectListItem()
                {
                    Value = "Minus", Text = "Minus"
                },
                new SelectListItem()
                {
                    Value = "Div", Text = "Division"
                },
                new SelectListItem()
                {
                    Value = "Exp", Text = "Exponent"
                },
                new SelectListItem()
                {
                    Value = "Max", Text = "Maximum"
                },
            };
            return(View());
        }
コード例 #2
0
 private void button15_Click(object sender, EventArgs e)
 {
     b = Convert.ToDouble(textBox1.Text);
     if (Operation == ("Div") && b == 0)
     {
         MessageBox.Show("Деление на ноль невозможно");
         textBox1.Clear();
     }
     else
     {
         ITwoArgCalculator calculator = TwoArgFactory.CreateObjectOrientedCalculator(Operation);
         double            res        = calculator.Calculate(a, b);
         textBox1.Text = res.ToString();
     }
 }
コード例 #3
0
        public void CalculateTest(string name, Type type)
        {
            var calculator = TwoArgFactory.CreateObjectOrientedCalculator(name);

            Assert.IsInstanceOf(type, calculator);
        }