from __future__ import annotations import importlib.util from pathlib import Path import unittest ROOT = Path(__file__).resolve().parents[1] SPEC = importlib.util.spec_from_file_location("power_study2", ROOT / "scripts" / "power_study2.py") assert SPEC and SPEC.loader POWER = importlib.util.module_from_spec(SPEC) SPEC.loader.exec_module(POWER) class Study2PowerTests(unittest.TestCase): def test_exact_binomial_reference_values(self) -> None: self.assertAlmostEqual(POWER.exact_binomial_pvalue(0, 6), 0.03125) self.assertAlmostEqual(POWER.exact_binomial_pvalue(3, 6), 1.0) def test_preregistered_power(self) -> None: value = POWER.exact_mcnemar_power(60, 0.25, 0.05, 0.05) self.assertAlmostEqual(value, 0.797, places=3) def test_invalid_discordance_is_rejected(self) -> None: with self.assertRaises(ValueError): POWER.exact_mcnemar_power(60, 0.8, 0.3) if __name__ == "__main__": unittest.main()