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); } /** * 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); } }