PhpSpreadsheet/tests/data/Calculation/Calculation.php
Fräntz Miccoli 0b387e767e
Branch pruning around IF function calls to avoid resolution of every branches
Calculation engine was resolving every function by first resolving its arguments
including IFs, this was causing significant over evaluation when IFs were used
as it meant for every case to be evaluated.

Introduce elements to identify ifs and enable better branch resolution
(pruning). We tag parsed tokens to associate a branch identifier to them.

Closes #844
2019-08-11 18:23:47 -07:00

64 lines
1.7 KiB
PHP

<?php
function calculationTestDataGenerator()
{
$dataArray1 = [
['please +', 'please *', 'increment'],
[1, 1, 1], // sum is 3
[3, 3, 3], // product is 27
];
$set0 = [3, $dataArray1, '=IF(A1="please +", SUM(A2:C2), 2)', 'E5'];
$set1 = [3, $dataArray1, '=IF(TRUE(), SUM(A2:C2), 2)', 'E5'];
$formula1 = '=IF(A1="please +",SUM(A2:C2),7 + IF(B1="please *", 4, 2))';
$set2 = [3, $dataArray1, $formula1, 'E5'];
$originalDataArray = $dataArray1;
$dataArray1[0][0] = 'not please + something else';
$set3 = [11, $dataArray1, $formula1, 'E5'];
$dataArray2 = [
['flag1', 'flag2', 'flag3', 'flag1'],
[1, 2, 3, 4],
[5, 6, 7, 8],
];
$set4 = [3, $dataArray2, '=IF($A$1=$B$1,A2,IF($A$1=$C$1,B2,IF($A$1=$D$1,C2,C3)))', 'E5'];
$dataArray2[0][0] = 'flag3';
$set5 = [2, $dataArray2, '=IF(A1=B1,A2,IF(A1=C1,B2,IF(A1=D1,C2,C3)))', 'E5'];
$dataArray3 = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
];
$set6 = [0, $dataArray3, '=IF(A1+B1>3,C1,0)', 'E5'];
$dataArray4 = [
['noflag', 0, 0],
[127000, 0, 0],
[ 10000, 0.03, 0],
[ 20000, 0.06, 0],
[ 40000, 0.09, 0],
[ 70000, 0.12, 0],
[ 90000, 0.03, 0]
];
$formula2 = '=IF(A1="flag",IF(A2<10, 0) + IF(A3<10000, 0))';
$set7 = [false, $dataArray4, $formula2, 'E5'];
$dataArray5 = [
[1, 2],
[3, 4],
['=A1+A2', '=SUM(B1:B2)'],
[ 'take A', 0]
];
$formula3 = '=IF(A4="take A", A3, B3)';
$set8 = [4, $dataArray5, $formula3, 'E5', ['A3'], ['B3']];
return [$set0, $set1, $set2, $set3, $set4, $set5, $set6, $set7, $set8];
};
return calculationTestDataGenerator();