PlantGrowthTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace MathPHP\Tests\SampleData;
  3. use MathPHP\SampleData;
  4. class PlantGrowthTest extends \PHPUnit\Framework\TestCase
  5. {
  6. /** @var SampleData\PlantGrowth */
  7. private $plantGrowth;
  8. public function setUp(): void
  9. {
  10. $this->plantGrowth = new SampleData\PlantGrowth();
  11. }
  12. /**
  13. * @test 30 observations
  14. */
  15. public function testDataHas30Observations()
  16. {
  17. // When
  18. $data = $this->plantGrowth->getData();
  19. // Then
  20. $this->assertCount(30, $data);
  21. }
  22. /**
  23. * @test 2 variables
  24. */
  25. public function testDataHas2Variables()
  26. {
  27. // When
  28. $data = $this->plantGrowth->getData();
  29. // Then
  30. foreach ($data as $observation) {
  31. $this->assertCount(2, $observation);
  32. }
  33. }
  34. /**
  35. * @test Labeled data
  36. * @dataProvider dataProviderForLabeledData
  37. * @param int $i
  38. * @param array $expectedData
  39. */
  40. public function testLabeledData(int $i, array $expectedData)
  41. {
  42. // When
  43. $labeledData = $this->plantGrowth->getLabeledData();
  44. // Then
  45. $this->assertEquals($expectedData, $labeledData[$i]);
  46. }
  47. /**
  48. * @return array (model, data)
  49. */
  50. public function dataProviderForLabeledData(): array
  51. {
  52. return [
  53. [
  54. 0,
  55. [
  56. 'weight' => 4.17,
  57. 'group' => 'ctrl',
  58. ]
  59. ],
  60. [
  61. 14,
  62. [
  63. 'weight' => 5.87,
  64. 'group' => 'trt1',
  65. ]
  66. ],
  67. [
  68. 29,
  69. [
  70. 'weight' => 5.26,
  71. 'group' => 'trt2',
  72. ]
  73. ],
  74. ];
  75. }
  76. /**
  77. * @test 30 weight observations
  78. */
  79. public function testNumberOfWeights()
  80. {
  81. // When
  82. $observations = $this->plantGrowth->getWeight();
  83. // Then
  84. $this->assertCount(30, $observations);
  85. }
  86. /**
  87. * @test 30 group observations
  88. */
  89. public function testNumberOfGroups()
  90. {
  91. // When
  92. $observations = $this->plantGrowth->getGroup();
  93. // Then
  94. $this->assertCount(30, $observations);
  95. }
  96. }