update tests
This commit is contained in:
parent
5a106c97db
commit
56fb79709e
|
@ -0,0 +1,49 @@
|
|||
--TEST--
|
||||
Test save/load with HDF5 format for `Arma\Mat`.
|
||||
--SKIPIF--
|
||||
<?php
|
||||
require_once 'includes/loaded.php';
|
||||
if (is_php_arma_loaded()) {
|
||||
supports_hdf5();
|
||||
}
|
||||
?>
|
||||
--ENV--
|
||||
TMP_FILE=/tmp/php_arma_test.tmp
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require_once 'includes/assert.php';
|
||||
|
||||
$file_name = getenv('TMP_FILE');
|
||||
|
||||
$hdf5_options = [
|
||||
'file_name' => $file_name,
|
||||
'dataset_name' => 'tmp_dataset',
|
||||
'options' => Arma\HDF5Opts::TRANS
|
||||
];
|
||||
|
||||
$mat = Arma\IMat::init(3, 3, Arma\Fill::RANDN);
|
||||
batch_assert('saving with HDF5 format',
|
||||
[true, $mat->save($hdf5_options, Arma\FileType::HDF5_BINARY)]
|
||||
);
|
||||
|
||||
$mat1 = Arma\IMat::init();
|
||||
batch_assert('loading with HDF5 format',
|
||||
[true, $mat1->load($hdf5_options, Arma\FileType::HDF5_BINARY)]
|
||||
);
|
||||
|
||||
$eq_mat = $mat->equals($mat1);
|
||||
batch_assert('loading with HDF5 format',
|
||||
[1, $eq_mat->min()],
|
||||
[1, $eq_mat->max()]
|
||||
);
|
||||
|
||||
?>
|
||||
--CLEAN--
|
||||
<?php
|
||||
$file_name = getenv('TMP_FILE');
|
||||
if (file_exists($file_name)) {
|
||||
unlink($file_name);
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
|
@ -0,0 +1,34 @@
|
|||
--TEST--
|
||||
Test operator overloading for comparisons.
|
||||
--SKIPIF--
|
||||
<?php
|
||||
require_once 'includes/loaded.php';
|
||||
require_once 'includes/supports.php';
|
||||
if (is_php_arma_loaded()) {
|
||||
supports_operator_overloading();
|
||||
}
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require_once 'includes/assert.php';
|
||||
|
||||
$mat0 = Arma\DMat::init(3, 3, Arma\Fill::RANDU);
|
||||
$mat1 = Arma\DMat::init(3, 3, Arma\Fill::RANDU);
|
||||
|
||||
$comp = function ($expected, $got) {
|
||||
$compare_result = $expected->equals($got);
|
||||
return $compare_result->max() == 1 && $compare_result->min() == 1;
|
||||
};
|
||||
|
||||
batch_assert_ex('operator overloading for comparisons', $comp,
|
||||
[$mat0->equals($mat1), $mat0 == $mat1],
|
||||
[$mat0->notEquals($mat1), $mat0 != $mat1],
|
||||
[$mat0->smallerThan($mat1), $mat0 < $mat1],
|
||||
[$mat0->greaterThan($mat1), $mat0 > $mat1],
|
||||
[$mat0->notSmallerThan($mat1), $mat0 >= $mat1],
|
||||
[$mat0->notGreaterThan($mat1), $mat0 <= $mat1]
|
||||
);
|
||||
|
||||
?>
|
||||
--EXPECT--
|
|
@ -1,16 +1,19 @@
|
|||
<?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($test, ...$cases) {
|
||||
function batch_assert_ex($test, $comp, ...$cases) {
|
||||
foreach ($cases as $case) {
|
||||
[$expected, $got] = $case;
|
||||
if ($expected == $got) {
|
||||
if ($comp($expected, $got)) {
|
||||
continue;
|
||||
}
|
||||
echo "Test for $test failed.\n";
|
||||
|
@ -22,3 +25,16 @@ function batch_assert($test, ...$cases) {
|
|||
}
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -1,14 +1,34 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Check whether the current php-armadillo build supports certain feature.
|
||||
*
|
||||
* @param bool $feature
|
||||
* @param string $msg
|
||||
* @return bool
|
||||
*/
|
||||
function arma_supports($feature, $msg) {
|
||||
if (!$feature) {
|
||||
echo "skip $msg is not supported.";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether operator overloading is supported.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function supports_operator_overloading() {
|
||||
if (!Arma\Features::OPERATORS) {
|
||||
echo 'skip operator overloading is not supported.';
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return arma_supports(Arma\Features::OPERATORS, 'operator overloading');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether HDF5 data format is supported.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function supports_hdf5() {
|
||||
return arma_supports(Arma\Features::HDF5, 'HDF5 data format');
|
||||
}
|
||||
|
|
Reference in New Issue