PeopleTest.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <?php
  2. namespace MathPHP\Tests\SampleData;
  3. use MathPHP\SampleData;
  4. class PeopleTest extends \PHPUnit\Framework\TestCase
  5. {
  6. /** @var SampleData\People */
  7. private $people;
  8. public function setUp(): void
  9. {
  10. $this->people = new SampleData\People();
  11. }
  12. /**
  13. * @test 32 observations
  14. */
  15. public function testDataHas32Observations()
  16. {
  17. // When
  18. $data = $this->people->getData();
  19. // Then
  20. $this->assertCount(32, $data);
  21. }
  22. /**
  23. * @test 11 variables
  24. */
  25. public function testDataHas12Variables()
  26. {
  27. // When
  28. $data = $this->people->getData();
  29. // Then
  30. foreach ($data as $observation) {
  31. $this->assertCount(12, $observation);
  32. }
  33. }
  34. /**
  35. * @test 16 names
  36. */
  37. public function testNumberOfNames()
  38. {
  39. // When
  40. $names = $this->people->getNames();
  41. // Then
  42. $this->assertCount(32, $names);
  43. }
  44. /**
  45. * @test Labeled data
  46. * @dataProvider dataProviderForLabeledData
  47. * @param string $model
  48. * @param array $expectedData
  49. */
  50. public function testLabeledData(string $model, array $expectedData)
  51. {
  52. // When
  53. $labeledData = $this->people->getLabeledData();
  54. // Then
  55. $this->assertEquals($expectedData, $labeledData[$model]);
  56. }
  57. /**
  58. * @return array (model, data)
  59. */
  60. public function dataProviderForLabeledData(): array
  61. {
  62. return [
  63. [
  64. 'Lars',
  65. [
  66. 'height' => 198,
  67. 'weight' => 92,
  68. 'hairLength' => -1,
  69. 'shoeSize' => 48,
  70. 'age' => 48,
  71. 'income' => 45000,
  72. 'beer' => 420,
  73. 'wine' => 115,
  74. 'sex' => -1,
  75. 'swim' => 98,
  76. 'region' => -1,
  77. 'iq' => 100,
  78. ]
  79. ],
  80. [
  81. 'Alessandro',
  82. [
  83. 'height' => 181,
  84. 'weight' => 75,
  85. 'hairLength' => -1,
  86. 'shoeSize' => 43,
  87. 'age' => 42,
  88. 'income' => 31000,
  89. 'beer' => 198,
  90. 'wine' => 161,
  91. 'sex' => -1,
  92. 'swim' => 83,
  93. 'region' => 1,
  94. 'iq' => 105,
  95. ]
  96. ],
  97. [
  98. 'Romina',
  99. [
  100. 'height' => 160,
  101. 'weight' => 48,
  102. 'hairLength' => 1,
  103. 'shoeSize' => 35,
  104. 'age' => 40,
  105. 'income' => 31000,
  106. 'beer' => 118,
  107. 'wine' => 198,
  108. 'sex' => 1,
  109. 'swim' => 74,
  110. 'region' => 1,
  111. 'iq' => 129,
  112. ]
  113. ],
  114. ];
  115. }
  116. /**
  117. * @test 16 height observations
  118. */
  119. public function testNumberOfPersonData()
  120. {
  121. // Given
  122. $expected = [
  123. 'height' => 198,
  124. 'weight' => 92,
  125. 'hairLength' => -1,
  126. 'shoeSize' => 48,
  127. 'age' => 48,
  128. 'income' => 45000,
  129. 'beer' => 420,
  130. 'wine' => 115,
  131. 'sex' => -1,
  132. 'swim' => 98,
  133. 'region' => -1,
  134. 'iq' => 100,
  135. ];
  136. // When
  137. $observation = $this->people->getPersonData('Lars');
  138. // Then
  139. $this->assertEquals($expected, $observation);
  140. }
  141. /**
  142. * @test 16 height observations
  143. */
  144. public function testNumberOfHeight()
  145. {
  146. // When
  147. $observations = $this->people->getHeight();
  148. // Then
  149. $this->assertCount(32, $observations);
  150. }
  151. /**
  152. * @test 32 weight observations
  153. */
  154. public function testNumberOfWeight()
  155. {
  156. // When
  157. $observations = $this->people->getWeight();
  158. // Then
  159. $this->assertCount(32, $observations);
  160. }
  161. /**
  162. * @test 32 hair length observations
  163. */
  164. public function testNumberOfHairLength()
  165. {
  166. // When
  167. $observations = $this->people->getHairLength();
  168. // Then
  169. $this->assertCount(32, $observations);
  170. }
  171. /**
  172. * @test 32 show size observations
  173. */
  174. public function testNumberOfShowSize()
  175. {
  176. // When
  177. $observations = $this->people->getShowSize();
  178. // Then
  179. $this->assertCount(32, $observations);
  180. }
  181. /**
  182. * @test 32 age observations
  183. */
  184. public function testNumberOfAge()
  185. {
  186. // When
  187. $observations = $this->people->getAge();
  188. // Then
  189. $this->assertCount(32, $observations);
  190. }
  191. /**
  192. * @test 32 income observations
  193. */
  194. public function testNumberOfIncome()
  195. {
  196. // When
  197. $observations = $this->people->getIncome();
  198. // Then
  199. $this->assertCount(32, $observations);
  200. }
  201. /**
  202. * @test 32 beer observations
  203. */
  204. public function testNumberOfBeer()
  205. {
  206. // When
  207. $observations = $this->people->getBeer();
  208. // Then
  209. $this->assertCount(32, $observations);
  210. }
  211. /**
  212. * @test 32 wine observations
  213. */
  214. public function testNumberOfWine()
  215. {
  216. // When
  217. $observations = $this->people->getWine();
  218. // Then
  219. $this->assertCount(32, $observations);
  220. }
  221. /**
  222. * @test 32 sex observations
  223. */
  224. public function testNumberOfSex()
  225. {
  226. // When
  227. $observations = $this->people->getSex();
  228. // Then
  229. $this->assertCount(32, $observations);
  230. }
  231. /**
  232. * @test 32 swim observations
  233. */
  234. public function testNumberOfSwim()
  235. {
  236. // When
  237. $observations = $this->people->getSwim();
  238. // Then
  239. $this->assertCount(32, $observations);
  240. }
  241. /**
  242. * @test 32 region observations
  243. */
  244. public function testNumberOfRegion()
  245. {
  246. // When
  247. $observations = $this->people->getRegion();
  248. // Then
  249. $this->assertCount(32, $observations);
  250. }
  251. /**
  252. * @test 32 iq observations
  253. */
  254. public function testNumberOfIq()
  255. {
  256. // When
  257. $observations = $this->people->getIq();
  258. // Then
  259. $this->assertCount(32, $observations);
  260. }
  261. }