Skip to content

Instantly share code, notes, and snippets.

@shoyan
Created September 14, 2012 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shoyan/3721179 to your computer and use it in GitHub Desktop.
Save shoyan/3721179 to your computer and use it in GitHub Desktop.
sample is simple test with php4
<?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