Standardize a comparison across case mix
Implement standardized_comparison(baseline,candidate,weights). Baseline and candidate map each stratum to (successes,total). Require the same nonempty keys in all mappings, integer counts excluding booleans, total>0, and 0<=successes<=total. Weights must be finite nonnegative numbers excluding booleans and sum to 1 within 1e-9. Return baseline_observed, candidate_observed, baseline_standardized, candidate_standardized, and standardized_delta. Even zero-weight strata must have valid observations so coverage is explicit.
Your task
- Complete the starter function using the contract above.
- Use the examples and visible tests to check normal inputs, boundaries, and rejected inputs.
- Run tests to record your result, then compare with the explained reference solution.
Examples
Inputbaseline={"easy":(90,100),"hard":(2,10)}, candidate={"easy":(19,20),"hard":(30,100)}, weights={"easy":0.5,"hard":0.5}
Outputbaseline_standardized=0.55, candidate_standardized=0.625, standardized_delta=0.075
Implement the function, then run the tests.
Ctrl / ⌘ + Enter to test · Shift + Tab leaves editor