當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Calculator::divide方法代碼示例

本文整理匯總了PHP中Calculator::divide方法的典型用法代碼示例。如果您正苦於以下問題:PHP Calculator::divide方法的具體用法?PHP Calculator::divide怎麽用?PHP Calculator::divide使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Calculator的用法示例。


在下文中一共展示了Calculator::divide方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testDivide

 public function testDivide()
 {
     $calc = new Calculator();
     $quotient = $calc->divide(10, 2);
     $this->assertEquals(5, $quotient);
     //check if 10/2 is equal to 5
 }
開發者ID:sampletestorg1,項目名稱:sample_php,代碼行數:7,代碼來源:calculator_test.php

示例2: shouldDivideTwoNumbers

 /**
  * @test
  */
 public function shouldDivideTwoNumbers()
 {
     // given
     $calculator = new \Calculator();
     // when
     $result = $calculator->divide(10, 5);
     // then
     $this->assertEquals(2, $result);
 }
開發者ID:DevSKiller,項目名稱:devskiller-sample-php-calculator,代碼行數:12,代碼來源:CalculatorTest.php

示例3: shouldThrowExceptionForDivisionByZero

 /**
  * @test
  * @expectedException InvalidArgumentException
  */
 public function shouldThrowExceptionForDivisionByZero()
 {
     // given
     $calculator = new \Calculator();
     // when
     $calculator->divide(10, 0);
     // then
     $this->fail('exception should be thrown');
 }
開發者ID:DevSKiller,項目名稱:devskiller-sample-php-calculator,代碼行數:13,代碼來源:IllegalArgumentsTest.php

示例4: shouldDivideTwoNumbers

 /**
  * @test
  */
 public function shouldDivideTwoNumbers()
 {
     // given
     $a = rand(0, 100);
     $b = rand(1, 100);
     $calculator = new \Calculator();
     // when
     $result = $calculator->divide($a, $b);
     // then
     $this->assertEquals(round($a / $b), $result);
 }
開發者ID:DevSKiller,項目名稱:devskiller-sample-php-calculator,代碼行數:14,代碼來源:RandomNumbersTest.php

示例5: Calculator

<?php

//set defaults
$number1 = 0;
$number2 = 0;
$result = 0;
//check the post
if (isset($_POST['submit'])) {
    //get the values
    $number1 = (int) strip_tags(trim($_POST['number1']));
    $number2 = (int) strip_tags(trim($_POST['number2']));
    $result = (int) strip_tags(trim($_POST['result']));
    //get result from model (send the values)
    $calc = new Calculator($number1, $number2, $result);
}
if ($_POST['plus']) {
    $result = $calc->add($number1, $number2);
} else {
    if ($_POST['minus']) {
        $result = $calc->minus($number1, $number2);
    } else {
        if ($_POST['times']) {
            $result = $calc->mutiply($number1, $number2);
        } else {
            if ($_POST['divide']) {
                $result = $calc->divide($number1, $number2);
            }
        }
    }
}
開發者ID:beshad,項目名稱:my-first-php-project,代碼行數:30,代碼來源:home.php

示例6: testThrowsInvalidArgumentExceptionIfTryingToDivideByZero

 /**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage Cannot divide by zero!
  */
 public function testThrowsInvalidArgumentExceptionIfTryingToDivideByZero()
 {
     $calculator = new Calculator();
     $calculator->divide(5, 0);
 }
開發者ID:michaelmoussa,項目名稱:talks,代碼行數:9,代碼來源:CalculatorTest.php

示例7: __construct

    public function __construct($a, $b)
    {
        $this->_a = $a;
        $this->_b = $b;
    }
    public function add()
    {
        return $this->_a + $this->_b;
    }
    public function subtract()
    {
        return $this->_a - $this->_b;
    }
    public function multiply()
    {
        return $this->_a * $this->_b;
    }
    public function divide()
    {
        return $this->_a / $this->_b;
    }
}
$mycalc = new Calculator(12, 6);
echo $mycalc->add() . "<br>";
// Displays 18
echo $mycalc->multiply() . "<br>";
// Displays 72
echo $mycalc->subtract() . "<br>";
// Displays 6
echo $mycalc->divide() . "<br>";
// Displays 2
開發者ID:kbalog,項目名稱:web-programming,代碼行數:31,代碼來源:exercise6.php

示例8: add

    {
        $this->_val1 = $val1;
        $this->_val2 = $val2;
    }
    public function add()
    {
        return $this->_val1 + $this->_val2;
    }
    public function subtract()
    {
        return $this->_val1 - $this->_val2;
    }
    public function multiply()
    {
        return $this->_val1 * $this->_val2;
    }
    public function divide()
    {
        return $this->_val1 / $this->_val2;
    }
}
$calc = new Calculator(3, 4);
echo "<p>3 + 4 = " . $calc->add() . "</p>";
echo "<p>3 - 4 = " . $calc->subtract() . "</p>";
echo "<p>3 * 4 = " . $calc->multiply() . "</p>";
echo "<p>3 / 4 = " . $calc->divide() . "</p>";
?>

  </body>
</html>
開發者ID:hoiwanjohnlouis,項目名稱:eclipsePrototyping,代碼行數:30,代碼來源:exercise1.php


注:本文中的Calculator::divide方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。