Root cause: test-runner was giving overly optimistic results due to: 1. Context bias - knew the implementation, tended to defend it 2. No actual visual comparison - just wrote 'ACCEPTABLE' without looking 3. No structural validation - accepted 35x scale differences as 'acceptable' Solution: - New result-verifier agent that performs blind visual comparison - Strict pass/fail criteria for structural validation - Updated test-runner to use result-verifier for each figure - Clear guidelines: structural mismatches = FAIL, not ACCEPTABLE Test result: verifier correctly identified Fig3 as FAIL with 7 specific issues: - Wrong X-axis variable (channels vs power) - Wrong Y-axis scale (5x difference) - Wrong curve count (5 vs 4) - etc.
45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
"""
|
|
tests/test_allocator.py
|
|
"""
|
|
|
|
import pytest
|
|
import numpy as np
|
|
from src.models.environment import EnvironmentConfig
|
|
from src.models.semantic_model import SemanticSurrogate
|
|
from src.models.allocator import ResourceAllocator
|
|
|
|
|
|
def test_allocator_initialization():
|
|
env_config = EnvironmentConfig(num_users=3, num_channels=4, bandwidth=1e6)
|
|
surrogate = SemanticSurrogate(L=12)
|
|
allocator = ResourceAllocator(surrogate, env_config, K_max=8)
|
|
|
|
assert allocator.K_max == 8
|
|
|
|
|
|
def test_optimize_semantic_aware():
|
|
env_config = EnvironmentConfig(num_users=2, num_channels=3, bandwidth=1e6)
|
|
surrogate = SemanticSurrogate(L=12)
|
|
allocator = ResourceAllocator(surrogate, env_config, K_max=4)
|
|
|
|
# Mock SNR values
|
|
snr_linear = np.array([[10.0, 100.0, 1000.0], [50.0, 20.0, 500.0]])
|
|
|
|
optimal_k, assignment, total_sse = allocator.optimize_semantic_aware(snr_linear)
|
|
|
|
assert optimal_k.shape == (2,)
|
|
assert assignment.shape == (2, 3)
|
|
assert np.all(assignment.sum(axis=1) == 1) # Each user gets 1 channel
|
|
assert np.all(assignment.sum(axis=0) <= 1) # Each channel used by max 1 user
|
|
|
|
|
|
def test_evaluate_fixed_k():
|
|
env_config = EnvironmentConfig(num_users=2, num_channels=2, bandwidth=1e6)
|
|
surrogate = SemanticSurrogate(L=12)
|
|
allocator = ResourceAllocator(surrogate, env_config, K_max=4)
|
|
|
|
snr_linear = np.array([[10.0, 100.0], [50.0, 20.0]])
|
|
|
|
total_sse = allocator.evaluate_fixed_k(snr_linear, k_n=4)
|
|
assert total_sse > 0
|