aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/MathTest.php16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/MathTest.php b/tests/MathTest.php
index c39eec7..382d67d 100644
--- a/tests/MathTest.php
+++ b/tests/MathTest.php
@@ -305,6 +305,22 @@ class MathTest extends TestCase
$this->assertEquals(100, $calculator->execute('10 ^ 2'));
}
+ public function testArrays() : void
+ {
+ $calculator = new MathExecutor();
+ $this->assertEquals([1, 5, 2], $calculator->execute('array(1, 5, 2)'));
+ $this->assertEquals([1, 5, 2], $calculator->execute('[1, 5, 2]'));
+ $this->assertEquals(\max([1, 5, 2]), $calculator->execute('max([1, 5, 2])'));
+ $this->assertEquals(\max([1, 5, 2]), $calculator->execute('max(array(1, 5, 2))'));
+ $calculator->addFunction('arr_with_max_elements', static function($arg1, ...$args) {
+ $args = \is_array($arg1) ? $arg1 : [$arg1, ...$args];
+ \usort($args, static fn($arr1, $arr2) => \count($arr2) <=> \count($arr1));
+
+ return $args[0];
+ });
+ $this->assertEquals([3, 3, 3], $calculator->execute('arr_with_max_elements([[1],array(2,2),[3,3,3]])'));
+ }
+
public function testFunctionParameterOrder() : void
{
$calculator = new MathExecutor();