public function testSubtract()
 {
     $calc = new Calculator();
     $difference = $calc->subtract(5, 2);
     $this->assertEquals(3, $difference);
     //check if 5 - 2 is equal to 3
 }
 /**
  * @test
  */
 public function shouldSubtractTwoNumbers()
 {
     // given
     $calculator = new \Calculator();
     // when
     $result = $calculator->subtract(3, 2);
     // then
     $this->assertEquals(1, $result);
 }
 /**
  * @test
  */
 public function shouldSubtractTwoNumbers()
 {
     // given
     $a = rand(0, 100);
     $b = rand(0, 100);
     $calculator = new \Calculator();
     // when
     $result = $calculator->subtract($a, $b);
     // then
     $this->assertEquals($a - $b, $result);
 }
Esempio n. 4
0
    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>