Codility demo test (PHP)
<?php | |
function equi($A) { | |
$lower_elements_sum = 0; | |
$higher_elements_sum = array_sum($A); | |
for ($i = 0, $cnt = count($A); $i < $cnt; $i++) { | |
if (isset($A[$i - 1])) { | |
$lower_elements_sum += $A[$i - 1]; | |
} | |
$higher_elements_sum -= $A[$i]; | |
if ($lower_elements_sum == $higher_elements_sum) { | |
return $i; | |
} | |
} | |
return -1; | |
} | |
class EquiTest extends PHPUnit_Framework_TestCase { | |
/** | |
* @dataProvider provider | |
*/ | |
public function testEqui($A, $acceptable_results) { | |
$this->assertTrue(in_array(equi($A), $acceptable_results)); | |
} | |
public function provider() { | |
return array( | |
array(array(-7, 1, 5, 2, -4, 3, 0), array(3, 6)), | |
array(array(3, 2, 1, -6, 0), array(4)), | |
array(array(0, 3, 2, 1, -6), array(0)), | |
array(array(1, 2, 3, 4, 5, 6), array(-1)) | |
); | |
} | |
} |
This comment has been minimized.
This comment has been minimized.
You need to have PHPUnit installed. https://stackoverflow.com/questions/6065730/why-fatal-error-class-phpunit-framework-testcase-not-found-in Also, since phpunit ver 6, it should be \PHPUnit\Framework\TestCase |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
"Fatal error: Class 'PHPUnit_Framework_TestCase' not found in C:\xampp\htdocs\array\index.php on line 18"
How to define PHPUnit_Framework_TestCase ?