mirror of
https://github.com/jez500/pricebuddy.git
synced 2026-11-24 19:58:13 +01:00
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
33 lines
1019 B
PHP
33 lines
1019 B
PHP
<?php
|
|
|
|
namespace Tests\Unit\Services\Insights;
|
|
|
|
use App\Services\Insights\DistributionCalculator;
|
|
use Tests\TestCase;
|
|
|
|
class DistributionCalculatorTest extends TestCase
|
|
{
|
|
public function test_it_bins_prices_and_flags_current_band(): void
|
|
{
|
|
$series = collect([
|
|
'a' => 40, 'b' => 41, 'c' => 42, 'd' => 50, 'e' => 60,
|
|
'f' => 70, 'g' => 75, 'h' => 80,
|
|
]);
|
|
|
|
$result = (new DistributionCalculator)->calculate($series, 41.0, 4);
|
|
|
|
$this->assertCount(4, $result->bins);
|
|
$this->assertSame(8, array_sum(array_column($result->bins, 'count')));
|
|
$this->assertTrue($result->bins[0]['isCurrent']);
|
|
$this->assertSame(38, $result->currentBinPercent);
|
|
}
|
|
|
|
public function test_flat_series_returns_single_full_bin(): void
|
|
{
|
|
$result = (new DistributionCalculator)->calculate(collect(['a' => 50, 'b' => 50]), 50.0, 8);
|
|
|
|
$this->assertCount(1, $result->bins);
|
|
$this->assertSame(100, $result->currentBinPercent);
|
|
}
|
|
}
|