mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-27 10:30:02 +00:00
541bf0f876
# Conflicts: # docs/topics/calculation-engine.md # phpstan-baseline.neon # src/PhpSpreadsheet/Reader/Xlsx.php # tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ConvertUoMTest.php # tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ErfCTest.php # tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ErfPreciseTest.php # tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ErfTest.php # tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ParseComplexTest.php # tests/PhpSpreadsheetTests/Calculation/Functions/Financial/IrrTest.php # tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/AddressTest.php # tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/ColumnsTest.php # tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/IndexTest.php # tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/IndirectTest.php # tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/RowsTest.php # tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/FactTest.php # tests/PhpSpreadsheetTests/Calculation/Functions/TextData/NumberValueTest.php
75 lines
2.3 KiB
PHP
75 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
|
|
|
class RandBetweenTest extends AllSetupTeardown
|
|
{
|
|
/**
|
|
* @dataProvider providerRANDBETWEEN
|
|
*
|
|
* @param mixed $expectedResult
|
|
* @param mixed $min
|
|
* @param mixed $max
|
|
*/
|
|
public function testRANDBETWEEN($expectedResult, $min = 'omitted', $max = 'omitted'): void
|
|
{
|
|
$this->mightHaveException($expectedResult);
|
|
$sheet = $this->getSheet();
|
|
$lower = (int) $min;
|
|
$upper = (int) $max;
|
|
if ($min !== null) {
|
|
$sheet->getCell('A1')->setValue($min);
|
|
}
|
|
if ($max !== null) {
|
|
$sheet->getCell('A2')->setValue($max);
|
|
}
|
|
if ($min === 'omitted') {
|
|
$sheet->getCell('B1')->setValue('=RANDBETWEEN()');
|
|
} elseif ($max === 'omitted') {
|
|
$sheet->getCell('B1')->setValue('=RANDBETWEEN(A1)');
|
|
} else {
|
|
$sheet->getCell('B1')->setValue('=RANDBETWEEN(A1,A2)');
|
|
}
|
|
$result = $sheet->getCell('B1')->getCalculatedValue();
|
|
if (is_numeric($expectedResult)) {
|
|
self::assertGreaterThanOrEqual($lower, $result);
|
|
self::assertLessThanOrEqual($upper, $result);
|
|
} else {
|
|
self::assertSame($expectedResult, $result);
|
|
}
|
|
}
|
|
|
|
public function providerRANDBETWEEN(): array
|
|
{
|
|
return require 'tests/data/Calculation/MathTrig/RANDBETWEEN.php';
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerRandBetweenArray
|
|
*/
|
|
public function testRandBetweenArray(
|
|
int $expectedRows,
|
|
int $expectedColumns,
|
|
string $argument1,
|
|
string $argument2
|
|
): void {
|
|
$calculation = Calculation::getInstance();
|
|
|
|
$formula = "=RandBetween({$argument1}, {$argument2})";
|
|
$result = $calculation->calculateFormulaValue($formula);
|
|
self::assertIsArray($result);
|
|
self::assertCount($expectedRows, /** @scrutinizer ignore-type */ $result);
|
|
self::assertIsArray($result[0]);
|
|
self::assertCount($expectedColumns, /** @scrutinizer ignore-type */ $result[0]);
|
|
}
|
|
|
|
public function providerRandBetweenArray(): array
|
|
{
|
|
return [
|
|
'row/column vectors' => [2, 2, '{1, 10}', '{10; 100}'],
|
|
];
|
|
}
|
|
}
|