Files
pricebuddy/tests/Unit/Services/Insights/PercentileCalculatorTest.php
Jeremy d1a8f1d009 feat: product insights tab
Add a Product Insights tab backed by a suite of price-analysis calculators and a
redesigned price history chart.

- Insights calculators: listing-history and daily best-price series builders,
  price stats, percentile, deal score, distribution, drop events, store showdown,
  seasonality, availability timeline, and target tracker
- ProductInsights aggregator service composing the calculators
- Price history chart: best-price and target datasets, best-price line honours the
  unit/retail filter, horizontal scroll on mobile
- Rename the History tab to Insights with consistent heading styling
- Feature and unit test coverage, plus review-feedback fixes
2026-06-18 23:13:14 +10:00

29 lines
851 B
PHP

<?php
namespace Tests\Unit\Services\Insights;
use App\Services\Insights\PercentileCalculator;
use Tests\TestCase;
class PercentileCalculatorTest extends TestCase
{
public function test_it_reports_fraction_of_days_more_expensive_than_current(): void
{
$series = collect([
'a' => 60, 'b' => 58, 'c' => 55, 'd' => 50, 'e' => 48,
'f' => 47, 'g' => 46, 'h' => 44, 'i' => 42, 'j' => 41,
]);
$result = (new PercentileCalculator)->calculate($series, 42.0);
$this->assertSame(80, $result->percentCheaperThan);
$this->assertEqualsWithDelta(0.8, $result->beatFraction, 0.001);
}
public function test_empty_series_is_zero(): void
{
$result = (new PercentileCalculator)->calculate(collect(), 10.0);
$this->assertSame(0, $result->percentCheaperThan);
}
}