当前位置: 首页>>代码示例>>C#>>正文


C# Calculator.Divide方法代码示例

本文整理汇总了C#中Calculator.Divide方法的典型用法代码示例。如果您正苦于以下问题:C# Calculator.Divide方法的具体用法?C# Calculator.Divide怎么用?C# Calculator.Divide使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Calculator的用法示例。


在下文中一共展示了Calculator.Divide方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CalculateButton_Click

 protected void CalculateButton_Click(object sender, EventArgs e)
 {
     if (ValueBox1.Text.Length > 0 && ValueBox2.Text.Length > 0)
     {
       double result = 0;
       double value1 = Convert.ToDouble(ValueBox1.Text);
       double value2 = Convert.ToDouble(ValueBox2.Text);
       Calculator myCalculator = new Calculator();
       switch (OperatorList.SelectedValue)
       {
     case "+":
       result = myCalculator.Add(value1, value2);
       break;
     case "-":
       result = myCalculator.Subtract(value1, value2);
       break;
     case "*":
       result = myCalculator.Multiply(value1, value2);
       break;
     case "/":
       result = myCalculator.Divide(value1, value2);
       break;
       }
       ResultLabel.Text = result.ToString();
     }
     else
     {
       ResultLabel.Text = string.Empty;
     }
 }
开发者ID:kathytrinh81,项目名称:assignment10,代码行数:30,代码来源:CalculatorDemo.aspx.cs

示例2: ShouldErrorWhenDivideByZero_ExplicitExceptionType

        public void ShouldErrorWhenDivideByZero_ExplicitExceptionType()
        {
            var sut = new Calculator();

            Assert.That(() => sut.Divide(99, 0), 
                Throws.TypeOf<DivideByZeroException>());
        }
开发者ID:CodeSavant,项目名称:NUnitDemo,代码行数:7,代码来源:CalculatorTests.cs

示例3: ShouldErrorWhenNumberTooBig

        public void ShouldErrorWhenNumberTooBig()
        {
            var sut = new Calculator();

            Assert.That(() => sut.Divide(200, 2), 
                Throws.TypeOf<ArgumentOutOfRangeException>());
        }
开发者ID:CodeSavant,项目名称:NUnitDemo,代码行数:7,代码来源:CalculatorTests.cs

示例4: CalculateButton_Click

    protected void CalculateButton_Click(object sender, EventArgs e)
    {
        if (ValueBox1.Text.Length > 0 && ValueBox2.Text.Length > 0)
        {
          double result = 0;
          double value1 = Convert.ToDouble(ValueBox1.Text);
          double value2 = Convert.ToDouble(ValueBox2.Text);

          Calculator myCalculator = new Calculator();
          Trace.Write(string.Format("Performing the calculation with the {0} operator", OperatorList.SelectedValue));
          switch (OperatorList.SelectedValue)
          {
        case "+":
          result = myCalculator.Add(value1, value2);
          break;
        case "-":
          result = myCalculator.Subtract(value1, value2);
          break;
        case "*":
          result = myCalculator.Multiply(value1, value2);
          break;
        case "/":
          result = myCalculator.Divide(value1, value2);
          break;
          }
          ResultLabel.Text = result.ToString();
        }
        else
        {
          ResultLabel.Text = string.Empty;
          Trace.Warn("Custom Category", "TextBox controls are empty; time to add Validation controls?");
        }
    }
开发者ID:evilempire22,项目名称:BegASPNET,代码行数:33,代码来源:CalculatorDemo.aspx.cs

示例5: ShouldErrorWhenNumberTooBig_MoreExplicit

        public void ShouldErrorWhenNumberTooBig_MoreExplicit()
        {
            var sut = new Calculator();

            Assert.That(() => sut.Divide(200, 2), 
                Throws.TypeOf<ArgumentOutOfRangeException>()
                .With.Matches<ArgumentOutOfRangeException>(x => x.ParamName == "value"));
        }
开发者ID:CodeSavant,项目名称:NUnitDemo,代码行数:8,代码来源:CalculatorTests.cs

示例6: divide_with_zero_then_return_throw_exception

        public void divide_with_zero_then_return_throw_exception()
        {
            //Arrange
            var calc = new Calculator();

            //Act
            calc.Divide(10, 0);
        }
开发者ID:alabras,项目名称:Acid-MeetUp-UnitTest,代码行数:8,代码来源:CalculatorDivideFixture.cs

示例7: TestDivideNumbers

 public void TestDivideNumbers() {
     //Arange 
     var calc = new Calculator();
     //Act
     var result = calc.Divide(21, 3);
     //Assert
     Assert.AreEqual(7, result);
 }
开发者ID:dustin-hitzing,项目名称:C-Calculator-with-Unit-Testing,代码行数:8,代码来源:CalculatorTests.cs

示例8: TestDivideNumbers

        public void TestDivideNumbers() {

            //Arrange
            var calculator = new Calculator();
            //Act
            var result = calculator.Divide(20, 5);
            //Assert
            Assert.AreEqual(4, result);
        }
开发者ID:sarahywloo,项目名称:CSharpRobust,代码行数:9,代码来源:CalculatorTests.cs

示例9: TestDivideByZero

        public void TestDivideByZero() {

            //Arrange
            var calculator = new Calculator();
            //Act
            var result = calculator.Divide(20, 0);
            //Assert
            Assert.AreEqual(double.PositiveInfinity, result);
        }
开发者ID:sarahywloo,项目名称:CSharpRobust,代码行数:9,代码来源:CalculatorTests.cs

示例10: TestDivideFrac

        public void TestDivideFrac() {

            //Arrange
            var calculator = new Calculator();
            //Act
            var result = calculator.Divide(3, 5);
            //Assert
            Assert.AreEqual(0.6, result);
        }
开发者ID:sarahywloo,项目名称:CSharpRobust,代码行数:9,代码来源:CalculatorTests.cs

示例11: TestDivideNegative

        public void TestDivideNegative() {

            //Arrange
            var calculator = new Calculator();
            //Act
            var result = calculator.Divide(-20, 5);
            //Assert
            Assert.AreEqual(-4, result);
        }
开发者ID:sarahywloo,项目名称:CSharpRobust,代码行数:9,代码来源:CalculatorTests.cs

示例12: divide_with_10_5_return_2

        public void divide_with_10_5_return_2()
        {
            //Arrangewith
            var calc = new Calculator();

            //Act
            var result = calc.Divide(10, 5);

            //Assert
            Assert.AreEqual(2, result);
        }
开发者ID:alabras,项目名称:Acid-MeetUp-UnitTest,代码行数:11,代码来源:CalculatorDivideFixture.cs

示例13: DivideTest

        public void DivideTest()
        {
            // arrange
            Calculator calc = new Calculator();
            int number1 = 5;
            int number2 = 7;
            int result = number1 / number2;

            // act
            int actual = calc.Divide(number1, number2);

            // assert
            Assert.AreEqual(result, actual);
        }
开发者ID:H9964,项目名称:Olioharjoitukset,代码行数:14,代码来源:CalculatorTests.cs

示例14: ShouldThrowExceptionWhenDivideByZero

 public void ShouldThrowExceptionWhenDivideByZero()
 {
     var calculator = new Calculator();
     Should.Throw<DivideByZeroException>(() => calculator.Divide(100, 0));
 }
开发者ID:kenwilcox,项目名称:PlayingWithShouldly,代码行数:5,代码来源:CalculatorTests.cs

示例15: TestDivide

 public void TestDivide()
 {
     var calc = new Calculator();
     var result = calc.Divide(33, 11);
     Assert.AreEqual(3, result);
 }
开发者ID:zg-mixon,项目名称:CSharpPractice1-14-16,代码行数:6,代码来源:CalcTests.cs


注:本文中的Calculator.Divide方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。