DStDevPTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Database;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Database;
  4. use PhpOffice\PhpSpreadsheet\Calculation\Functions;
  5. use PHPUnit\Framework\TestCase;
  6. class DStDevPTest extends TestCase
  7. {
  8. protected function setUp(): void
  9. {
  10. Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
  11. }
  12. /**
  13. * @dataProvider providerDStDevP
  14. *
  15. * @param mixed $expectedResult
  16. * @param mixed $database
  17. * @param mixed $field
  18. * @param mixed $criteria
  19. */
  20. public function testDStDevP($expectedResult, $database, $field, $criteria): void
  21. {
  22. $result = Database::DSTDEVP($database, $field, $criteria);
  23. self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12);
  24. }
  25. private function database1(): array
  26. {
  27. return [
  28. ['Tree', 'Height', 'Age', 'Yield', 'Profit'],
  29. ['Apple', 18, 20, 14, 105],
  30. ['Pear', 12, 12, 10, 96],
  31. ['Cherry', 13, 14, 9, 105],
  32. ['Apple', 14, 15, 10, 75],
  33. ['Pear', 9, 8, 8, 77],
  34. ['Apple', 8, 9, 6, 45],
  35. ];
  36. }
  37. private function database2(): array
  38. {
  39. return [
  40. ['Name', 'Gender', 'Age', 'Subject', 'Score'],
  41. ['Amy', 'Female', 10, 'Math', 0.63],
  42. ['Amy', 'Female', 10, 'English', 0.78],
  43. ['Amy', 'Female', 10, 'Science', 0.39],
  44. ['Bill', 'Male', 8, 'Math', 0.55],
  45. ['Bill', 'Male', 8, 'English', 0.71],
  46. ['Bill', 'Male', 8, 'Science', 0.51],
  47. ['Sam', 'Male', 9, 'Math', 0.39],
  48. ['Sam', 'Male', 9, 'English', 0.52],
  49. ['Sam', 'Male', 9, 'Science', 0.48],
  50. ['Tom', 'Male', 9, 'Math', 0.78],
  51. ['Tom', 'Male', 9, 'English', 0.69],
  52. ['Tom', 'Male', 9, 'Science', 0.65],
  53. ];
  54. }
  55. public function providerDStDevP(): array
  56. {
  57. return [
  58. [
  59. 2.653299832284,
  60. $this->database1(),
  61. 'Yield',
  62. [
  63. ['Tree'],
  64. ['=Apple'],
  65. ['=Pear'],
  66. ],
  67. ],
  68. [
  69. 0.085244745684,
  70. $this->database2(),
  71. 'Score',
  72. [
  73. ['Subject', 'Gender'],
  74. ['English', 'Male'],
  75. ],
  76. ],
  77. [
  78. 0.160623784042,
  79. $this->database2(),
  80. 'Score',
  81. [
  82. ['Subject', 'Age'],
  83. ['Math', '>8'],
  84. ],
  85. ],
  86. [
  87. null,
  88. $this->database1(),
  89. null,
  90. $this->database1(),
  91. ],
  92. ];
  93. }
  94. }