123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Noa
- * Date: 24/09/2017
- * Time: 15:14
- */
- namespace Cloud\RD\Calculator;
- use PHPUnit_Framework_TestCase;
- class CalculatorTest extends PHPUnit_Framework_TestCase
- {
- /**
- * @var Calculator $calculator
- */
- private $calculator;
- public function setUp()
- {
- $this->calculator = new Calculator();
- }
- /**
- * What : try to add non real numbers (10 + 'test')
- * Expected : An exception must be thrown
- */
- public function testAddNonRealNumber() {
- try {
- $this->calculator->add(10, 'test');
- $this->assertFalse(true, "An exception must be thrown");
- } catch (\Exception $e) {
- $this->assertInstanceOf(CalculatorException::class, $e);
- $this->assertEquals("Adding not real numbers", $e->getMessage());
- }
- }
- /**
- * What : add to real numbers (10.1 + 42)
- * Expected : Returns 52.1
- */
- public function testAddRealNumber() {
- $result = $this->calculator->add(10.1, 42);
- $this->assertEquals(52.1, $result);
- }
- /**
- * What : add to real numbers (10.1 + 42)
- * Expected : Returns 52.1
- */
- public function testAddProbeBothPositive() {
- $probe = '';
- $result = $this->calculator->add(10.1, 42, $probe);
- $this->assertEquals(52.1, $result);
- $this->assertEquals('1 1', $probe);
- }
- /**
- * What : add to real numbers (10.1 + 42)
- * Expected : Returns 42
- */
- public function testAddANullBPositive() {
- $probe = '';
- $result = $this->calculator->add(0, 42, $probe);
- $this->assertEquals(42, $result);
- $this->assertEquals('0 1', $probe);
- }
- }
|