From c4659a9103e654582f6b69b0af6a4a2c487865e0 Mon Sep 17 00:00:00 2001 From: Nicholas Karlson Date: Mon, 10 Nov 2025 17:02:09 -0800 Subject: [PATCH] feat(ch13): add tests, fix CI data size, and run tests in workflow --- .github/workflows/ci.yml | 6 ++++++ Makefile | 2 +- tests/test_ch13_fitness.py | 8 +++++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 601f78e..fcfa669 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,6 +31,12 @@ jobs: - name: Tests run: make test + - name: Lint + run: make lint + + - name: Tests + run: make test + - name: Tiny Chapter 13 smoke run: make ch13-ci diff --git a/Makefile b/Makefile index 326c97b..872da1e 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ help: ch13-ci: python scripts/sim_stroop.py --n-subjects 6 --n-trials 10 --seed 2025 python scripts/ch13_stroop_within.py --save-plots - python scripts/sim_fitness_2x2.py --n-per-group 5 --seed 2025 + python scripts/sim_fitness_2x2.py --n-per-group 40 --seed 2025 python scripts/ch13_fitness_mixed.py --save-plots .PHONY: ch13 diff --git a/tests/test_ch13_fitness.py b/tests/test_ch13_fitness.py index 3ca3597..225994a 100644 --- a/tests/test_ch13_fitness.py +++ b/tests/test_ch13_fitness.py @@ -4,7 +4,8 @@ SEED = 2025 def test_fitness_mixed_model_signals(): - subjects, long_df = sim.simulate(n_per_group=5, seed=SEED) + # Use n_per_group=40 to provide enough data for the model + subjects, long_df = sim.simulate(n_per_group=40, seed=SEED) # Mixed model with random intercept for id, categorical time/group + covariates md = smf.mixedlm( @@ -18,6 +19,7 @@ def test_fitness_mixed_model_signals(): assert res.params["C(time)[T.post]"] > 5 assert res.pvalues["C(time)[T.post]"] < 1e-6 - # interaction should be positive (ProgramB a bit more improvement); allow modest p + # interaction should be positive (ProgramB a bit more improvement) assert res.params["C(time)[T.post]:C(group)[T.ProgramB]"] > 0 - assert res.pvalues["C(time)[T.post]:C(group)[T.ProgramB]"] < 0.2 \ No newline at end of file + # With N=80, we can have a stricter p-value check + assert res.pvalues["C(time)[T.post]:C(group)[T.ProgramB]"] < 0.05 \ No newline at end of file