diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 4142c995..7a4229e9 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -340,16 +340,6 @@ parameters: count: 1 path: src/PhpSpreadsheet/Calculation/Engine/Logger.php - - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Engineering\\:\\:BITLSHIFT\\(\\) should return int\\|string but returns float\\|int\\|string\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/Engineering.php - - - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Engineering\\:\\:BITRSHIFT\\(\\) should return int\\|string but returns float\\|int\\|string\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/Engineering.php - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Engineering\\\\BesselJ\\:\\:besselj2a\\(\\) has no return type specified\\.$#" count: 1 diff --git a/src/PhpSpreadsheet/Calculation/Engineering.php b/src/PhpSpreadsheet/Calculation/Engineering.php index a70ddac5..2103140e 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering.php +++ b/src/PhpSpreadsheet/Calculation/Engineering.php @@ -61,7 +61,7 @@ class Engineering * If $ord is nonnumeric, BESSELI returns the #VALUE! error value. * If $ord < 0, BESSELI returns the #NUM! error value. * - * @return float|string Result, or a string containing an error + * @return array|float|string Result, or a string containing an error */ public static function BESSELI($x, $ord) { @@ -86,7 +86,7 @@ class Engineering * If $ord is nonnumeric, BESSELJ returns the #VALUE! error value. * If $ord < 0, BESSELJ returns the #NUM! error value. * - * @return float|string Result, or a string containing an error + * @return array|float|string Result, or a string containing an error */ public static function BESSELJ($x, $ord) { @@ -112,7 +112,7 @@ class Engineering * If $ord is nonnumeric, BESSELK returns the #VALUE! error value. * If $ord < 0, BESSELK returns the #NUM! error value. * - * @return float|string Result, or a string containing an error + * @return array|float|string Result, or a string containing an error */ public static function BESSELK($x, $ord) { @@ -137,7 +137,7 @@ class Engineering * If $ord is nonnumeric, BESSELY returns the #VALUE! error value. * If $ord < 0, BESSELY returns the #NUM! error value. * - * @return float|string Result, or a string containing an error + * @return array|float|string Result, or a string containing an error */ public static function BESSELY($x, $ord) { @@ -163,7 +163,7 @@ class Engineering * If number is not a valid binary number, or if number contains more than * 10 characters (10 bits), BIN2DEC returns the #NUM! error value. * - * @return string + * @return array|string */ public static function BINTODEC($x) { @@ -195,7 +195,7 @@ class Engineering * If places is nonnumeric, BIN2HEX returns the #VALUE! error value. * If places is negative, BIN2HEX returns the #NUM! error value. * - * @return string + * @return array|string */ public static function BINTOHEX($x, $places = null) { @@ -227,7 +227,7 @@ class Engineering * If places is nonnumeric, BIN2OCT returns the #VALUE! error value. * If places is negative, BIN2OCT returns the #NUM! error value. * - * @return string + * @return array|string */ public static function BINTOOCT($x, $places = null) { @@ -263,7 +263,7 @@ class Engineering * If places is nonnumeric, DEC2BIN returns the #VALUE! error value. * If places is zero or negative, DEC2BIN returns the #NUM! error value. * - * @return string + * @return array|string */ public static function DECTOBIN($x, $places = null) { @@ -299,7 +299,7 @@ class Engineering * If places is nonnumeric, DEC2HEX returns the #VALUE! error value. * If places is zero or negative, DEC2HEX returns the #NUM! error value. * - * @return string + * @return array|string */ public static function DECTOHEX($x, $places = null) { @@ -335,7 +335,7 @@ class Engineering * If places is nonnumeric, DEC2OCT returns the #VALUE! error value. * If places is zero or negative, DEC2OCT returns the #NUM! error value. * - * @return string + * @return array|string */ public static function DECTOOCT($x, $places = null) { @@ -371,7 +371,7 @@ class Engineering * If places is nonnumeric, HEX2BIN returns the #VALUE! error value. * If places is negative, HEX2BIN returns the #NUM! error value. * - * @return string + * @return array|string */ public static function HEXTOBIN($x, $places = null) { @@ -398,7 +398,7 @@ class Engineering * If number is not a valid hexadecimal number, HEX2DEC returns the * #NUM! error value. * - * @return string + * @return array|string */ public static function HEXTODEC($x) { @@ -438,7 +438,7 @@ class Engineering * value. * If places is negative, HEX2OCT returns the #NUM! error value. * - * @return string + * @return array|string */ public static function HEXTOOCT($x, $places = null) { @@ -480,7 +480,7 @@ class Engineering * If places is negative, OCT2BIN returns the #NUM! error * value. * - * @return string + * @return array|string */ public static function OCTTOBIN($x, $places = null) { @@ -507,7 +507,7 @@ class Engineering * If number is not a valid octal number, OCT2DEC returns the * #NUM! error value. * - * @return string + * @return array|string */ public static function OCTTODEC($x) { @@ -544,7 +544,7 @@ class Engineering * If places is nonnumeric, OCT2HEX returns the #VALUE! error value. * If places is negative, OCT2HEX returns the #NUM! error value. * - * @return string + * @return array|string */ public static function OCTTOHEX($x, $places = null) { @@ -1123,7 +1123,7 @@ class Engineering * @param float $a the first number * @param float $b The second number. If omitted, b is assumed to be zero. * - * @return int|string (string in the event of an error) + * @return array|int|string (string in the event of an error) */ public static function DELTA($a, $b = 0) { @@ -1147,7 +1147,7 @@ class Engineering * @param float $number the value to test against step * @param float $step The threshold value. If you omit a value for step, GESTEP uses zero. * - * @return int|string (string in the event of an error) + * @return array|int|string (string in the event of an error) */ public static function GESTEP($number, $step = 0) { @@ -1169,7 +1169,7 @@ class Engineering * @param int $number1 * @param int $number2 * - * @return int|string + * @return array|int|string */ public static function BITAND($number1, $number2) { @@ -1191,7 +1191,7 @@ class Engineering * @param int $number1 * @param int $number2 * - * @return int|string + * @return array|int|string */ public static function BITOR($number1, $number2) { @@ -1213,7 +1213,7 @@ class Engineering * @param int $number1 * @param int $number2 * - * @return int|string + * @return array|int|string */ public static function BITXOR($number1, $number2) { @@ -1235,7 +1235,7 @@ class Engineering * @param int $number * @param int $shiftAmount * - * @return int|string + * @return array|float|int|string */ public static function BITLSHIFT($number, $shiftAmount) { @@ -1257,7 +1257,7 @@ class Engineering * @param int $number * @param int $shiftAmount * - * @return int|string + * @return array|float|int|string */ public static function BITRSHIFT($number, $shiftAmount) { @@ -1285,7 +1285,7 @@ class Engineering * @param float $upper upper bound for integrating ERF. * If omitted, ERF integrates between zero and lower_limit * - * @return float|string + * @return array|float|string */ public static function ERF($lower, $upper = null) { @@ -1306,7 +1306,7 @@ class Engineering * * @param float $limit bound for integrating ERF * - * @return float|string + * @return array|float|string */ public static function ERFPRECISE($limit) { @@ -1332,7 +1332,7 @@ class Engineering * * @param float $x The lower bound for integrating ERFC * - * @return float|string + * @return array|float|string */ public static function ERFC($x) { @@ -1437,7 +1437,7 @@ class Engineering * @param string $fromUOM the units for value * @param string $toUOM the units for the result * - * @return float|string + * @return array|float|string */ public static function CONVERTUOM($value, $fromUOM, $toUOM) { diff --git a/src/PhpSpreadsheet/Calculation/Engineering/BesselI.php b/src/PhpSpreadsheet/Calculation/Engineering/BesselI.php index ea2577cd..24145aa9 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/BesselI.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/BesselI.php @@ -2,11 +2,14 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering; +use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; class BesselI { + use ArrayEnabled; + /** * BESSELI. * @@ -21,17 +24,22 @@ class BesselI * * @param mixed $x A float value at which to evaluate the function. * If x is nonnumeric, BESSELI returns the #VALUE! error value. + * Or can be an array of values * @param mixed $ord The integer order of the Bessel function. * If ord is not an integer, it is truncated. * If $ord is nonnumeric, BESSELI returns the #VALUE! error value. * If $ord < 0, BESSELI returns the #NUM! error value. + * Or can be an array of values * - * @return float|string Result, or a string containing an error + * @return array|float|string Result, or a string containing an error + * If an array of numbers is passed as an argument, then the returned result will also be an array + * with the same dimensions */ public static function BESSELI($x, $ord) { - $x = Functions::flattenSingleValue($x); - $ord = Functions::flattenSingleValue($ord); + if (is_array($x) || is_array($ord)) { + return self::evaluateArrayArguments([self::class, __FUNCTION__], $x, $ord); + } try { $x = EngineeringValidations::validateFloat($x); diff --git a/src/PhpSpreadsheet/Calculation/Engineering/BesselJ.php b/src/PhpSpreadsheet/Calculation/Engineering/BesselJ.php index 7ea45a74..4b6a79e9 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/BesselJ.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/BesselJ.php @@ -2,11 +2,14 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering; +use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; class BesselJ { + use ArrayEnabled; + /** * BESSELJ. * @@ -20,17 +23,22 @@ class BesselJ * * @param mixed $x A float value at which to evaluate the function. * If x is nonnumeric, BESSELJ returns the #VALUE! error value. + * Or can be an array of values * @param mixed $ord The integer order of the Bessel function. * If ord is not an integer, it is truncated. * If $ord is nonnumeric, BESSELJ returns the #VALUE! error value. * If $ord < 0, BESSELJ returns the #NUM! error value. + * Or can be an array of values * - * @return float|string Result, or a string containing an error + * @return array|float|string Result, or a string containing an error + * If an array of numbers is passed as an argument, then the returned result will also be an array + * with the same dimensions */ public static function BESSELJ($x, $ord) { - $x = Functions::flattenSingleValue($x); - $ord = Functions::flattenSingleValue($ord); + if (is_array($x) || is_array($ord)) { + return self::evaluateArrayArguments([self::class, __FUNCTION__], $x, $ord); + } try { $x = EngineeringValidations::validateFloat($x); diff --git a/src/PhpSpreadsheet/Calculation/Engineering/BesselK.php b/src/PhpSpreadsheet/Calculation/Engineering/BesselK.php index 8facdffc..977eadf8 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/BesselK.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/BesselK.php @@ -2,11 +2,14 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering; +use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; class BesselK { + use ArrayEnabled; + /** * BESSELK. * @@ -18,17 +21,22 @@ class BesselK * * @param mixed $x A float value at which to evaluate the function. * If x is nonnumeric, BESSELK returns the #VALUE! error value. + * Or can be an array of values * @param mixed $ord The integer order of the Bessel function. * If ord is not an integer, it is truncated. * If $ord is nonnumeric, BESSELK returns the #VALUE! error value. * If $ord < 0, BESSELKI returns the #NUM! error value. + * Or can be an array of values * - * @return float|string Result, or a string containing an error + * @return array|float|string Result, or a string containing an error + * If an array of numbers is passed as an argument, then the returned result will also be an array + * with the same dimensions */ public static function BESSELK($x, $ord) { - $x = Functions::flattenSingleValue($x); - $ord = Functions::flattenSingleValue($ord); + if (is_array($x) || is_array($ord)) { + return self::evaluateArrayArguments([self::class, __FUNCTION__], $x, $ord); + } try { $x = EngineeringValidations::validateFloat($x); diff --git a/src/PhpSpreadsheet/Calculation/Engineering/BesselY.php b/src/PhpSpreadsheet/Calculation/Engineering/BesselY.php index 7f387497..2b373bd2 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/BesselY.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/BesselY.php @@ -2,11 +2,14 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering; +use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; class BesselY { + use ArrayEnabled; + /** * BESSELY. * @@ -17,17 +20,22 @@ class BesselY * * @param mixed $x A float value at which to evaluate the function. * If x is nonnumeric, BESSELY returns the #VALUE! error value. + * Or can be an array of values * @param mixed $ord The integer order of the Bessel function. * If ord is not an integer, it is truncated. * If $ord is nonnumeric, BESSELY returns the #VALUE! error value. * If $ord < 0, BESSELY returns the #NUM! error value. + * Or can be an array of values * - * @return float|string Result, or a string containing an error + * @return array|float|string Result, or a string containing an error + * If an array of numbers is passed as an argument, then the returned result will also be an array + * with the same dimensions */ public static function BESSELY($x, $ord) { - $x = Functions::flattenSingleValue($x); - $ord = Functions::flattenSingleValue($ord); + if (is_array($x) || is_array($ord)) { + return self::evaluateArrayArguments([self::class, __FUNCTION__], $x, $ord); + } try { $x = EngineeringValidations::validateFloat($x); diff --git a/src/PhpSpreadsheet/Calculation/Engineering/BitWise.php b/src/PhpSpreadsheet/Calculation/Engineering/BitWise.php index 9958f054..3041a41c 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/BitWise.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/BitWise.php @@ -2,11 +2,14 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering; +use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; class BitWise { + use ArrayEnabled; + const SPLIT_DIVISOR = 2 ** 24; /** @@ -27,13 +30,21 @@ class BitWise * Excel Function: * BITAND(number1, number2) * - * @param int $number1 - * @param int $number2 + * @param array|int $number1 + * Or can be an array of values + * @param array|int $number2 + * Or can be an array of values * - * @return int|string + * @return array|int|string + * If an array of numbers is passed as an argument, then the returned result will also be an array + * with the same dimensions */ public static function BITAND($number1, $number2) { + if (is_array($number1) || is_array($number2)) { + return self::evaluateArrayArguments([self::class, __FUNCTION__], $number1, $number2); + } + try { $number1 = self::validateBitwiseArgument($number1); $number2 = self::validateBitwiseArgument($number2); @@ -54,13 +65,21 @@ class BitWise * Excel Function: * BITOR(number1, number2) * - * @param int $number1 - * @param int $number2 + * @param array|int $number1 + * Or can be an array of values + * @param array|int $number2 + * Or can be an array of values * - * @return int|string + * @return array|int|string + * If an array of numbers is passed as an argument, then the returned result will also be an array + * with the same dimensions */ public static function BITOR($number1, $number2) { + if (is_array($number1) || is_array($number2)) { + return self::evaluateArrayArguments([self::class, __FUNCTION__], $number1, $number2); + } + try { $number1 = self::validateBitwiseArgument($number1); $number2 = self::validateBitwiseArgument($number2); @@ -82,13 +101,21 @@ class BitWise * Excel Function: * BITXOR(number1, number2) * - * @param int $number1 - * @param int $number2 + * @param array|int $number1 + * Or can be an array of values + * @param array|int $number2 + * Or can be an array of values * - * @return int|string + * @return array|int|string + * If an array of numbers is passed as an argument, then the returned result will also be an array + * with the same dimensions */ public static function BITXOR($number1, $number2) { + if (is_array($number1) || is_array($number2)) { + return self::evaluateArrayArguments([self::class, __FUNCTION__], $number1, $number2); + } + try { $number1 = self::validateBitwiseArgument($number1); $number2 = self::validateBitwiseArgument($number2); @@ -110,13 +137,21 @@ class BitWise * Excel Function: * BITLSHIFT(number, shift_amount) * - * @param int $number - * @param int $shiftAmount + * @param array|int $number + * Or can be an array of values + * @param array|int $shiftAmount + * Or can be an array of values * - * @return float|int|string + * @return array|float|int|string + * If an array of numbers is passed as an argument, then the returned result will also be an array + * with the same dimensions */ public static function BITLSHIFT($number, $shiftAmount) { + if (is_array($number) || is_array($shiftAmount)) { + return self::evaluateArrayArguments([self::class, __FUNCTION__], $number, $shiftAmount); + } + try { $number = self::validateBitwiseArgument($number); $shiftAmount = self::validateShiftAmount($shiftAmount); @@ -140,13 +175,21 @@ class BitWise * Excel Function: * BITRSHIFT(number, shift_amount) * - * @param int $number - * @param int $shiftAmount + * @param array|int $number + * Or can be an array of values + * @param array|int $shiftAmount + * Or can be an array of values * - * @return float|int|string + * @return array|float|int|string + * If an array of numbers is passed as an argument, then the returned result will also be an array + * with the same dimensions */ public static function BITRSHIFT($number, $shiftAmount) { + if (is_array($number) || is_array($shiftAmount)) { + return self::evaluateArrayArguments([self::class, __FUNCTION__], $number, $shiftAmount); + } + try { $number = self::validateBitwiseArgument($number); $shiftAmount = self::validateShiftAmount($shiftAmount); @@ -171,7 +214,7 @@ class BitWise */ private static function validateBitwiseArgument($value) { - self::nullFalseTrueToNumber($value); + $value = self::nullFalseTrueToNumber($value); if (is_numeric($value)) { if ($value == floor($value)) { @@ -197,7 +240,7 @@ class BitWise */ private static function validateShiftAmount($value) { - self::nullFalseTrueToNumber($value); + $value = self::nullFalseTrueToNumber($value); if (is_numeric($value)) { if (abs($value) > 53) { @@ -214,14 +257,17 @@ class BitWise * Many functions accept null/false/true argument treated as 0/0/1. * * @param mixed $number + * + * @return mixed */ - public static function nullFalseTrueToNumber(&$number): void + private static function nullFalseTrueToNumber(&$number) { - $number = Functions::flattenSingleValue($number); if ($number === null) { $number = 0; } elseif (is_bool($number)) { $number = (int) $number; } + + return $number; } } diff --git a/src/PhpSpreadsheet/Calculation/Engineering/Compare.php b/src/PhpSpreadsheet/Calculation/Engineering/Compare.php index 0a634206..4d4bc07e 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/Compare.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/Compare.php @@ -2,11 +2,13 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering; +use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; class Compare { + use ArrayEnabled; + /** * DELTA. * @@ -18,15 +20,20 @@ class Compare * functions you calculate the count of equal pairs. This function is also known as the * Kronecker Delta function. * - * @param float $a the first number - * @param float $b The second number. If omitted, b is assumed to be zero. + * @param array|float $a the first number + * Or can be an array of values + * @param array|float $b The second number. If omitted, b is assumed to be zero. + * Or can be an array of values * - * @return int|string (string in the event of an error) + * @return array|int|string (string in the event of an error) + * If an array of numbers is passed as an argument, then the returned result will also be an array + * with the same dimensions */ - public static function DELTA($a, $b = 0) + public static function DELTA($a, $b = 0.0) { - $a = Functions::flattenSingleValue($a); - $b = Functions::flattenSingleValue($b); + if (is_array($a) || is_array($b)) { + return self::evaluateArrayArguments([self::class, __FUNCTION__], $a, $b); + } try { $a = EngineeringValidations::validateFloat($a); @@ -35,7 +42,7 @@ class Compare return $e->getMessage(); } - return (int) ($a == $b); + return (int) (abs($a - $b) < 1.0e-15); } /** @@ -48,15 +55,20 @@ class Compare * Use this function to filter a set of values. For example, by summing several GESTEP * functions you calculate the count of values that exceed a threshold. * - * @param float $number the value to test against step - * @param float $step The threshold value. If you omit a value for step, GESTEP uses zero. + * @param array|float $number the value to test against step + * Or can be an array of values + * @param array|float $step The threshold value. If you omit a value for step, GESTEP uses zero. + * Or can be an array of values * - * @return int|string (string in the event of an error) + * @return array|int|string (string in the event of an error) + * If an array of numbers is passed as an argument, then the returned result will also be an array + * with the same dimensions */ - public static function GESTEP($number, $step = 0) + public static function GESTEP($number, $step = 0.0) { - $number = Functions::flattenSingleValue($number); - $step = Functions::flattenSingleValue($step); + if (is_array($number) || is_array($step)) { + return self::evaluateArrayArguments([self::class, __FUNCTION__], $number, $step); + } try { $number = EngineeringValidations::validateFloat($number); diff --git a/src/PhpSpreadsheet/Calculation/Engineering/ConvertBase.php b/src/PhpSpreadsheet/Calculation/Engineering/ConvertBase.php index a095690d..4a741975 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/ConvertBase.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/ConvertBase.php @@ -2,11 +2,14 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering; +use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; -class ConvertBase +abstract class ConvertBase { + use ArrayEnabled; + protected static function validateValue($value): string { if (is_bool($value)) { diff --git a/src/PhpSpreadsheet/Calculation/Engineering/ConvertBinary.php b/src/PhpSpreadsheet/Calculation/Engineering/ConvertBinary.php index a662b78d..5f1be454 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/ConvertBinary.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/ConvertBinary.php @@ -15,17 +15,26 @@ class ConvertBinary extends ConvertBase * Excel Function: * BIN2DEC(x) * - * @param string $value The binary number (as a string) that you want to convert. The number + * @param array|string $value The binary number (as a string) that you want to convert. The number * cannot contain more than 10 characters (10 bits). The most significant * bit of number is the sign bit. The remaining 9 bits are magnitude bits. * Negative numbers are represented using two's-complement notation. * If number is not a valid binary number, or if number contains more than * 10 characters (10 bits), BIN2DEC returns the #NUM! error value. + * Or can be an array of values + * + * @return array|string Result, or an error + * If an array of numbers is passed as an argument, then the returned result will also be an array + * with the same dimensions */ - public static function toDecimal($value): string + public static function toDecimal($value) { + if (is_array($value)) { + return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $value); + } + try { - $value = self::validateValue(Functions::flattenSingleValue($value)); + $value = self::validateValue($value); $value = self::validateBinary($value); } catch (Exception $e) { return $e->getMessage(); @@ -49,25 +58,35 @@ class ConvertBinary extends ConvertBase * Excel Function: * BIN2HEX(x[,places]) * - * @param string $value The binary number (as a string) that you want to convert. The number + * @param array|string $value The binary number (as a string) that you want to convert. The number * cannot contain more than 10 characters (10 bits). The most significant * bit of number is the sign bit. The remaining 9 bits are magnitude bits. * Negative numbers are represented using two's-complement notation. * If number is not a valid binary number, or if number contains more than * 10 characters (10 bits), BIN2HEX returns the #NUM! error value. - * @param int $places The number of characters to use. If places is omitted, BIN2HEX uses the + * Or can be an array of values + * @param array|int $places The number of characters to use. If places is omitted, BIN2HEX uses the * minimum number of characters necessary. Places is useful for padding the * return value with leading 0s (zeros). * If places is not an integer, it is truncated. * If places is nonnumeric, BIN2HEX returns the #VALUE! error value. * If places is negative, BIN2HEX returns the #NUM! error value. + * Or can be an array of values + * + * @return array|string Result, or an error + * If an array of numbers is passed as an argument, then the returned result will also be an array + * with the same dimensions */ - public static function toHex($value, $places = null): string + public static function toHex($value, $places = null) { + if (is_array($value) || is_array($places)) { + return self::evaluateArrayArguments([self::class, __FUNCTION__], $value, $places); + } + try { - $value = self::validateValue(Functions::flattenSingleValue($value)); + $value = self::validateValue($value); $value = self::validateBinary($value); - $places = self::validatePlaces(Functions::flattenSingleValue($places)); + $places = self::validatePlaces($places); } catch (Exception $e) { return $e->getMessage(); } @@ -92,25 +111,35 @@ class ConvertBinary extends ConvertBase * Excel Function: * BIN2OCT(x[,places]) * - * @param string $value The binary number (as a string) that you want to convert. The number + * @param array|string $value The binary number (as a string) that you want to convert. The number * cannot contain more than 10 characters (10 bits). The most significant * bit of number is the sign bit. The remaining 9 bits are magnitude bits. * Negative numbers are represented using two's-complement notation. * If number is not a valid binary number, or if number contains more than * 10 characters (10 bits), BIN2OCT returns the #NUM! error value. - * @param int $places The number of characters to use. If places is omitted, BIN2OCT uses the + * Or can be an array of values + * @param array|int $places The number of characters to use. If places is omitted, BIN2OCT uses the * minimum number of characters necessary. Places is useful for padding the * return value with leading 0s (zeros). * If places is not an integer, it is truncated. * If places is nonnumeric, BIN2OCT returns the #VALUE! error value. * If places is negative, BIN2OCT returns the #NUM! error value. + * Or can be an array of values + * + * @return array|string Result, or an error + * If an array of numbers is passed as an argument, then the returned result will also be an array + * with the same dimensions */ - public static function toOctal($value, $places = null): string + public static function toOctal($value, $places = null) { + if (is_array($value) || is_array($places)) { + return self::evaluateArrayArguments([self::class, __FUNCTION__], $value, $places); + } + try { - $value = self::validateValue(Functions::flattenSingleValue($value)); + $value = self::validateValue($value); $value = self::validateBinary($value); - $places = self::validatePlaces(Functions::flattenSingleValue($places)); + $places = self::validatePlaces($places); } catch (Exception $e) { return $e->getMessage(); } diff --git a/src/PhpSpreadsheet/Calculation/Engineering/ConvertDecimal.php b/src/PhpSpreadsheet/Calculation/Engineering/ConvertDecimal.php index a34332fb..6a876786 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/ConvertDecimal.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/ConvertDecimal.php @@ -22,7 +22,7 @@ class ConvertDecimal extends ConvertBase * Excel Function: * DEC2BIN(x[,places]) * - * @param string $value The decimal integer you want to convert. If number is negative, + * @param array|string $value The decimal integer you want to convert. If number is negative, * valid place values are ignored and DEC2BIN returns a 10-character * (10-bit) binary number in which the most significant bit is the sign * bit. The remaining 9 bits are magnitude bits. Negative numbers are @@ -32,19 +32,29 @@ class ConvertDecimal extends ConvertBase * If number is nonnumeric, DEC2BIN returns the #VALUE! error value. * If DEC2BIN requires more than places characters, it returns the #NUM! * error value. - * @param int $places The number of characters to use. If places is omitted, DEC2BIN uses + * Or can be an array of values + * @param array|int $places The number of characters to use. If places is omitted, DEC2BIN uses * the minimum number of characters necessary. Places is useful for * padding the return value with leading 0s (zeros). * If places is not an integer, it is truncated. * If places is nonnumeric, DEC2BIN returns the #VALUE! error value. * If places is zero or negative, DEC2BIN returns the #NUM! error value. + * Or can be an array of values + * + * @return array|string Result, or an error + * If an array of numbers is passed as an argument, then the returned result will also be an array + * with the same dimensions */ - public static function toBinary($value, $places = null): string + public static function toBinary($value, $places = null) { + if (is_array($value) || is_array($places)) { + return self::evaluateArrayArguments([self::class, __FUNCTION__], $value, $places); + } + try { - $value = self::validateValue(Functions::flattenSingleValue($value)); + $value = self::validateValue($value); $value = self::validateDecimal($value); - $places = self::validatePlaces(Functions::flattenSingleValue($places)); + $places = self::validatePlaces($places); } catch (Exception $e) { return $e->getMessage(); } @@ -69,7 +79,7 @@ class ConvertDecimal extends ConvertBase * Excel Function: * DEC2HEX(x[,places]) * - * @param string $value The decimal integer you want to convert. If number is negative, + * @param array|string $value The decimal integer you want to convert. If number is negative, * places is ignored and DEC2HEX returns a 10-character (40-bit) * hexadecimal number in which the most significant bit is the sign * bit. The remaining 39 bits are magnitude bits. Negative numbers @@ -79,19 +89,29 @@ class ConvertDecimal extends ConvertBase * If number is nonnumeric, DEC2HEX returns the #VALUE! error value. * If DEC2HEX requires more than places characters, it returns the * #NUM! error value. - * @param int $places The number of characters to use. If places is omitted, DEC2HEX uses + * Or can be an array of values + * @param array|int $places The number of characters to use. If places is omitted, DEC2HEX uses * the minimum number of characters necessary. Places is useful for * padding the return value with leading 0s (zeros). * If places is not an integer, it is truncated. * If places is nonnumeric, DEC2HEX returns the #VALUE! error value. * If places is zero or negative, DEC2HEX returns the #NUM! error value. + * Or can be an array of values + * + * @return array|string Result, or an error + * If an array of numbers is passed as an argument, then the returned result will also be an array + * with the same dimensions */ - public static function toHex($value, $places = null): string + public static function toHex($value, $places = null) { + if (is_array($value) || is_array($places)) { + return self::evaluateArrayArguments([self::class, __FUNCTION__], $value, $places); + } + try { - $value = self::validateValue(Functions::flattenSingleValue($value)); + $value = self::validateValue($value); $value = self::validateDecimal($value); - $places = self::validatePlaces(Functions::flattenSingleValue($places)); + $places = self::validatePlaces($places); } catch (Exception $e) { return $e->getMessage(); } @@ -135,7 +155,7 @@ class ConvertDecimal extends ConvertBase * Excel Function: * DEC2OCT(x[,places]) * - * @param string $value The decimal integer you want to convert. If number is negative, + * @param array|string $value The decimal integer you want to convert. If number is negative, * places is ignored and DEC2OCT returns a 10-character (30-bit) * octal number in which the most significant bit is the sign bit. * The remaining 29 bits are magnitude bits. Negative numbers are @@ -145,19 +165,29 @@ class ConvertDecimal extends ConvertBase * If number is nonnumeric, DEC2OCT returns the #VALUE! error value. * If DEC2OCT requires more than places characters, it returns the * #NUM! error value. - * @param int $places The number of characters to use. If places is omitted, DEC2OCT uses + * Or can be an array of values + * @param array|int $places The number of characters to use. If places is omitted, DEC2OCT uses * the minimum number of characters necessary. Places is useful for * padding the return value with leading 0s (zeros). * If places is not an integer, it is truncated. * If places is nonnumeric, DEC2OCT returns the #VALUE! error value. * If places is zero or negative, DEC2OCT returns the #NUM! error value. + * Or can be an array of values + * + * @return array|string Result, or an error + * If an array of numbers is passed as an argument, then the returned result will also be an array + * with the same dimensions */ - public static function toOctal($value, $places = null): string + public static function toOctal($value, $places = null) { + if (is_array($value) || is_array($places)) { + return self::evaluateArrayArguments([self::class, __FUNCTION__], $value, $places); + } + try { - $value = self::validateValue(Functions::flattenSingleValue($value)); + $value = self::validateValue($value); $value = self::validateDecimal($value); - $places = self::validatePlaces(Functions::flattenSingleValue($places)); + $places = self::validatePlaces($places); } catch (Exception $e) { return $e->getMessage(); } diff --git a/src/PhpSpreadsheet/Calculation/Engineering/ConvertHex.php b/src/PhpSpreadsheet/Calculation/Engineering/ConvertHex.php index de1b0704..12c99521 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/ConvertHex.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/ConvertHex.php @@ -15,7 +15,7 @@ class ConvertHex extends ConvertBase * Excel Function: * HEX2BIN(x[,places]) * - * @param string $value The hexadecimal number you want to convert. + * @param array|string $value The hexadecimal number you want to convert. * Number cannot contain more than 10 characters. * The most significant bit of number is the sign bit (40th bit from the right). * The remaining 9 bits are magnitude bits. @@ -25,19 +25,29 @@ class ConvertHex extends ConvertBase * and if number is positive, it cannot be greater than 1FF. * If number is not a valid hexadecimal number, HEX2BIN returns the #NUM! error value. * If HEX2BIN requires more than places characters, it returns the #NUM! error value. - * @param int $places The number of characters to use. If places is omitted, + * Or can be an array of values + * @param array|int $places The number of characters to use. If places is omitted, * HEX2BIN uses the minimum number of characters necessary. Places * is useful for padding the return value with leading 0s (zeros). * If places is not an integer, it is truncated. * If places is nonnumeric, HEX2BIN returns the #VALUE! error value. * If places is negative, HEX2BIN returns the #NUM! error value. + * Or can be an array of values + * + * @return array|string Result, or an error + * If an array of numbers is passed as an argument, then the returned result will also be an array + * with the same dimensions */ - public static function toBinary($value, $places = null): string + public static function toBinary($value, $places = null) { + if (is_array($value) || is_array($places)) { + return self::evaluateArrayArguments([self::class, __FUNCTION__], $value, $places); + } + try { - $value = self::validateValue(Functions::flattenSingleValue($value)); + $value = self::validateValue($value); $value = self::validateHex($value); - $places = self::validatePlaces(Functions::flattenSingleValue($places)); + $places = self::validatePlaces($places); } catch (Exception $e) { return $e->getMessage(); } @@ -55,18 +65,27 @@ class ConvertHex extends ConvertBase * Excel Function: * HEX2DEC(x) * - * @param string $value The hexadecimal number you want to convert. This number cannot + * @param array|string $value The hexadecimal number you want to convert. This number cannot * contain more than 10 characters (40 bits). The most significant * bit of number is the sign bit. The remaining 39 bits are magnitude * bits. Negative numbers are represented using two's-complement * notation. * If number is not a valid hexadecimal number, HEX2DEC returns the * #NUM! error value. + * Or can be an array of values + * + * @return array|string Result, or an error + * If an array of numbers is passed as an argument, then the returned result will also be an array + * with the same dimensions */ - public static function toDecimal($value): string + public static function toDecimal($value) { + if (is_array($value)) { + return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $value); + } + try { - $value = self::validateValue(Functions::flattenSingleValue($value)); + $value = self::validateValue($value); $value = self::validateHex($value); } catch (Exception $e) { return $e->getMessage(); @@ -99,7 +118,7 @@ class ConvertHex extends ConvertBase * Excel Function: * HEX2OCT(x[,places]) * - * @param string $value The hexadecimal number you want to convert. Number cannot + * @param array|string $value The hexadecimal number you want to convert. Number cannot * contain more than 10 characters. The most significant bit of * number is the sign bit. The remaining 39 bits are magnitude * bits. Negative numbers are represented using two's-complement @@ -112,20 +131,30 @@ class ConvertHex extends ConvertBase * the #NUM! error value. * If HEX2OCT requires more than places characters, it returns * the #NUM! error value. - * @param int $places The number of characters to use. If places is omitted, HEX2OCT + * Or can be an array of values + * @param array|int $places The number of characters to use. If places is omitted, HEX2OCT * uses the minimum number of characters necessary. Places is * useful for padding the return value with leading 0s (zeros). * If places is not an integer, it is truncated. * If places is nonnumeric, HEX2OCT returns the #VALUE! error * value. * If places is negative, HEX2OCT returns the #NUM! error value. + * Or can be an array of values + * + * @return array|string Result, or an error + * If an array of numbers is passed as an argument, then the returned result will also be an array + * with the same dimensions */ - public static function toOctal($value, $places = null): string + public static function toOctal($value, $places = null) { + if (is_array($value) || is_array($places)) { + return self::evaluateArrayArguments([self::class, __FUNCTION__], $value, $places); + } + try { - $value = self::validateValue(Functions::flattenSingleValue($value)); + $value = self::validateValue($value); $value = self::validateHex($value); - $places = self::validatePlaces(Functions::flattenSingleValue($places)); + $places = self::validatePlaces($places); } catch (Exception $e) { return $e->getMessage(); } diff --git a/src/PhpSpreadsheet/Calculation/Engineering/ConvertOctal.php b/src/PhpSpreadsheet/Calculation/Engineering/ConvertOctal.php index 1181e2ee..3c3af5c1 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/ConvertOctal.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/ConvertOctal.php @@ -15,7 +15,7 @@ class ConvertOctal extends ConvertBase * Excel Function: * OCT2BIN(x[,places]) * - * @param string $value The octal number you want to convert. Number may not + * @param array|string $value The octal number you want to convert. Number may not * contain more than 10 characters. The most significant * bit of number is the sign bit. The remaining 29 bits * are magnitude bits. Negative numbers are represented @@ -28,7 +28,8 @@ class ConvertOctal extends ConvertBase * the #NUM! error value. * If OCT2BIN requires more than places characters, it * returns the #NUM! error value. - * @param int $places The number of characters to use. If places is omitted, + * Or can be an array of values + * @param array|int $places The number of characters to use. If places is omitted, * OCT2BIN uses the minimum number of characters necessary. * Places is useful for padding the return value with * leading 0s (zeros). @@ -37,13 +38,22 @@ class ConvertOctal extends ConvertBase * error value. * If places is negative, OCT2BIN returns the #NUM! error * value. + * Or can be an array of values + * + * @return array|string Result, or an error + * If an array of numbers is passed as an argument, then the returned result will also be an array + * with the same dimensions */ - public static function toBinary($value, $places = null): string + public static function toBinary($value, $places = null) { + if (is_array($value) || is_array($places)) { + return self::evaluateArrayArguments([self::class, __FUNCTION__], $value, $places); + } + try { - $value = self::validateValue(Functions::flattenSingleValue($value)); + $value = self::validateValue($value); $value = self::validateOctal($value); - $places = self::validatePlaces(Functions::flattenSingleValue($places)); + $places = self::validatePlaces($places); } catch (Exception $e) { return $e->getMessage(); } @@ -59,18 +69,27 @@ class ConvertOctal extends ConvertBase * Excel Function: * OCT2DEC(x) * - * @param string $value The octal number you want to convert. Number may not contain + * @param array|string $value The octal number you want to convert. Number may not contain * more than 10 octal characters (30 bits). The most significant * bit of number is the sign bit. The remaining 29 bits are * magnitude bits. Negative numbers are represented using * two's-complement notation. * If number is not a valid octal number, OCT2DEC returns the * #NUM! error value. + * Or can be an array of values + * + * @return array|string Result, or an error + * If an array of numbers is passed as an argument, then the returned result will also be an array + * with the same dimensions */ - public static function toDecimal($value): string + public static function toDecimal($value) { + if (is_array($value)) { + return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $value); + } + try { - $value = self::validateValue(Functions::flattenSingleValue($value)); + $value = self::validateValue($value); $value = self::validateOctal($value); } catch (Exception $e) { return $e->getMessage(); @@ -99,7 +118,7 @@ class ConvertOctal extends ConvertBase * Excel Function: * OCT2HEX(x[,places]) * - * @param string $value The octal number you want to convert. Number may not contain + * @param array|string $value The octal number you want to convert. Number may not contain * more than 10 octal characters (30 bits). The most significant * bit of number is the sign bit. The remaining 29 bits are * magnitude bits. Negative numbers are represented using @@ -110,25 +129,35 @@ class ConvertOctal extends ConvertBase * #NUM! error value. * If OCT2HEX requires more than places characters, it returns * the #NUM! error value. - * @param int $places The number of characters to use. If places is omitted, OCT2HEX + * Or can be an array of values + * @param array|int $places The number of characters to use. If places is omitted, OCT2HEX * uses the minimum number of characters necessary. Places is useful * for padding the return value with leading 0s (zeros). * If places is not an integer, it is truncated. * If places is nonnumeric, OCT2HEX returns the #VALUE! error value. * If places is negative, OCT2HEX returns the #NUM! error value. + * Or can be an array of values + * + * @return array|string Result, or an error + * If an array of numbers is passed as an argument, then the returned result will also be an array + * with the same dimensions */ - public static function toHex($value, $places = null): string + public static function toHex($value, $places = null) { + if (is_array($value) || is_array($places)) { + return self::evaluateArrayArguments([self::class, __FUNCTION__], $value, $places); + } + try { - $value = self::validateValue(Functions::flattenSingleValue($value)); + $value = self::validateValue($value); $value = self::validateOctal($value); - $places = self::validatePlaces(Functions::flattenSingleValue($places)); + $places = self::validatePlaces($places); } catch (Exception $e) { return $e->getMessage(); } $hexVal = strtoupper(dechex((int) self::toDecimal($value))); - $hexVal = (PHP_INT_SIZE === 4 && strlen($value) === 10 && $value[0] >= '4') ? "FF$hexVal" : $hexVal; + $hexVal = (PHP_INT_SIZE === 4 && strlen($value) === 10 && $value[0] >= '4') ? "FF{$hexVal}" : $hexVal; return self::nbrConversionFormat($hexVal, $places); } diff --git a/src/PhpSpreadsheet/Calculation/Engineering/ConvertUOM.php b/src/PhpSpreadsheet/Calculation/Engineering/ConvertUOM.php index d169ae54..a104662b 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/ConvertUOM.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/ConvertUOM.php @@ -2,11 +2,14 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering; +use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; class ConvertUOM { + use ArrayEnabled; + public const CATEGORY_WEIGHT_AND_MASS = 'Weight and Mass'; public const CATEGORY_DISTANCE = 'Distance'; public const CATEGORY_TIME = 'Time'; @@ -518,17 +521,22 @@ class ConvertUOM * Excel Function: * CONVERT(value,fromUOM,toUOM) * - * @param float|int $value the value in fromUOM to convert - * @param string $fromUOM the units for value - * @param string $toUOM the units for the result + * @param array|float|int|string $value the value in fromUOM to convert + * Or can be an array of values + * @param array|string $fromUOM the units for value + * Or can be an array of values + * @param array|string $toUOM the units for the result + * Or can be an array of values * - * @return float|string + * @return array|float|string Result, or a string containing an error + * If an array of numbers is passed as an argument, then the returned result will also be an array + * with the same dimensions */ public static function CONVERT($value, $fromUOM, $toUOM) { - $value = Functions::flattenSingleValue($value); - $fromUOM = Functions::flattenSingleValue($fromUOM); - $toUOM = Functions::flattenSingleValue($toUOM); + if (is_array($value) || is_array($fromUOM) || is_array($toUOM)) { + return self::evaluateArrayArguments([self::class, __FUNCTION__], $value, $fromUOM, $toUOM); + } if (!is_numeric($value)) { return Functions::VALUE(); diff --git a/src/PhpSpreadsheet/Calculation/Engineering/Erf.php b/src/PhpSpreadsheet/Calculation/Engineering/Erf.php index db87ec0d..5aca8f2b 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/Erf.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/Erf.php @@ -2,10 +2,13 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering; +use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Functions; class Erf { + use ArrayEnabled; + private static $twoSqrtPi = 1.128379167095512574; /** @@ -22,15 +25,20 @@ class Erf * ERF(lower[,upper]) * * @param mixed $lower Lower bound float for integrating ERF + * Or can be an array of values * @param mixed $upper Upper bound float for integrating ERF. * If omitted, ERF integrates between zero and lower_limit + * Or can be an array of values * - * @return float|string + * @return array|float|string + * If an array of numbers is passed as an argument, then the returned result will also be an array + * with the same dimensions */ public static function ERF($lower, $upper = null) { - $lower = Functions::flattenSingleValue($lower); - $upper = Functions::flattenSingleValue($upper); + if (is_array($lower) || is_array($upper)) { + return self::evaluateArrayArguments([self::class, __FUNCTION__], $lower, $upper); + } if (is_numeric($lower)) { if ($upper === null) { @@ -53,12 +61,17 @@ class Erf * ERF.PRECISE(limit) * * @param mixed $limit Float bound for integrating ERF, other bound is zero + * Or can be an array of values * - * @return float|string + * @return array|float|string + * If an array of numbers is passed as an argument, then the returned result will also be an array + * with the same dimensions */ public static function ERFPRECISE($limit) { - $limit = Functions::flattenSingleValue($limit); + if (is_array($limit)) { + return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $limit); + } return self::ERF($limit); } diff --git a/src/PhpSpreadsheet/Calculation/Engineering/ErfC.php b/src/PhpSpreadsheet/Calculation/Engineering/ErfC.php index c57a28f4..da1a932e 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/ErfC.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/ErfC.php @@ -2,10 +2,13 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering; +use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; use PhpOffice\PhpSpreadsheet\Calculation\Functions; class ErfC { + use ArrayEnabled; + /** * ERFC. * @@ -20,12 +23,17 @@ class ErfC * ERFC(x) * * @param mixed $value The float lower bound for integrating ERFC + * Or can be an array of values * - * @return float|string + * @return array|float|string + * If an array of numbers is passed as an argument, then the returned result will also be an array + * with the same dimensions */ public static function ERFC($value) { - $value = Functions::flattenSingleValue($value); + if (is_array($value)) { + return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $value); + } if (is_numeric($value)) { return self::erfcValue($value); @@ -45,7 +53,7 @@ class ErfC return 1 - Erf::erfValue($value); } if ($value < 0) { - return 2 - self::ERFC(-$value); + return 2 - self::erfcValue(-$value); } $a = $n = 1; $b = $c = $value; diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BesselITest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BesselITest.php index d24a0208..6e9673a8 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BesselITest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BesselITest.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; +use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PHPUnit\Framework\TestCase; @@ -30,4 +31,31 @@ class BesselITest extends TestCase { return require 'tests/data/Calculation/Engineering/BESSELI.php'; } + + /** + * @dataProvider providerBesselIArray + */ + public function testBesselIArray(array $expectedResult, string $value, string $ord): void + { + $calculation = Calculation::getInstance(); + + $formula = "=BESSELI({$value}, {$ord})"; + $result = $calculation->_calculateFormulaValue($formula); + self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14); + } + + public function providerBesselIArray(): array + { + return [ + 'row/column vector' => [ + [ + [1.393725572000487, 1.0634833439946074, 1.0, 1.0156861326120836, 3.2898391723912908], + [-0.7146779363262508, -0.25789430328903556, 0.0, 0.12597910862299733, 2.516716242025361], + [0.20259567978255663, 0.031906148375295325, 0.0, 0.007853269593280343, 1.276466158815611], + ], + '{-1.2, -0.5, 0.0, 0.25, 2.5}', + '{0; 1; 2}', + ], + ]; + } } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BesselJTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BesselJTest.php index 325a0d64..16002ae5 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BesselJTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BesselJTest.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; +use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PHPUnit\Framework\TestCase; @@ -30,4 +31,31 @@ class BesselJTest extends TestCase { return require 'tests/data/Calculation/Engineering/BESSELJ.php'; } + + /** + * @dataProvider providerBesselJArray + */ + public function testBesselJArray(array $expectedResult, string $value, string $ord): void + { + $calculation = Calculation::getInstance(); + + $formula = "=BESSELJ({$value}, {$ord})"; + $result = $calculation->_calculateFormulaValue($formula); + self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14); + } + + public function providerBesselJArray(): array + { + return [ + 'row/column vector' => [ + [ + [0.6711327417644983, 0.9384698074235406, 1.00000000283141, 0.9844359313618615, -0.04838377582675685], + [-0.4982890574931824, -0.24226845767957006, 0.0, 0.12402597733693042, 0.49709410250442176], + [0.15934901834766313, 0.03060402345868265, 0.0, 0.007771889285962677, 0.44605905783029426], + ], + '{-1.2, -0.5, 0.0, 0.25, 2.5}', + '{0; 1; 2}', + ], + ]; + } } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BesselKTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BesselKTest.php index 51725d38..11e0885e 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BesselKTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BesselKTest.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; +use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PHPUnit\Framework\TestCase; @@ -30,4 +31,31 @@ class BesselKTest extends TestCase { return require 'tests/data/Calculation/Engineering/BESSELK.php'; } + + /** + * @dataProvider providerBesselKArray + */ + public function testBesselKArray(array $expectedResult, string $value, string $ord): void + { + $calculation = Calculation::getInstance(); + + $formula = "=BESSELK({$value}, {$ord})"; + $result = $calculation->_calculateFormulaValue($formula); + self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14); + } + + public function providerBesselKArray(): array + { + return [ + 'row/column vector' => [ + [ + [4.721244734980139, 1.5415067364690132, 0.9244190350213235, 0.2976030874538336, 0.06234755419101918], + [99.97389411857176, 3.747025980669556, 1.6564411280110791, 0.4021240820149834, 0.07389081565026694], + [19999.500068449335, 31.517714581825462, 7.5501835470656395, 0.9410016186778072, 0.12146020671123273], + ], + '{0.01, 0.25, 0.5, 1.25, 2.5}', + '{0; 1; 2}', + ], + ]; + } } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BesselYTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BesselYTest.php index 1e8d863f..47f05e98 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BesselYTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BesselYTest.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; +use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PHPUnit\Framework\TestCase; @@ -30,4 +31,31 @@ class BesselYTest extends TestCase { return require 'tests/data/Calculation/Engineering/BESSELY.php'; } + + /** + * @dataProvider providerBesselYArray + */ + public function testBesselYArray(array $expectedResult, string $value, string $ord): void + { + $calculation = Calculation::getInstance(); + + $formula = "=BESSELY({$value}, {$ord})"; + $result = $calculation->_calculateFormulaValue($formula); + self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14); + } + + public function providerBesselYArray(): array + { + return [ + 'row/column vector' => [ + [ + [-3.005455650891885, -0.9315730314941618, -0.44451873376270784, 0.25821685699105446, 0.4980703584466886], + [-63.67859624529592, -2.7041052277866418, -1.4714723918672943, -0.5843640364184131, 0.14591813750831284], + [-12732.713793408293, -20.701268790798974, -5.441370833706469, -1.1931993152605154, -0.3813358484400383], + ], + '{0.01, 0.25, 0.5, 1.25, 2.5}', + '{0; 1; 2}', + ], + ]; + } } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Bin2DecTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Bin2DecTest.php index c0923d1a..beb31bbb 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Bin2DecTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Bin2DecTest.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; +use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Spreadsheet; @@ -90,4 +91,26 @@ class Bin2DecTest extends TestCase $sheet->setCellValue($cell, '=BIN2DEC(101.1)'); self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue(), 'Excel'); } + + /** + * @dataProvider providerBin2DecArray + */ + public function testBin2DecArray(array $expectedResult, string $value): void + { + $calculation = Calculation::getInstance(); + + $formula = "=BIN2DEC({$value})"; + $result = $calculation->_calculateFormulaValue($formula); + self::assertEquals($expectedResult, $result); + } + + public function providerBin2DecArray(): array + { + return [ + 'row/column vector' => [ + [[4, 7, 63, 153, 204, 341]], + '{"100", "111", "111111", "10011001", "11001100", "101010101"}', + ], + ]; + } } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Bin2HexTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Bin2HexTest.php index c95c375d..ccb2ce79 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Bin2HexTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Bin2HexTest.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; +use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Spreadsheet; @@ -90,4 +91,26 @@ class Bin2HexTest extends TestCase $sheet->setCellValue($cell, '=BIN2HEX(101.1)'); self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue()); } + + /** + * @dataProvider providerBin2HexArray + */ + public function testBin2HexArray(array $expectedResult, string $value): void + { + $calculation = Calculation::getInstance(); + + $formula = "=BIN2HEX({$value})"; + $result = $calculation->_calculateFormulaValue($formula); + self::assertEquals($expectedResult, $result); + } + + public function providerBin2HexArray(): array + { + return [ + 'row/column vector' => [ + [['4', '7', '3F', '99', 'CC', '155']], + '{"100", "111", "111111", "10011001", "11001100", "101010101"}', + ], + ]; + } } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Bin2OctTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Bin2OctTest.php index ee54063c..513901a8 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Bin2OctTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Bin2OctTest.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; +use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Spreadsheet; @@ -90,4 +91,26 @@ class Bin2OctTest extends TestCase $sheet->setCellValue($cell, '=BIN2OCT(101.1)'); self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue()); } + + /** + * @dataProvider providerBin2OctArray + */ + public function testBin2OctArray(array $expectedResult, string $value): void + { + $calculation = Calculation::getInstance(); + + $formula = "=BIN2OCT({$value})"; + $result = $calculation->_calculateFormulaValue($formula); + self::assertEquals($expectedResult, $result); + } + + public function providerBin2OctArray(): array + { + return [ + 'row/column vector' => [ + [['4', '7', '77', '231', '314', '525']], + '{"100", "111", "111111", "10011001", "11001100", "101010101"}', + ], + ]; + } } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BitAndTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BitAndTest.php index 23682908..d5d8a26a 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BitAndTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BitAndTest.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; +use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PHPUnit\Framework\TestCase; @@ -30,4 +31,31 @@ class BitAndTest extends TestCase { return require 'tests/data/Calculation/Engineering/BITAND.php'; } + + /** + * @dataProvider providerBitAndArray + */ + public function testBitAndArray(array $expectedResult, string $number1, string $number2): void + { + $calculation = Calculation::getInstance(); + + $formula = "=BITAND({$number1}, {$number2})"; + $result = $calculation->_calculateFormulaValue($formula); + self::assertEquals($expectedResult, $result); + } + + public function providerBitAndArray(): array + { + return [ + 'row/column vector' => [ + [ + [3, 0, 1], + [4, 0, 0], + [5, 0, 1], + ], + '{7, 8, 9}', + '{3; 4; 5}', + ], + ]; + } } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BitLShiftTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BitLShiftTest.php index ee408497..246299ac 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BitLShiftTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BitLShiftTest.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; +use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PHPUnit\Framework\TestCase; @@ -30,4 +31,31 @@ class BitLShiftTest extends TestCase { return require 'tests/data/Calculation/Engineering/BITLSHIFT.php'; } + + /** + * @dataProvider providerBitLShiftArray + */ + public function testBitLShiftArray(array $expectedResult, string $number, string $bits): void + { + $calculation = Calculation::getInstance(); + + $formula = "=BITLSHIFT({$number}, {$bits})"; + $result = $calculation->_calculateFormulaValue($formula); + self::assertEquals($expectedResult, $result); + } + + public function providerBitLShiftArray(): array + { + return [ + 'row/column vector' => [ + [ + [14, 28, 56, 112, 224], + [16, 32, 64, 128, 256], + [18, 36, 72, 144, 288], + ], + '{7; 8; 9}', + '{1, 2, 3, 4, 5}', + ], + ]; + } } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BitOrTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BitOrTest.php index 3cc1f4bc..6addf05d 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BitOrTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BitOrTest.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; +use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PHPUnit\Framework\TestCase; @@ -30,4 +31,31 @@ class BitOrTest extends TestCase { return require 'tests/data/Calculation/Engineering/BITOR.php'; } + + /** + * @dataProvider providerBitOrArray + */ + public function testBitOrArray(array $expectedResult, string $number1, string $number2): void + { + $calculation = Calculation::getInstance(); + + $formula = "=BITOR({$number1}, {$number2})"; + $result = $calculation->_calculateFormulaValue($formula); + self::assertEquals($expectedResult, $result); + } + + public function providerBitOrArray(): array + { + return [ + 'row/column vector' => [ + [ + [7, 11, 11], + [7, 12, 13], + [7, 13, 13], + ], + '{7, 8, 9}', + '{3; 4; 5}', + ], + ]; + } } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BitRShiftTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BitRShiftTest.php index f58d6149..5c6f76c7 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BitRShiftTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BitRShiftTest.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; +use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PHPUnit\Framework\TestCase; @@ -30,4 +31,31 @@ class BitRShiftTest extends TestCase { return require 'tests/data/Calculation/Engineering/BITRSHIFT.php'; } + + /** + * @dataProvider providerBitRShiftArray + */ + public function testBitRShiftArray(array $expectedResult, string $number, string $bits): void + { + $calculation = Calculation::getInstance(); + + $formula = "=BITRSHIFT({$number}, {$bits})"; + $result = $calculation->_calculateFormulaValue($formula); + self::assertEquals($expectedResult, $result); + } + + public function providerBitRShiftArray(): array + { + return [ + 'row/column vector' => [ + [ + [31, 15, 7, 3, 1], + [32, 16, 8, 4, 2], + [37, 18, 9, 4, 2], + ], + '{63; 64; 75}', + '{1, 2, 3, 4, 5}', + ], + ]; + } } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BitXorTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BitXorTest.php index 4fa302af..ed8f2065 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BitXorTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BitXorTest.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; +use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PHPUnit\Framework\TestCase; @@ -30,4 +31,31 @@ class BitXorTest extends TestCase { return require 'tests/data/Calculation/Engineering/BITXOR.php'; } + + /** + * @dataProvider providerBitXorArray + */ + public function testBitXorArray(array $expectedResult, string $number1, string $number2): void + { + $calculation = Calculation::getInstance(); + + $formula = "=BITXOR({$number1}, {$number2})"; + $result = $calculation->_calculateFormulaValue($formula); + self::assertEquals($expectedResult, $result); + } + + public function providerBitXorArray(): array + { + return [ + 'row/column vector' => [ + [ + [4, 11, 10], + [3, 12, 13], + [2, 13, 12], + ], + '{7, 8, 9}', + '{3; 4; 5}', + ], + ]; + } } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ConvertUoMTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ConvertUoMTest.php index 87198edb..9a448824 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ConvertUoMTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ConvertUoMTest.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; +use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PHPUnit\Framework\TestCase; @@ -58,4 +59,58 @@ class ConvertUoMTest extends TestCase { return require 'tests/data/Calculation/Engineering/CONVERTUOM.php'; } + + /** + * @dataProvider providerConvertUoMArray + */ + public function testConvertUoMArray(array $expectedResult, string $value, string $fromUoM, string $toUoM): void + { + $calculation = Calculation::getInstance(); + + $formula = "=CONVERT({$value}, {$fromUoM}, {$toUoM})"; + $result = $calculation->_calculateFormulaValue($formula); + self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14); + } + + public function providerConvertUoMArray(): array + { + return [ + 'Weight/Mass' => [ + [ + [71.42857142857142, 0.15747304441777], + [453.5923699999991, 1.0], + ], + '1000', + '{"lbm", "g"}', + '{"stone"; "kg"}', + ], + 'Distance' => [ + [ + [2025371.8285214372, 1093.6132983377101], + [1851.9999999999984, 1.0], + ], + '1000', + '{"Nmi", "m"}', + '{"yd"; "km"}', + ], + 'Volume' => [ + [ + [2.976190476190475, 0.00628981077043211], + [473.1764729999994, 1.0], + ], + '1000', + '{"pt", "ml"}', + '{"barrel"; "l"}', + ], + 'Area' => [ + [ + [999.9960000040016, 0.247104393046628], + [404.6856422400005, 0.1], + ], + '1000', + '{"uk_acre", "m2"}', + '{"us_acre"; "ha"}', + ], + ]; + } } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Dec2BinTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Dec2BinTest.php index dfed3478..db4c517d 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Dec2BinTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Dec2BinTest.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; +use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Spreadsheet; @@ -90,4 +91,26 @@ class Dec2BinTest extends TestCase $sheet->setCellValue($cell, '=DEC2BIN(5.1)'); self::assertEquals(101, $sheet->getCell($cell)->getCalculatedValue(), 'Excel'); } + + /** + * @dataProvider providerDec2BinArray + */ + public function testDec2BinArray(array $expectedResult, string $value): void + { + $calculation = Calculation::getInstance(); + + $formula = "=DEC2BIN({$value})"; + $result = $calculation->_calculateFormulaValue($formula); + self::assertEquals($expectedResult, $result); + } + + public function providerDec2BinArray(): array + { + return [ + 'row/column vector' => [ + [['100', '111', '111111', '10011001', '11001100', '101010101']], + '{4, 7, 63, 153, 204, 341}', + ], + ]; + } } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Dec2HexTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Dec2HexTest.php index ebe49464..6200ac56 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Dec2HexTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Dec2HexTest.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; +use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; use PhpOffice\PhpSpreadsheet\Calculation\Functions; @@ -98,4 +99,26 @@ class Dec2HexTest extends TestCase self::assertEquals('7FFFFFFFFF', Engineering\ConvertDecimal::hex32bit(549755813887, 'FFFFFFFF', true)); self::assertEquals('FFFFFFFFFF', Engineering\ConvertDecimal::hex32bit(-1, 'FFFFFFFF', true)); } + + /** + * @dataProvider providerDec2HexArray + */ + public function testDec2HexArray(array $expectedResult, string $value): void + { + $calculation = Calculation::getInstance(); + + $formula = "=DEC2HEX({$value})"; + $result = $calculation->_calculateFormulaValue($formula); + self::assertEquals($expectedResult, $result); + } + + public function providerDec2HexArray(): array + { + return [ + 'row/column vector' => [ + [['4', '7', '3F', '99', 'CC', '155']], + '{4, 7, 63, 153, 204, 341}', + ], + ]; + } } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Dec2OctTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Dec2OctTest.php index 093f17bc..2e6007c5 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Dec2OctTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Dec2OctTest.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; +use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Spreadsheet; @@ -90,4 +91,26 @@ class Dec2OctTest extends TestCase $sheet->setCellValue($cell, '=DEC2OCT(17.1)'); self::assertEquals(21, $sheet->getCell($cell)->getCalculatedValue(), 'Excel'); } + + /** + * @dataProvider providerDec2OctArray + */ + public function testDec2OctArray(array $expectedResult, string $value): void + { + $calculation = Calculation::getInstance(); + + $formula = "=DEC2OCT({$value})"; + $result = $calculation->_calculateFormulaValue($formula); + self::assertEquals($expectedResult, $result); + } + + public function providerDec2OctArray(): array + { + return [ + 'row/column vector' => [ + [['4', '7', '77', '231', '314', '525']], + '{4, 7, 63, 153, 204, 341}', + ], + ]; + } } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/DeltaTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/DeltaTest.php index 749b33c2..41d809ca 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/DeltaTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/DeltaTest.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; +use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PHPUnit\Framework\TestCase; @@ -16,11 +17,13 @@ class DeltaTest extends TestCase /** * @dataProvider providerDELTA * + * @param mixed $a + * @param mixed $b * @param mixed $expectedResult */ - public function testDELTA($expectedResult, ...$args): void + public function testDELTA($expectedResult, $a, $b): void { - $result = Engineering::DELTA(...$args); + $result = Engineering::DELTA($a, $b); self::assertEquals($expectedResult, $result); } @@ -28,4 +31,33 @@ class DeltaTest extends TestCase { return require 'tests/data/Calculation/Engineering/DELTA.php'; } + + /** + * @dataProvider providerDeltaArray + */ + public function testDeltaArray(array $expectedResult, string $a, string $b): void + { + $calculation = Calculation::getInstance(); + + $formula = "=DELTA({$a}, {$b})"; + $result = $calculation->_calculateFormulaValue($formula); + self::assertEquals($expectedResult, $result); + } + + public function providerDeltaArray(): array + { + return [ + 'row/column vector' => [ + [ + [1, 0, 0, 0, 0], + [0, 1, 0, 0, 0], + [0, 0, 1, 0, 0], + [0, 0, 0, 1, 0], + [0, 0, 0, 0, 1], + ], + '{-1.2, -0.5, 0.0, 0.25, 2.5}', + '{-1.2; -0.5; 0.0; 0.25; 2.5}', + ], + ]; + } } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ErfCTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ErfCTest.php index 45d5b4c8..f0a721c7 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ErfCTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ErfCTest.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; +use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PHPUnit\Framework\TestCase; @@ -18,11 +19,12 @@ class ErfCTest extends TestCase /** * @dataProvider providerERFC * + * @param mixed $lower * @param mixed $expectedResult */ - public function testERFC($expectedResult, ...$args): void + public function testERFC($expectedResult, $lower): void { - $result = Engineering::ERFC(...$args); + $result = Engineering::ERFC($lower); self::assertEquals($expectedResult, $result); self::assertEqualsWithDelta($expectedResult, $result, self::ERF_PRECISION); } @@ -31,4 +33,28 @@ class ErfCTest extends TestCase { return require 'tests/data/Calculation/Engineering/ERFC.php'; } + + /** + * @dataProvider providerErfCArray + */ + public function testErfCArray(array $expectedResult, string $lower): void + { + $calculation = Calculation::getInstance(); + + $formula = "=ERFC({$lower})"; + $result = $calculation->_calculateFormulaValue($formula); + self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14); + } + + public function providerErfCArray(): array + { + return [ + 'row vector' => [ + [ + [1.9103139782296354, 1.5204998778130465, 1.0, 0.7236736098317631, 0.0004069520174449588], + ], + '{-1.2, -0.5, 0.0, 0.25, 2.5}', + ], + ]; + } } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ErfPreciseTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ErfPreciseTest.php index 952b2560..dc3ee84c 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ErfPreciseTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ErfPreciseTest.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; +use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PHPUnit\Framework\TestCase; @@ -18,11 +19,12 @@ class ErfPreciseTest extends TestCase /** * @dataProvider providerERFPRECISE * + * @param mixed $limit * @param mixed $expectedResult */ - public function testERFPRECISE($expectedResult, ...$args): void + public function testERFPRECISE($expectedResult, $limit): void { - $result = Engineering::ERFPRECISE(...$args); + $result = Engineering::ERFPRECISE($limit); self::assertEquals($expectedResult, $result); self::assertEqualsWithDelta($expectedResult, $result, self::ERF_PRECISION); } @@ -31,4 +33,28 @@ class ErfPreciseTest extends TestCase { return require 'tests/data/Calculation/Engineering/ERFPRECISE.php'; } + + /** + * @dataProvider providerErfPreciseArray + */ + public function testErfPreciseArray(array $expectedResult, string $limit): void + { + $calculation = Calculation::getInstance(); + + $formula = "=ERF.PRECISE({$limit})"; + $result = $calculation->_calculateFormulaValue($formula); + self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14); + } + + public function providerErfPreciseArray(): array + { + return [ + 'row vector' => [ + [ + [-0.9103139782296353, -0.5204998778130465, 0.0, 0.2763263901682369, 0.999593047982555], + ], + '{-1.2, -0.5, 0.0, 0.25, 2.5}', + ], + ]; + } } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ErfTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ErfTest.php index 9866024f..4d13d47d 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ErfTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ErfTest.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; +use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PHPUnit\Framework\TestCase; @@ -18,11 +19,13 @@ class ErfTest extends TestCase /** * @dataProvider providerERF * + * @param mixed $lower + * @param null|mixed $upper * @param mixed $expectedResult */ - public function testERF($expectedResult, ...$args): void + public function testERF($expectedResult, $lower, $upper = null): void { - $result = Engineering::ERF(...$args); + $result = Engineering::ERF($lower, $upper); self::assertEquals($expectedResult, $result); self::assertEqualsWithDelta($expectedResult, $result, self::ERF_PRECISION); } @@ -31,4 +34,28 @@ class ErfTest extends TestCase { return require 'tests/data/Calculation/Engineering/ERF.php'; } + + /** + * @dataProvider providerErfArray + */ + public function testErfArray(array $expectedResult, string $lower, string $upper = 'NULL'): void + { + $calculation = Calculation::getInstance(); + + $formula = "=ERF({$lower}, {$upper})"; + $result = $calculation->_calculateFormulaValue($formula); + self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14); + } + + public function providerErfArray(): array + { + return [ + 'row vector' => [ + [ + [-0.9103139782296353, -0.5204998778130465, 0.0, 0.2763263901682369, 0.999593047982555], + ], + '{-1.2, -0.5, 0.0, 0.25, 2.5}', + ], + ]; + } } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/GeStepTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/GeStepTest.php index 07e3a48c..4e5b8ec5 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/GeStepTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/GeStepTest.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; +use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PHPUnit\Framework\TestCase; @@ -16,11 +17,13 @@ class GeStepTest extends TestCase /** * @dataProvider providerGESTEP * + * @param mixed $a + * @param mixed $b * @param mixed $expectedResult */ - public function testGESTEP($expectedResult, ...$args): void + public function testGESTEP($expectedResult, $a, $b): void { - $result = Engineering::GESTEP(...$args); + $result = Engineering::GESTEP($a, $b); self::assertEquals($expectedResult, $result); } @@ -28,4 +31,33 @@ class GeStepTest extends TestCase { return require 'tests/data/Calculation/Engineering/GESTEP.php'; } + + /** + * @dataProvider providerGeStepArray + */ + public function testGeStepArray(array $expectedResult, string $a, string $b): void + { + $calculation = Calculation::getInstance(); + + $formula = "=GESTEP({$a}, {$b})"; + $result = $calculation->_calculateFormulaValue($formula); + self::assertEquals($expectedResult, $result); + } + + public function providerGeStepArray(): array + { + return [ + 'row/column vector' => [ + [ + [1, 1, 1, 1, 1], + [0, 1, 1, 1, 1], + [0, 1, 1, 1, 0], + [0, 1, 0, 1, 0], + [0, 1, 0, 0, 0], + ], + '{-1.2, 2.5, 0.0, 0.25, -0.5}', + '{-1.2; -0.5; 0.0; 0.25; 2.5}', + ], + ]; + } } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Hex2BinTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Hex2BinTest.php index ad76716c..f70d1943 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Hex2BinTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Hex2BinTest.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; +use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Spreadsheet; @@ -93,4 +94,26 @@ class Hex2BinTest extends TestCase $sheet->setCellValue($cell, '=HEX2BIN(10.1)'); self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue()); } + + /** + * @dataProvider providerHex2BinArray + */ + public function testHex2BinArray(array $expectedResult, string $value): void + { + $calculation = Calculation::getInstance(); + + $formula = "=HEX2BIN({$value})"; + $result = $calculation->_calculateFormulaValue($formula); + self::assertEquals($expectedResult, $result); + } + + public function providerHex2BinArray(): array + { + return [ + 'row/column vector' => [ + [['100', '111', '111111', '10011001', '11001100', '101010101']], + '{"4", "7", "3F", "99", "CC", "155"}', + ], + ]; + } } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Hex2DecTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Hex2DecTest.php index 806ba44d..2e4ceeab 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Hex2DecTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Hex2DecTest.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; +use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Spreadsheet; @@ -93,4 +94,26 @@ class Hex2DecTest extends TestCase $sheet->setCellValue($cell, '=HEX2DEC(10.1)'); self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue(), 'Excel'); } + + /** + * @dataProvider providerHex2DecArray + */ + public function testHex2DecArray(array $expectedResult, string $value): void + { + $calculation = Calculation::getInstance(); + + $formula = "=HEX2DEC({$value})"; + $result = $calculation->_calculateFormulaValue($formula); + self::assertEquals($expectedResult, $result); + } + + public function providerHex2DecArray(): array + { + return [ + 'row/column vector' => [ + [[4, 7, 63, 153, 204, 341]], + '{"4", "7", "3F", "99", "CC", "155"}', + ], + ]; + } } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Hex2OctTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Hex2OctTest.php index 41f1a8f7..449925df 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Hex2OctTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Hex2OctTest.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; +use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Spreadsheet; @@ -90,4 +91,26 @@ class Hex2OctTest extends TestCase $sheet->setCellValue($cell, '=HEX2OCT(10.1)'); self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue(), 'Excel'); } + + /** + * @dataProvider providerHex2OctArray + */ + public function testHex2OctArray(array $expectedResult, string $value): void + { + $calculation = Calculation::getInstance(); + + $formula = "=HEX2OCT({$value})"; + $result = $calculation->_calculateFormulaValue($formula); + self::assertEquals($expectedResult, $result); + } + + public function providerHex2OctArray(): array + { + return [ + 'row/column vector' => [ + [['4', '7', '77', '231', '314', '525']], + '{"4", "7", "3F", "99", "CC", "155"}', + ], + ]; + } } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Oct2BinTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Oct2BinTest.php index e7f085b1..39c8c1d9 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Oct2BinTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Oct2BinTest.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; +use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Spreadsheet; @@ -90,4 +91,26 @@ class Oct2BinTest extends TestCase $sheet->setCellValue($cell, '=OCT2BIN(10.1)'); self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue()); } + + /** + * @dataProvider providerOct2BinArray + */ + public function testOct2BinArray(array $expectedResult, string $value): void + { + $calculation = Calculation::getInstance(); + + $formula = "=OCT2BIN({$value})"; + $result = $calculation->_calculateFormulaValue($formula); + self::assertEquals($expectedResult, $result); + } + + public function providerOct2BinArray(): array + { + return [ + 'row/column vector' => [ + [['100', '111', '111111', '10011001', '11001100', '101010101']], + '{"4", "7", "77", "231", "314", "525"}', + ], + ]; + } } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Oct2DecTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Oct2DecTest.php index 2c354046..e814e76d 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Oct2DecTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Oct2DecTest.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; +use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Spreadsheet; @@ -90,4 +91,26 @@ class Oct2DecTest extends TestCase $sheet->setCellValue($cell, '=OCT2DEC(10.1)'); self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue()); } + + /** + * @dataProvider providerOct2DecArray + */ + public function testOct2DecArray(array $expectedResult, string $value): void + { + $calculation = Calculation::getInstance(); + + $formula = "=OCT2DEC({$value})"; + $result = $calculation->_calculateFormulaValue($formula); + self::assertEquals($expectedResult, $result); + } + + public function providerOct2DecArray(): array + { + return [ + 'row/column vector' => [ + [[4, 7, 63, 153, 204, 341]], + '{"4", "7", "77", "231", "314", "525"}', + ], + ]; + } } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Oct2HexTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Oct2HexTest.php index 3f721a48..0f38752f 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Oct2HexTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Oct2HexTest.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; +use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Spreadsheet; @@ -90,4 +91,26 @@ class Oct2HexTest extends TestCase $sheet->setCellValue($cell, '=OCT2HEX(20.1)'); self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue()); } + + /** + * @dataProvider providerOct2HexArray + */ + public function testOct2HexArray(array $expectedResult, string $value): void + { + $calculation = Calculation::getInstance(); + + $formula = "=OCT2HEX({$value})"; + $result = $calculation->_calculateFormulaValue($formula); + self::assertEquals($expectedResult, $result); + } + + public function providerOct2HexArray(): array + { + return [ + 'row/column vector' => [ + [['4', '7', '3F', '99', 'CC', '155']], + '{"4", "7", "77", "231", "314", "525"}', + ], + ]; + } }