Pular para o conteúdo principal

persona_db/tests/unit/test_base_engines.py

Unit tests for Agent 2 engines: rng, socio, health.

Self-contained, deterministic, fixed-seed. Uses pytest.importorskip for optional deps so collection never fails.

:::info Fonte Módulo persona_db.tests.unit.test_base_engines — 434 linhas · 3 classe(s) · 0 função(ões) pública(s). Ver no GitHub :::

class TestSeededRNG​

Determinism and distribution basics for SeededRNG.

TesteO que verifica
test_deterministic_same_paramsSame seed+persona+domain => identical sequences.
test_fork_different_personaDifferent persona => different sequences.
test_fork_different_domainDifferent domain => different sequences.
test_fork_respects_saltPending salt => different sequences from base fork.
test_bernoulli_distributionOver 1000 draws at p=0.3, fraction within [25%, 35%].
test_bernoulli_returns_bool—
test_normal_clipped_boundsnormal_clipped must respect low/high bounds.
test_normal_clipped_deterministic—
test_choice_with_weights—
test_choice_unweighted—
test_beta_sample_range—
test_integer_inclusive—
test_integer_returns_int—
test_dirichlet_sums_to_one—
test_dirichlet_nonnegative—
test_log_normal_positive—
test_poisson_nonnegative_int—
test_uniform_range—
test_rng_property—
test_new_rng_works—
test_new_rng_autoseed—

class TestSocioeconomicEngine​

Social class sampling and mobility constraints.

TesteO que verifica
test_sample_class_valid—
test_sample_class_matches_marginal_broadly—
test_mobility_child_of_de_rarely_aChild of D_E rarely reaches A: < 15% over 1500 samples.
test_mobility_child_of_a_seldom_deChild of A seldom gets D_E: < 15% over 1500 samples.
test_mobility_matrix_rows_sum_to_one—
test_mobility_matrix_diagonal_band—
test_education_high_parent_high_incomeWith parent superior + high income, P(superior|pos) > 0.5.
test_education_parent_gapSuperior-educated parent raises attainment over fundamental parent.
test_salary_floorSalary never below BRL 1200.
test_salary_female_gapFemale salary systematically lower (same inputs).
test_salary_education_orderingHigher education yields higher average gross salary.
test_family_influence_same_sectorSame-sector parent can trigger nepotism multiplier (1.0-1.35).
test_family_influence_different_sectorDifferent-sector parent always returns 1.0.
test_family_influence_no_parent—

class TestHealthEngine​

Survival, diagnoses, and mental health generators.

TesteO que verifica
test_survival_decreasingSurvival should generally decrease with age.
test_survival_rangeSurvival always in (0, 1].
test_survival_female_higherFemale survival at 60 should be >= male survival.
test_lifetime_hazard_diabetes_gate—
test_lifetime_hazard_hipertension_gate—
test_lifetime_hazard_depression_peak—
test_lifetime_hazard_cancer_nonnegative_growing—
test_simulate_diagnoses_no_early_diabetesNo diabetes diagnosis before age 40.
test_simulate_diagnoses_dict_keysOutput is list of dicts with expected keys.
test_simulate_diagnoses_known_diseases—
test_simulate_diagnoses_deterministic—
test_hereditary_multiplier—
test_hereditary_alias—
test_predisposition_raises_diagnosis_rate—
test_mental_risk_score—
test_mental_disorder_returns_bool—
test_mental_disorder_rate_grows_with_score—
test_chronic_impact_no_chronic—
test_chronic_impact_with_chronic—
test_chronic_impact_deterministic—