Skip to content

Commit db502ce

Browse files
author
MarkBaker
committed
Additional unit tests
1 parent 07339c6 commit db502ce

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

src/PhpSpreadsheet/Calculation/MathTrig.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,9 @@ public static function FLOORPRECISE($number, $significance = 1)
301301
* @see MathTrig\IntClass::evaluate()
302302
* Use the evaluate() method in the MathTrig\IntClass class instead
303303
*
304-
* @param float $number Number to cast to an integer
304+
* @param array|float $number Number to cast to an integer
305305
*
306-
* @return int|string Integer value, or a string containing an error
306+
* @return array|int|string Integer value, or a string containing an error
307307
*/
308308
public static function INT($number)
309309
{

src/PhpSpreadsheet/Calculation/MathTrig/IntClass.php

+11-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
44

5+
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
56
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
67

78
class IntClass
89
{
10+
use ArrayEnabled;
11+
912
/**
1013
* INT.
1114
*
@@ -14,12 +17,18 @@ class IntClass
1417
* Excel Function:
1518
* INT(number)
1619
*
17-
* @param float $number Number to cast to an integer
20+
* @param array|float $number Number to cast to an integer, or can be an array of numbers
1821
*
19-
* @return int|string Integer value, or a string containing an error
22+
* @return array|string Integer value, or a string containing an error
23+
* If an array of numbers is passed as the argument, then the returned result will also be an array
24+
* with the same dimensions
2025
*/
2126
public static function evaluate($number)
2227
{
28+
if (is_array($number)) {
29+
return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $number);
30+
}
31+
2332
try {
2433
$number = Helpers::validateNumericNullBool($number);
2534
} catch (Exception $e) {

tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/IntTest.php

+23
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
44

5+
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
6+
57
class IntTest extends AllSetupTeardown
68
{
79
/**
@@ -27,4 +29,25 @@ public function providerINT(): array
2729
{
2830
return require 'tests/data/Calculation/MathTrig/INT.php';
2931
}
32+
33+
/**
34+
* @dataProvider providerIntArray
35+
*/
36+
public function testIntArray(array $expectedResult, string $array): void
37+
{
38+
$calculation = Calculation::getInstance();
39+
40+
$formula = "=INT({$array})";
41+
$result = $calculation->_calculateFormulaValue($formula);
42+
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
43+
}
44+
45+
public function providerIntArray(): array
46+
{
47+
return [
48+
'row vector' => [[[-2, 0, 0]], '{-1.5, 0, 0.3}'],
49+
'column vector' => [[[-2], [0], [0]], '{-1.5; 0; 0.3}'],
50+
'matrix' => [[[-2, 0], [0, 12]], '{-1.5, 0; 0.3, 12.5}'],
51+
];
52+
}
3053
}

0 commit comments

Comments
 (0)