-
-
Save darles/c8065784747909e33437 to your computer and use it in GitHub Desktop.
TDD on KaunasPHP result
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Class Test | |
*/ | |
class Test extends PHPUnit_Framework_TestCase { | |
/** | |
* @var Calc | |
*/ | |
private $calc; | |
protected function setUp() | |
{ | |
$this->calc = new Calc(); | |
} | |
public function test_sums_2_numbers() | |
{ | |
$this->assertSame(2, $this->calc->calculate('1 + 1')); | |
} | |
public function test_makes_minus_on_2_numbers() | |
{ | |
$this->assertSame(1, $this->calc->calculate('2 - 1')); | |
} | |
public function test_calc_can_multiply() | |
{ | |
$this->assertEquals(6, $this->calc->calculate('2 * 3')); | |
} | |
public function test_multiple_operands() | |
{ | |
$this->assertSame(2, $this->calc->calculate('2 + 2 - 2')); | |
} | |
public function test_operator_position() | |
{ | |
$this->assertSame(6, $this->calc->calculate('2 + 2 * 2')); | |
} | |
} | |
/** | |
* Class Calc | |
*/ | |
class Calc | |
{ | |
/** | |
* @param $string | |
* @return mixed | |
*/ | |
public function calculate($string) | |
{ | |
$result = eval("return $string;"); | |
return $result; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment