public function testMultiply() { $calc = new Calculator(); $product = $calc->multiply(array(1, 3, 5, 6)); $this->assertEquals(90, $product); //check if 1*3*5*6 is equal to 90 }
/** * @test */ public function shouldMultiplyTwoNumbers() { // given $calculator = new \Calculator(); // when $result = $calculator->multiply(2, 3); // then $this->assertEquals(6, $result); }
/** * @test */ public function shouldMultiplyTwoNumbers() { // given $a = rand(0, 100); $b = rand(0, 100); $calculator = new \Calculator(); // when $result = $calculator->multiply($a, $b); // then $this->assertEquals($a * $b, $result); }
</td> </tr> <!--Checks whether buttons have been clicked and calls the function according to btn clicked--> <?php $obj = new Calculator(); if (isset($_POST['btn'])) { $first_number = $_POST['first_number']; $second_number = $_POST['second_number']; if ($_POST['btn'] == '+') { $result = $obj->addition($first_number, $second_number); } if ($_POST['btn'] == '-') { $result = $obj->subtraction($first_number, $second_number); } if ($_POST['btn'] == '*') { $result = $obj->multiply($first_number, $second_number); } if ($_POST['btn'] == '/') { $result = $obj->division($first_number, $second_number); } // if($first_number==0 or $second_number==0){ // $result= $obj->nothing(); // } } ?> <tr> <td><?php echo $result['label_value']; ?> </td>
<?php require_once 'Calculator.php'; $Calc = new Calculator(); $Calc->add(5); $Calc->multiply(7); echo $Calc->getTotal();
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
{ $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>
public function percent($value) { return $this->calculator->multiply($this->calculator->getDecimal($value), 100); }