Created
September 14, 2012 10:18
-
-
Save shoyan/3721179 to your computer and use it in GitHub Desktop.
sample is simple test with php4
This file contains hidden or 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('simpletest/autorun.php'); | |
require_once('Calc.php'); | |
class TestOfCalc extends UnitTestCase { | |
function testCalcAdd() { | |
$calc = new Calc(); | |
// 1 + 1 = 2 | |
$this->assertEqual($calc->add(1,1), 2); | |
// -1 + 1 = 0 | |
$this->assertEqual($calc->add(-1,1), 0); | |
// 0 + 0 = 0 | |
$this->assertEqual($calc->add(0,0), 0); | |
// -1 + -1 = -2 | |
$this->assertEqual($calc->add(-1,-1), -2); | |
// 数字以外はエラーを出力 | |
$this->expectError(); | |
$calc->add('a', 1); | |
$this->expectError(); | |
$calc->add('', 1); | |
} | |
} | |
/** | |
* Calc Class | |
* varsion PHP4 | |
*/ | |
class Calc{ | |
function add($a, $b) { | |
if (!is_int($a) || !is_int($b)) { | |
trigger_error('argument is invalid'); | |
} | |
return $a + $b; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment