File size: 974 Bytes
d61821a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | 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()
|