41 lines
922 B
PHP
41 lines
922 B
PHP
<?php
|
|
|
|
/**
|
|
* Batch assert for one or more cases with the given comparator.
|
|
*
|
|
* Print message if test fail.
|
|
*
|
|
* @param string $test
|
|
* @param callable $comp
|
|
* @param array $cases
|
|
* @return bool
|
|
*/
|
|
function batch_assert_ex($test, $comp, ...$cases) {
|
|
foreach ($cases as $case) {
|
|
[$expected, $got] = $case;
|
|
if ($comp($expected, $got)) {
|
|
continue;
|
|
}
|
|
echo "Test for $test failed.\n";
|
|
$expected = var_export($expected, true);
|
|
$got = var_export($got, true);
|
|
echo "Expected:\n$expected\n";
|
|
echo "Got:\n$got\n";
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Batch assert with default comparator.
|
|
*
|
|
* @param string $test
|
|
* @param array $cases
|
|
* @return bool
|
|
*/
|
|
function batch_assert($test, ...$cases) {
|
|
return batch_assert_ex($test, function ($expected, $got) {
|
|
return $expected == $got;
|
|
}, ...$cases);
|
|
}
|