123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- <?php
- namespace MathPHP\Tests\SampleData;
- use MathPHP\SampleData;
- class PeopleTest extends \PHPUnit\Framework\TestCase
- {
- /** @var SampleData\People */
- private $people;
- public function setUp(): void
- {
- $this->people = new SampleData\People();
- }
- /**
- * @test 32 observations
- */
- public function testDataHas32Observations()
- {
- // When
- $data = $this->people->getData();
- // Then
- $this->assertCount(32, $data);
- }
- /**
- * @test 11 variables
- */
- public function testDataHas12Variables()
- {
- // When
- $data = $this->people->getData();
- // Then
- foreach ($data as $observation) {
- $this->assertCount(12, $observation);
- }
- }
- /**
- * @test 16 names
- */
- public function testNumberOfNames()
- {
- // When
- $names = $this->people->getNames();
- // Then
- $this->assertCount(32, $names);
- }
- /**
- * @test Labeled data
- * @dataProvider dataProviderForLabeledData
- * @param string $model
- * @param array $expectedData
- */
- public function testLabeledData(string $model, array $expectedData)
- {
- // When
- $labeledData = $this->people->getLabeledData();
- // Then
- $this->assertEquals($expectedData, $labeledData[$model]);
- }
- /**
- * @return array (model, data)
- */
- public function dataProviderForLabeledData(): array
- {
- return [
- [
- 'Lars',
- [
- 'height' => 198,
- 'weight' => 92,
- 'hairLength' => -1,
- 'shoeSize' => 48,
- 'age' => 48,
- 'income' => 45000,
- 'beer' => 420,
- 'wine' => 115,
- 'sex' => -1,
- 'swim' => 98,
- 'region' => -1,
- 'iq' => 100,
- ]
- ],
- [
- 'Alessandro',
- [
- 'height' => 181,
- 'weight' => 75,
- 'hairLength' => -1,
- 'shoeSize' => 43,
- 'age' => 42,
- 'income' => 31000,
- 'beer' => 198,
- 'wine' => 161,
- 'sex' => -1,
- 'swim' => 83,
- 'region' => 1,
- 'iq' => 105,
- ]
- ],
- [
- 'Romina',
- [
- 'height' => 160,
- 'weight' => 48,
- 'hairLength' => 1,
- 'shoeSize' => 35,
- 'age' => 40,
- 'income' => 31000,
- 'beer' => 118,
- 'wine' => 198,
- 'sex' => 1,
- 'swim' => 74,
- 'region' => 1,
- 'iq' => 129,
- ]
- ],
- ];
- }
- /**
- * @test 16 height observations
- */
- public function testNumberOfPersonData()
- {
- // Given
- $expected = [
- 'height' => 198,
- 'weight' => 92,
- 'hairLength' => -1,
- 'shoeSize' => 48,
- 'age' => 48,
- 'income' => 45000,
- 'beer' => 420,
- 'wine' => 115,
- 'sex' => -1,
- 'swim' => 98,
- 'region' => -1,
- 'iq' => 100,
- ];
- // When
- $observation = $this->people->getPersonData('Lars');
- // Then
- $this->assertEquals($expected, $observation);
- }
- /**
- * @test 16 height observations
- */
- public function testNumberOfHeight()
- {
- // When
- $observations = $this->people->getHeight();
- // Then
- $this->assertCount(32, $observations);
- }
- /**
- * @test 32 weight observations
- */
- public function testNumberOfWeight()
- {
- // When
- $observations = $this->people->getWeight();
- // Then
- $this->assertCount(32, $observations);
- }
- /**
- * @test 32 hair length observations
- */
- public function testNumberOfHairLength()
- {
- // When
- $observations = $this->people->getHairLength();
- // Then
- $this->assertCount(32, $observations);
- }
- /**
- * @test 32 show size observations
- */
- public function testNumberOfShowSize()
- {
- // When
- $observations = $this->people->getShowSize();
- // Then
- $this->assertCount(32, $observations);
- }
- /**
- * @test 32 age observations
- */
- public function testNumberOfAge()
- {
- // When
- $observations = $this->people->getAge();
- // Then
- $this->assertCount(32, $observations);
- }
- /**
- * @test 32 income observations
- */
- public function testNumberOfIncome()
- {
- // When
- $observations = $this->people->getIncome();
- // Then
- $this->assertCount(32, $observations);
- }
- /**
- * @test 32 beer observations
- */
- public function testNumberOfBeer()
- {
- // When
- $observations = $this->people->getBeer();
- // Then
- $this->assertCount(32, $observations);
- }
- /**
- * @test 32 wine observations
- */
- public function testNumberOfWine()
- {
- // When
- $observations = $this->people->getWine();
- // Then
- $this->assertCount(32, $observations);
- }
- /**
- * @test 32 sex observations
- */
- public function testNumberOfSex()
- {
- // When
- $observations = $this->people->getSex();
- // Then
- $this->assertCount(32, $observations);
- }
- /**
- * @test 32 swim observations
- */
- public function testNumberOfSwim()
- {
- // When
- $observations = $this->people->getSwim();
- // Then
- $this->assertCount(32, $observations);
- }
- /**
- * @test 32 region observations
- */
- public function testNumberOfRegion()
- {
- // When
- $observations = $this->people->getRegion();
- // Then
- $this->assertCount(32, $observations);
- }
- /**
- * @test 32 iq observations
- */
- public function testNumberOfIq()
- {
- // When
- $observations = $this->people->getIq();
- // Then
- $this->assertCount(32, $observations);
- }
- }
|