| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- declare(strict_types=1);
- namespace App\Tests\Unit\Reputation;
- use App\Domain\Reputation\Decay;
- use App\Domain\Reputation\DecayFunction;
- use PHPUnit\Framework\TestCase;
- /**
- * Hand-computed reference values for both decay shapes. The exponential
- * cases hit half-life multiples so the answers are clean fractions.
- */
- final class DecayTest extends TestCase
- {
- public function testLinearAtZeroReturnsFullWeight(): void
- {
- self::assertSame(1.0, Decay::value(DecayFunction::Linear, 0.0, 30.0));
- }
- public function testLinearMidwayReturnsHalf(): void
- {
- self::assertEqualsWithDelta(0.5, Decay::value(DecayFunction::Linear, 15.0, 30.0), 1e-9);
- }
- public function testLinearAtOrPastDecayParamClampsToZero(): void
- {
- self::assertSame(0.0, Decay::value(DecayFunction::Linear, 30.0, 30.0));
- self::assertSame(0.0, Decay::value(DecayFunction::Linear, 100.0, 30.0));
- }
- public function testExponentialAtZeroReturnsFullWeight(): void
- {
- self::assertSame(1.0, Decay::value(DecayFunction::Exponential, 0.0, 14.0));
- }
- public function testExponentialAtOneHalfLifeReturnsHalf(): void
- {
- self::assertEqualsWithDelta(0.5, Decay::value(DecayFunction::Exponential, 14.0, 14.0), 1e-9);
- }
- public function testExponentialAtTwoHalfLivesReturnsQuarter(): void
- {
- self::assertEqualsWithDelta(0.25, Decay::value(DecayFunction::Exponential, 28.0, 14.0), 1e-9);
- }
- public function testNegativeAgeClampsToFullWeight(): void
- {
- // Future-dated reports shouldn't happen, but if they do they count
- // at full weight rather than blowing up.
- self::assertSame(1.0, Decay::value(DecayFunction::Linear, -5.0, 30.0));
- self::assertSame(1.0, Decay::value(DecayFunction::Exponential, -5.0, 14.0));
- }
- public function testZeroDecayParamReturnsZero(): void
- {
- self::assertSame(0.0, Decay::value(DecayFunction::Linear, 5.0, 0.0));
- self::assertSame(0.0, Decay::value(DecayFunction::Exponential, 5.0, 0.0));
- }
- }
|