CerealTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. namespace MathPHP\Tests\SampleData;
  3. use MathPHP\SampleData;
  4. class CerealTest extends \PHPUnit\Framework\TestCase
  5. {
  6. /** @var SampleData\Cereal */
  7. private $cereal;
  8. public function setUp(): void
  9. {
  10. $this->cereal = new SampleData\Cereal();
  11. }
  12. /**
  13. * @test observations
  14. */
  15. public function testDataObservations()
  16. {
  17. // When
  18. $X = $this->cereal->getXData();
  19. $Y = $this->cereal->getYData();
  20. $Ysc = $this->cereal->getYscData();
  21. $names = $this->cereal->getCereals();
  22. // Then
  23. $this->assertCount(15, $X);
  24. $this->assertCount(15, $Y);
  25. $this->assertCount(15, $Ysc);
  26. $this->assertCount(15, $names);
  27. }
  28. /**
  29. * @test X variables
  30. */
  31. public function testXDataVariables()
  32. {
  33. // When
  34. $X = $this->cereal->getXData();
  35. // Then
  36. foreach ($X as $observation) {
  37. $this->assertCount(145, $observation);
  38. }
  39. }
  40. /**
  41. * @test Labeled X data
  42. */
  43. public function testLabeledXData()
  44. {
  45. // When
  46. $X = $this->cereal->getLabeledXData();
  47. // Then
  48. $this->assertCount(15, $X);
  49. foreach ($X as $label => $observation) {
  50. $this->assertTrue(\in_array($label, SampleData\Cereal::CEREALS));
  51. $this->assertCount(145, $observation);
  52. }
  53. }
  54. /**
  55. * @test Y variables
  56. */
  57. public function testYDataVariables()
  58. {
  59. // When
  60. $Y = $this->cereal->getYData();
  61. // Then
  62. foreach ($Y as $observation) {
  63. $this->assertCount(6, $observation);
  64. }
  65. }
  66. /**
  67. * @test Labeled Y data
  68. */
  69. public function testLabeledYData()
  70. {
  71. // When
  72. $Y = $this->cereal->getLabeledYData();
  73. // Then
  74. $this->assertCount(15, $Y);
  75. foreach ($Y as $label => $observation) {
  76. $this->assertTrue(\in_array($label, SampleData\Cereal::CEREALS));
  77. $this->assertCount(6, $observation);
  78. }
  79. }
  80. /**
  81. * @test Ysc variables
  82. */
  83. public function testYscDataVariables()
  84. {
  85. // When
  86. $Ysc = $this->cereal->getYscData();
  87. // Then
  88. foreach ($Ysc as $observation) {
  89. $this->assertCount(6, $observation);
  90. }
  91. }
  92. /**
  93. * @test Labeled Ysc data
  94. */
  95. public function testLabeledYscData()
  96. {
  97. // When
  98. $Ysc = $this->cereal->getLabeledYscData();
  99. // Then
  100. $this->assertCount(15, $Ysc);
  101. foreach ($Ysc as $label => $observation) {
  102. $this->assertTrue(\in_array($label, SampleData\Cereal::CEREALS));
  103. $this->assertCount(6, $observation);
  104. }
  105. }
  106. /**
  107. * @test Scaled center
  108. */
  109. public function testGetScaledCenter()
  110. {
  111. // When
  112. $scaledCenter = $this->cereal->getScaledCenter();
  113. // Then
  114. $this->assertCount(6, $scaledCenter);
  115. }
  116. /**
  117. * @test Scaled scake
  118. */
  119. public function testGetScaledScale()
  120. {
  121. // When
  122. $scaledScale = $this->cereal->getScaledScale();
  123. // Then
  124. $this->assertCount(6, $scaledScale);
  125. }
  126. }