PR Vision v0.1.1: rename from peptide-geo-monitor + QA P2 fixes (#2)
Rename to PR Vision (PRV_/pr-vision); fix www-strip char-mask in competitor display (str_starts_with); make PHPCS a CI gate; remove dead in-run cache. QA: APPROVE — qa-reviews/pr-vision/2026-06-13-c633fdb9e1541386a713a6de12d2ee2ae4239640.md Agent-Session: pr-vision rename v0.1.1 merge
This commit is contained in:
@@ -1,28 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests for the visibility score formula in PGM_Ai_Visibility_Collector.
|
||||
* Tests for the visibility score formula in PRV_Ai_Visibility_Collector.
|
||||
*
|
||||
* Score formula (CONTEXT.md):
|
||||
* base_score = cited_probes / total_probes
|
||||
* position_bonus = Σ(1/our_position for cited) / total_probes
|
||||
* visibility_score = round((base_score + position_bonus) / 2, 4)
|
||||
*
|
||||
* @package PeptideGeoMonitor
|
||||
* @package PrVision
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once __DIR__ . '/../bootstrap.php';
|
||||
|
||||
echo "=== PGM Score Calculation Tests ===\n";
|
||||
echo "=== PRV Score Calculation Tests ===\n";
|
||||
|
||||
// Instantiate with a null ledger (no DB calls in these tests).
|
||||
$collector = new PGM_Ai_Visibility_Collector( null );
|
||||
$collector = new PRV_Ai_Visibility_Collector( null );
|
||||
|
||||
// ── Test: zero total → score 0 ──────────────────────────────────────────
|
||||
|
||||
pgm_test_reset();
|
||||
pgm_assert_equals( 0.0, $collector->compute_score( 0, 0, 0.0 ), 'score: zero total returns 0.0' );
|
||||
prv_test_reset();
|
||||
prv_assert_equals( 0.0, $collector->compute_score( 0, 0, 0.0 ), 'score: zero total returns 0.0' );
|
||||
|
||||
// ── Test: all cited, position 1 ─────────────────────────────────────────
|
||||
|
||||
@@ -30,15 +30,15 @@ pgm_assert_equals( 0.0, $collector->compute_score( 0, 0, 0.0 ), 'score: zero tot
|
||||
// base_score = 10/10 = 1.0
|
||||
// position_bonus = (1+1+1+…)/10 = 10/10 = 1.0
|
||||
// score = (1.0 + 1.0) / 2 = 1.0
|
||||
pgm_test_reset();
|
||||
pgm_assert_equals( 1.0, $collector->compute_score( 10, 10, 10.0 ), 'score: all cited at position 1 → 1.0' );
|
||||
prv_test_reset();
|
||||
prv_assert_equals( 1.0, $collector->compute_score( 10, 10, 10.0 ), 'score: all cited at position 1 → 1.0' );
|
||||
|
||||
// ── Test: none cited ────────────────────────────────────────────────────
|
||||
|
||||
// 10 probes, 0 cited, position_sum=0
|
||||
// base_score = 0, position_bonus = 0 → score = 0
|
||||
pgm_test_reset();
|
||||
pgm_assert_equals( 0.0, $collector->compute_score( 0, 10, 0.0 ), 'score: none cited → 0.0' );
|
||||
prv_test_reset();
|
||||
prv_assert_equals( 0.0, $collector->compute_score( 0, 10, 0.0 ), 'score: none cited → 0.0' );
|
||||
|
||||
// ── Test: half cited at position 2 ──────────────────────────────────────
|
||||
|
||||
@@ -46,9 +46,9 @@ pgm_assert_equals( 0.0, $collector->compute_score( 0, 10, 0.0 ), 'score: none ci
|
||||
// base_score = 5/10 = 0.5
|
||||
// position_bonus = 2.5/10 = 0.25
|
||||
// score = (0.5 + 0.25) / 2 = 0.375
|
||||
pgm_test_reset();
|
||||
prv_test_reset();
|
||||
$score = $collector->compute_score( 5, 10, 2.5 );
|
||||
pgm_assert_equals( 0.375, $score, 'score: half cited at position 2 → 0.375' );
|
||||
prv_assert_equals( 0.375, $score, 'score: half cited at position 2 → 0.375' );
|
||||
|
||||
// ── Test: single probe, cited at position 3 ─────────────────────────────
|
||||
|
||||
@@ -56,25 +56,25 @@ pgm_assert_equals( 0.375, $score, 'score: half cited at position 2 → 0.375' );
|
||||
// base_score = 1.0
|
||||
// position_bonus = 0.3333
|
||||
// score = (1.0 + 0.3333) / 2 ≈ 0.6667 (rounded to 4 decimals)
|
||||
pgm_test_reset();
|
||||
prv_test_reset();
|
||||
$score = $collector->compute_score( 1, 1, 1.0 / 3.0 );
|
||||
pgm_assert_equals( 0.6667, $score, 'score: single probe cited at position 3 → 0.6667' );
|
||||
prv_assert_equals( 0.6667, $score, 'score: single probe cited at position 3 → 0.6667' );
|
||||
|
||||
// ── Test: score is bounded [0, 1] ───────────────────────────────────────
|
||||
|
||||
// Extreme: position_sum could theoretically exceed total but that's logically
|
||||
// impossible with 1-based positions (position_sum ≤ cited_count ≤ total).
|
||||
// Verify edge case: 1 probe, 1 cited, position 1
|
||||
pgm_test_reset();
|
||||
pgm_assert( $collector->compute_score( 1, 1, 1.0 ) <= 1.0, 'score: never exceeds 1.0' );
|
||||
pgm_assert( $collector->compute_score( 0, 10, 0.0 ) >= 0.0, 'score: never below 0.0' );
|
||||
prv_test_reset();
|
||||
prv_assert( $collector->compute_score( 1, 1, 1.0 ) <= 1.0, 'score: never exceeds 1.0' );
|
||||
prv_assert( $collector->compute_score( 0, 10, 0.0 ) >= 0.0, 'score: never below 0.0' );
|
||||
|
||||
// ── Test: precision — 4 decimal places ──────────────────────────────────
|
||||
|
||||
pgm_test_reset();
|
||||
prv_test_reset();
|
||||
$score = $collector->compute_score( 3, 7, 1.5 );
|
||||
// base = 3/7 ≈ 0.4286, bonus = 1.5/7 ≈ 0.2143, avg ≈ 0.3214
|
||||
$expected = round( ( 3.0 / 7.0 + 1.5 / 7.0 ) / 2.0, 4 );
|
||||
pgm_assert_equals( $expected, $score, 'score: 4-decimal precision maintained' );
|
||||
prv_assert_equals( $expected, $score, 'score: 4-decimal precision maintained' );
|
||||
|
||||
exit( pgm_test_summary() );
|
||||
exit( prv_test_summary() );
|
||||
|
||||
Reference in New Issue
Block a user