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: