123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- /**
- * Created by PhpStorm.
- * User: yguern
- * Date: 29/09/2017
- * Time: 09:01
- */
- namespace Cloud\RDexp\Calculator;
- class CalculatorTest extends \PHPUnit_Framework_TestCase
- {
- /**
- * @var Calculator $calculator
- */
- private $calculator;
- public function setUp()
- {
- $this->calculator = new Calculator();
- }
- /**
- * What : try to add non real number 10 + 'test'
- * Expected : An exception must be thrown
- */
- public function testAddNonRealNumber() {
- $this->calculator = new Calculator();
- 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 but one of them is a string (10.1 + "42")
- * Expected : Returns 52.1
- */
- public function testAddRealNumberAsString() {
- $result = $this->calculator->add(10.1, "42.2");
- $this->assertEquals(52.3, $result);
- }
- }
|