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.
| Teste | O que verifica |
|---|---|
test_deterministic_same_params | Same seed+persona+domain => identical sequences. |
test_fork_different_persona | Different persona => different sequences. |
test_fork_different_domain | Different domain => different sequences. |
test_fork_respects_salt | Pending salt => different sequences from base fork. |
test_bernoulli_distribution | Over 1000 draws at p=0.3, fraction within [25%, 35%]. |
test_bernoulli_returns_bool | — |
test_normal_clipped_bounds | normal_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.
| Teste | O que verifica |
|---|---|
test_sample_class_valid | — |
test_sample_class_matches_marginal_broadly | — |
test_mobility_child_of_de_rarely_a | Child of D_E rarely reaches A: < 15% over 1500 samples. |
test_mobility_child_of_a_seldom_de | Child 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_income | With parent superior + high income, P(superior|pos) > 0.5. |
test_education_parent_gap | Superior-educated parent raises attainment over fundamental parent. |
test_salary_floor | Salary never below BRL 1200. |
test_salary_female_gap | Female salary systematically lower (same inputs). |
test_salary_education_ordering | Higher education yields higher average gross salary. |
test_family_influence_same_sector | Same-sector parent can trigger nepotism multiplier (1.0-1.35). |
test_family_influence_different_sector | Different-sector parent always returns 1.0. |
test_family_influence_no_parent | — |
class TestHealthEngine
Survival, diagnoses, and mental health generators.
| Teste | O que verifica |
|---|---|
test_survival_decreasing | Survival should generally decrease with age. |
test_survival_range | Survival always in (0, 1]. |
test_survival_female_higher | Female 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_diabetes | No diabetes diagnosis before age 40. |
test_simulate_diagnoses_dict_keys | Output 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 | — |