PermutTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
  4. use PhpOffice\PhpSpreadsheet\Calculation\Functions;
  5. use PhpOffice\PhpSpreadsheet\Calculation\Statistical;
  6. use PHPUnit\Framework\TestCase;
  7. class PermutTest extends TestCase
  8. {
  9. protected function setUp(): void
  10. {
  11. Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
  12. }
  13. /**
  14. * @dataProvider providerPERMUT
  15. *
  16. * @param mixed $expectedResult
  17. */
  18. public function testPERMUT($expectedResult, ...$args): void
  19. {
  20. $result = Statistical::PERMUT(...$args);
  21. self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
  22. }
  23. public function providerPERMUT(): array
  24. {
  25. return require 'tests/data/Calculation/Statistical/PERMUT.php';
  26. }
  27. /**
  28. * @dataProvider providerPermutArray
  29. */
  30. public function testPermutArray(array $expectedResult, string $argument1, string $argument2): void
  31. {
  32. $calculation = Calculation::getInstance();
  33. $formula = "=PERMUT({$argument1},{$argument2})";
  34. $result = $calculation->_calculateFormulaValue($formula);
  35. self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
  36. }
  37. public function providerPermutArray(): array
  38. {
  39. return [
  40. 'first argument row vector' => [
  41. [[336, 60]],
  42. '{8, 5}',
  43. '3',
  44. ],
  45. 'first argument column vector' => [
  46. [[336], [60]],
  47. '{8; 5}',
  48. '3',
  49. ],
  50. 'first argument matrix' => [
  51. [[336, 60], [6, 210]],
  52. '{8, 5; 3, 7}',
  53. '3',
  54. ],
  55. 'second argument row vector' => [
  56. [[1716, 1235520]],
  57. '13',
  58. '{3, 6}',
  59. ],
  60. 'second argument column vector' => [
  61. [[1716], [1235520]],
  62. '13',
  63. '{3; 6}',
  64. ],
  65. 'second argument matrix' => [
  66. [[1716, 1235520], [17160, 51891840]],
  67. '13',
  68. '{3, 6; 4, 8}',
  69. ],
  70. 'A row and a column vector' => [
  71. [
  72. [95040, 11880, 1320, 132],
  73. [30240, 5040, 720, 90],
  74. [6720, 1680, 336, 56],
  75. [720, 360, 120, 30],
  76. ],
  77. '{12; 10; 8; 6}',
  78. '{5, 4, 3, 2}',
  79. ],
  80. 'Two row vectors' => [
  81. [[95040, 5040, 336, 30]],
  82. '{12, 10, 8, 6}',
  83. '{5, 4, 3, 2}',
  84. ],
  85. 'Two column vectors' => [
  86. [[95040], [5040], [336], [30]],
  87. '{12; 10; 8; 6}',
  88. '{5; 4; 3; 2}',
  89. ],
  90. ];
  91. }
  92. }