From 42c412a713ad6e27445bd3392116cab6b85626cb Mon Sep 17 00:00:00 2001 From: protosphinx <133899485+protosphinx@users.noreply.github.com> Date: Thu, 14 May 2026 16:11:23 +0000 Subject: [PATCH] test(synth): add unit tests for is_positive_outcome is_positive_outcome had no direct tests; it was only exercised through the full outcome-pipeline e2e test. The new tests cover the four boundary conditions: empty list, single-event positive, activity-not-last, and ordinary negative. A probabilistic rate test verifies that the synthetic log produces roughly the 10% positive share dictated by PATHS/WEIGHTS for large n_cases. --- tests/test_synth.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/test_synth.py b/tests/test_synth.py index 5f4a2ca..ede8b77 100644 --- a/tests/test_synth.py +++ b/tests/test_synth.py @@ -1,4 +1,36 @@ from pm_bench import _synth +from pm_bench._synth import is_positive_outcome + + +def test_is_positive_outcome_true_when_ends_with_delivery_confirmed() -> None: + assert is_positive_outcome(["received", "ship_order", "delivery_confirmed"]) + + +def test_is_positive_outcome_false_when_ends_with_other_activity() -> None: + assert not is_positive_outcome(["received", "ship_order"]) + + +def test_is_positive_outcome_false_on_empty_list() -> None: + assert not is_positive_outcome([]) + + +def test_is_positive_outcome_false_when_delivery_confirmed_not_last() -> None: + assert not is_positive_outcome(["delivery_confirmed", "received"]) + + +def test_is_positive_outcome_true_on_single_event_delivery_confirmed() -> None: + assert is_positive_outcome(["delivery_confirmed"]) + + +def test_synthetic_log_positive_rate_matches_paths_weight() -> None: + """PATHS[4] has weight 0.10; rate on a large sample should be close.""" + events = list(_synth.synthetic_log(n_cases=500, seed=42)) + by_case: dict[str, list[str]] = {} + for cid, act, _ in events: + by_case.setdefault(cid, []).append(act) + positives = sum(1 for acts in by_case.values() if is_positive_outcome(acts)) + rate = positives / len(by_case) + assert 0.05 <= rate <= 0.20, f"positive rate {rate:.3f} outside expected range" def test_deterministic() -> None: