Files
pr-vision/tests/unit/ScoreCalcTest.php
peptiderepo 01a9356c16 v0.3.2 — adopt estate CI: PHPUnit suite + reusable pipeline + governance workflows
- Convert 17 hand-rolled tests to PHPUnit TestCases (tests: stubs pattern)
  P0 security tests preserved: key-leak/encryption (KeyStoreTest),
  capture-allowlist/executor-path sentinel (CaptureWriterTest)
- Add phpunit.xml.dist + update tests/bootstrap.php (Composer autoloader first)
- Add phpunit/phpunit ^9.6 + yoast/phpunit-polyfills ^2.0 to require-dev
- composer test -> vendor/bin/phpunit --configuration phpunit.xml.dist
- ci.yml: thin caller of peptide-e2e reusable CI (tests: stubs, has_js: true,
  workflow_call trigger, permissions: contents: write)
- deploy.yml: estate pattern caller of peptide-e2e deploy-app.yml@main
  (target_path: wp-content/plugins/pr-vision, gated on reusable CI)
  Pull-deploy on Hostinger stays as break-glass
- Add cto-review.yml (Haiku-only, A/B panel dropped 2026-06-12)
- Add main-push-audit.yml (direct-push tripwire)

Agent-Session: claude-adopt-ci-20260616
2026-06-16 15:25:22 +00:00

58 lines
1.7 KiB
PHP

<?php
/**
* Tests for the visibility score formula in PRV_Ai_Visibility_Collector.
*
* Formula: score = round((cited/total + position_sum/total) / 2, 4)
*
* @package PrVision
*/
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
/**
* @covers PRV_Ai_Visibility_Collector
*/
class ScoreCalcTest extends TestCase {
private PRV_Ai_Visibility_Collector $collector;
protected function setUp(): void {
prv_test_reset();
$this->collector = new PRV_Ai_Visibility_Collector( null );
}
public function test_zero_total_returns_zero(): void {
$this->assertSame( 0.0, $this->collector->compute_score( 0, 0, 0.0 ) );
}
public function test_all_cited_position_1_returns_1(): void {
$this->assertSame( 1.0, $this->collector->compute_score( 10, 10, 10.0 ) );
}
public function test_none_cited_returns_zero(): void {
$this->assertSame( 0.0, $this->collector->compute_score( 0, 10, 0.0 ) );
}
public function test_half_cited_at_position_2(): void {
// base=0.5, bonus=0.25, score=0.375
$this->assertSame( 0.375, $this->collector->compute_score( 5, 10, 2.5 ) );
}
public function test_single_probe_cited_at_position_3(): void {
// base=1.0, bonus=0.3333, score=0.6667
$this->assertSame( 0.6667, $this->collector->compute_score( 1, 1, 1.0 / 3.0 ) );
}
public function test_score_bounded_within_0_and_1(): void {
$this->assertLessThanOrEqual( 1.0, $this->collector->compute_score( 1, 1, 1.0 ) );
$this->assertGreaterThanOrEqual( 0.0, $this->collector->compute_score( 0, 10, 0.0 ) );
}
public function test_four_decimal_precision(): void {
$expected = round( ( 3.0 / 7.0 + 1.5 / 7.0 ) / 2.0, 4 );
$this->assertSame( $expected, $this->collector->compute_score( 3, 7, 1.5 ) );
}
}