b6539802e0
- mv src/multi_swarm → src/multi_swarm_core/multi_swarm_core (member layout) - sed-replace globale degli import: from/import multi_swarm.* → multi_swarm_core.* - 115 occorrenze aggiornate in src/ scripts/ tests/ - multi_swarm_coevolutive (nome repo) preservato dal word boundary Pre-condizione per il setup uv workspace della Fase 3. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
27 lines
817 B
Python
27 lines
817 B
Python
import math
|
|
|
|
import pytest
|
|
|
|
from multi_swarm_core.ga.summary import generation_summary
|
|
|
|
|
|
def test_summary_basic_stats():
|
|
fitnesses = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]
|
|
s = generation_summary(fitnesses, n_bins=5)
|
|
assert s["median"] == pytest.approx(0.45, abs=0.05)
|
|
assert s["max"] == pytest.approx(0.9)
|
|
assert 0.0 <= s["entropy"] <= math.log(5) + 0.01
|
|
|
|
|
|
def test_summary_uniform_high_entropy():
|
|
fitnesses = [0.1 * i for i in range(20)]
|
|
s_uniform = generation_summary(fitnesses, n_bins=5)
|
|
s_concentrated = generation_summary([0.5] * 20, n_bins=5)
|
|
assert s_uniform["entropy"] > s_concentrated["entropy"]
|
|
|
|
|
|
def test_summary_p90():
|
|
fitnesses = list(range(100))
|
|
s = generation_summary([float(x) for x in fitnesses], n_bins=10)
|
|
assert 88.0 <= s["p90"] <= 91.0
|