123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- <?php
- namespace MathPHP\Tests\Probability\Distribution\Continuous;
- use MathPHP\Probability\Distribution\Continuous\DiracDelta;
- class DiracDeltaTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @test pdf
- * @dataProvider dataProviderForPdf
- * @param float $x
- * @param float $expectedPdf
- */
- public function testPdf(float $x, float $expectedPdf)
- {
- // Given
- $dirac = new DiracDelta();
- // When
- $pdf = $dirac->pdf($x);
- // Then
- $this->assertEquals($expectedPdf, $pdf);
- }
- /**
- * @return array [x, pdf]
- */
- public function dataProviderForPdf(): array
- {
- return [
- [-100, 0],
- [-12, 0],
- [-2, 0],
- [-1, 0],
- [-0.5, 0],
- [0, \INF],
- [0.5, 0],
- [1, 0],
- [2, 0],
- [12, 0],
- [100, 0],
- ];
- }
- /**
- * @testCase cdf
- * @dataProvider dataProviderForCdf
- * @param float $x
- * @param int $expectedCdf
- */
- public function testCdf(float $x, int $expectedCdf)
- {
- // Given
- $dirac = new DiracDelta();
- // When
- $cdf = $dirac->cdf($x);
- // Then
- $this->assertSame($expectedCdf, $cdf);
- }
- /**
- * @return array [x, cdf]
- */
- public function dataProviderForCdf(): array
- {
- return [
- [-100, 0],
- [-12, 0],
- [-2, 0],
- [-1, 0],
- [-0.5, 0],
- [0, 1],
- [0.5, 1],
- [1, 1],
- [2, 1],
- [12, 1],
- [100, 1],
- ];
- }
- /**
- * @testCase inverse is always 0
- */
- public function testInverse()
- {
- // Given
- $diracDelta = new DiracDelta();
- foreach (\range(-10, 10, 0.5) as $p) {
- // When
- $inverse = $diracDelta->inverse($p);
- // Then
- $this->assertEquals(0, $inverse);
- }
- }
- /**
- * @testCase rand is always 0
- */
- public function testRand()
- {
- // Given
- $diracDelta = new DiracDelta();
- foreach (\range(-10, 10, 0.5) as $_) {
- // When
- $rand = $diracDelta->rand();
- // Then
- $this->assertEquals(0, $rand);
- }
- }
- /**
- * @testCase mean is always 0
- */
- public function testMean()
- {
- // Given
- $diracDelta = new DiracDelta();
- foreach (\range(-10, 10, 0.5) as $_) {
- // When
- $mean = $diracDelta->mean();
- // Then
- $this->assertEquals(0, $mean);
- }
- }
- /**
- * @testCase median is always 0
- */
- public function testMedian()
- {
- // Given
- $diracDelta = new DiracDelta();
- foreach (\range(-10, 10, 0.5) as $_) {
- // When
- $median = $diracDelta->median();
- // Then
- $this->assertEquals(0, $median);
- }
- }
- /**
- * @testCase mode is always 0
- */
- public function testMode()
- {
- // Given
- $diracDelta = new DiracDelta();
- foreach (\range(-10, 10, 0.5) as $_) {
- // When
- $mode = $diracDelta->mode();
- // Then
- $this->assertEquals(0, $mode);
- }
- }
- }
|