fedi-feed-router/tests/Unit/Dashboard/Stats/BreakdownResultTest.php

58 lines
1.6 KiB
PHP

<?php
namespace Tests\Unit\Dashboard\Stats;
use App\Dashboard\Stats\Breakdown;
use App\Dashboard\Stats\BreakdownResult;
use Tests\TestCase;
class BreakdownResultTest extends TestCase
{
public function test_it_sums_its_rows(): void
{
$result = new BreakdownResult([
new Breakdown('A', 3),
new Breakdown('B', 4),
]);
$this->assertSame(7, $result->total());
}
public function test_it_reports_a_zero_total_when_empty(): void
{
$this->assertSame(0, (new BreakdownResult([]))->total());
}
public function test_it_calculates_a_row_share_of_the_total(): void
{
$result = new BreakdownResult([
new Breakdown('A', 3),
new Breakdown('B', 1),
]);
$this->assertSame(75.0, $result->shareOf($result->rows[0]));
$this->assertSame(25.0, $result->shareOf($result->rows[1]));
}
public function test_it_reports_a_zero_share_when_nothing_was_counted(): void
{
$result = new BreakdownResult([new Breakdown('A', 0)]);
$this->assertSame(0.0, $result->shareOf($result->rows[0]));
}
public function test_it_has_no_data_without_rows(): void
{
$this->assertTrue((new BreakdownResult([]))->isEmpty());
}
public function test_it_has_no_data_when_every_row_is_zero(): void
{
$this->assertTrue((new BreakdownResult([new Breakdown('A', 0)]))->isEmpty());
}
public function test_it_has_data_when_any_row_is_counted(): void
{
$this->assertFalse((new BreakdownResult([new Breakdown('A', 1)]))->isEmpty());
}
}