123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- <?php
- namespace MathPHP\Tests\SampleData;
- use MathPHP\SampleData;
- class UsArrestsTest extends \PHPUnit\Framework\TestCase
- {
- /** @var SampleData\UsArrests */
- private $usArrests;
- public function setUp(): void
- {
- $this->usArrests = new SampleData\UsArrests();
- }
- /**
- * @test 50 observations
- */
- public function testDataHas50Observations()
- {
- // When
- $data = $this->usArrests->getData();
- // Then
- $this->assertCount(50, $data);
- }
- /**
- * @test 4 variables
- */
- public function testDataHas4Variables()
- {
- // When
- $data = $this->usArrests->getData();
- // Then
- foreach ($data as $observation) {
- $this->assertCount(4, $observation);
- }
- }
- /**
- * @test 50 states
- */
- public function testNumberOfModels()
- {
- // When
- $models = $this->usArrests->getStates();
- // Then
- $this->assertCount(50, $models);
- }
- /**
- * @test State names
- */
- public function testStateNames()
- {
- // Given
- $sampleOfStateNames = ['Alabama', 'Alaska', 'Texas', 'Wyoming'];
- $states = $this->usArrests->getStates();
- // When
- foreach ($sampleOfStateNames as $state) {
- // Then
- $this->assertTrue(\in_array($state, $states));
- }
- }
- /**
- * @test Labeled data
- * @dataProvider dataProviderForLabeledData
- * @param string $model
- * @param array $expectedData
- */
- public function testLabeledData(string $model, array $expectedData)
- {
- // When
- $labeledData = $this->usArrests->getLabeledData();
- // Then
- $this->assertEquals($expectedData, $labeledData[$model]);
- }
- /**
- * @test Model data
- * @dataProvider dataProviderForLabeledData
- * @param string $state
- * @param array $expectedData
- */
- public function testGetStateData(string $state, array $expectedData)
- {
- // When
- $data = $this->usArrests->getStateData($state);
- // Then
- $this->assertEquals($expectedData, $data);
- }
- /**
- * @return array (model, data)
- */
- public function dataProviderForLabeledData(): array
- {
- return [
- [
- 'Alabama',
- [
- 'murder' => 13.2,
- 'assault' => 236,
- 'urbanPop' => 58,
- 'rape' => 21.2,
- ]
- ],
- [
- 'New York',
- [
- 'murder' => 11.1,
- 'assault' => 254,
- 'urbanPop' => 86,
- 'rape' => 26.1,
- ]
- ],
- [
- 'Wyoming',
- [
- 'murder' => 6.8,
- 'assault' => 161,
- 'urbanPop' => 60,
- 'rape' => 15.6,
- ]
- ],
- ];
- }
- /**
- * @test 50 murder observations
- */
- public function testNumberOfMurders()
- {
- // When
- $observations = $this->usArrests->getMurder();
- // Then
- $this->assertCount(50, $observations);
- }
- /**
- * @test 50 assault observations
- */
- public function testNumberOfAssaults()
- {
- // When
- $observations = $this->usArrests->getAssault();
- // Then
- $this->assertCount(50, $observations);
- }
- /**
- * @test 50 urbanPop observations
- */
- public function testNumberOfUrbanPops()
- {
- // When
- $observations = $this->usArrests->getUrbanPop();
- // Then
- $this->assertCount(50, $observations);
- }
- /**
- * @test 50 rape observations
- */
- public function testNumberOfRapes()
- {
- // When
- $observations = $this->usArrests->getRape();
- // Then
- $this->assertCount(50, $observations);
- }
- }
|