This repository has been archived on 2020-06-07. You can view files and clone it, but cannot push or open issues or pull requests.
php-armadillo/tests/015-arithmetic-operators.phpt

48 lines
1.2 KiB
PHP

--TEST--
Test for operator overloading of arithmetic operations.
--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';
$mat = Arma\IMat::init(2, 2, Arma\Fill::RANDN);
$mat1 = Arma\IMat::init(2, 2, Arma\Fill::RANDN);
$mat1->forEach(function (Arma\MapVal $elem) {
if ($elem->val() == 0) {
$elem->setTo(7);
}
});
batch_assert_mat('operator overloading of arithmetic operations',
[$mat->add($mat1), $mat + $mat1],
[$mat->add(1), $mat + 1],
[$mat->sub($mat1), $mat - $mat1],
[$mat->sub(2), $mat - 2],
[$mat->neg(), -$mat],
[$mat->mul($mat1), $mat * $mat1],
[$mat->mul(2), $mat * 2],
[$mat->dotMul($mat1), $mat % $mat1],
[$mat->div($mat1), $mat / $mat1],
[$mat->div(2), $mat / 2]
);
$mat2 = $mat->div($mat1);
$mat3 = $mat1->add($mat2);
$mat4 = $mat2->mul($mat3);
$mat5 = $mat3->sub($mat4);
$mat1 -= $mat *= $mat1 += $mat /= $mat1;
batch_assert_mat('operator overloading of arithmetic operations', [$mat5, $mat1]);
?>
--EXPECT--