Created
July 18, 2010 04:47
-
-
Save yuya-takeyama/480133 to your computer and use it in GitHub Desktop.
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 Calc | |
{ | |
public function add($a, $b, $c = NULL) | |
{ | |
if (isset($c)) { | |
return $a + $b + $c; | |
} else { | |
return $a + $b; | |
} | |
} | |
} |
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 Calc | |
{ | |
public function add() | |
{ | |
$num = 0; | |
$cnt = func_num_args(); | |
for ($i = 0; $i < $cnt; $i++) { | |
$num += func_get_arg($i); | |
} | |
return $num; | |
} | |
} |
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 | |
require_once 'PHPUnit/Framework.php'; | |
require_once './Calc.php'; | |
class CalcTest extends PHPUnit_Framework_TestCase | |
{ | |
public function testAdd() | |
{ | |
$calc = new Calc; | |
$this->assertEquals(2, $calc->add(1, 1)); | |
} | |
public function testAddThreeNumbers() | |
{ | |
$calc = new Calc; | |
$this->assertEquals(3, $calc->add(1, 1, 1)); | |
} | |
} |
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 | |
require_once 'PHPUnit/Framework.php'; | |
require_once './Calc.php'; | |
class CalcTest extends PHPUnit_Framework_TestCase | |
{ | |
protected $calc; | |
public function setUp() | |
{ | |
$this->calc = new Calc; | |
} | |
public function testAdd() | |
{ | |
$this->assertEquals(2, $this->calc->add(1, 1)); | |
} | |
public function testAddThreeNumbers() | |
{ | |
$this->assertEquals(3, $this->calc->add(1, 1, 1)); | |
} | |
} |
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 | |
require_once 'PHPUnit/Framework.php'; | |
require_once './Calc.php'; | |
class CalcTest extends PHPUnit_Framework_TestCase | |
{ | |
protected $calc; | |
public function setUp() | |
{ | |
$this->calc = new Calc; | |
} | |
public function testAdd() | |
{ | |
$this->assertEquals(2, $this->calc->add(1, 1)); | |
} | |
public function testAddThreeNumbers() | |
{ | |
$this->assertEquals(3, $this->calc->add(1, 1, 1)); | |
} | |
public function testAddTenNumbers() | |
{ | |
$this->assertEquals(55, $this->calc->add(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment