ToothGrowthTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace MathPHP\Tests\SampleData;
  3. use MathPHP\SampleData;
  4. class ToothGrowthTest extends \PHPUnit\Framework\TestCase
  5. {
  6. /** @var SampleData\ToothGrowth */
  7. private $toothGrowth;
  8. public function setUp(): void
  9. {
  10. $this->toothGrowth = new SampleData\ToothGrowth();
  11. }
  12. /**
  13. * @test 60 observations
  14. */
  15. public function testDataHas60Observations()
  16. {
  17. // When
  18. $data = $this->toothGrowth->getData();
  19. // Then
  20. $this->assertCount(60, $data);
  21. }
  22. /**
  23. * @test 3 variables
  24. */
  25. public function testDataHas3Variables()
  26. {
  27. // When
  28. $data = $this->toothGrowth->getData();
  29. // Then
  30. foreach ($data as $observation) {
  31. $this->assertCount(3, $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->toothGrowth->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. 'len' => 4.2,
  57. 'supp' => 'VC',
  58. 'dose' => 0.5,
  59. ]
  60. ],
  61. [
  62. 29,
  63. [
  64. 'len' => 29.5,
  65. 'supp' => 'VC',
  66. 'dose' => 2.0,
  67. ]
  68. ],
  69. [
  70. 59,
  71. [
  72. 'len' => 23.0,
  73. 'supp' => 'OJ',
  74. 'dose' => 2.0,
  75. ]
  76. ],
  77. ];
  78. }
  79. /**
  80. * @test 60 length observations
  81. */
  82. public function testNumberOfLength()
  83. {
  84. // When
  85. $observations = $this->toothGrowth->getLen();
  86. // Then
  87. $this->assertCount(60, $observations);
  88. }
  89. /**
  90. * @test 60 supplement observations
  91. */
  92. public function testNumberOfSupplementTypes()
  93. {
  94. // When
  95. $observations = $this->toothGrowth->getSupp();
  96. // Then
  97. $this->assertCount(60, $observations);
  98. }
  99. /**
  100. * @test 60 dose observations
  101. */
  102. public function testNumberOfDoses()
  103. {
  104. // When
  105. $observations = $this->toothGrowth->getDose();
  106. // Then
  107. $this->assertCount(60, $observations);
  108. }
  109. }