@@ -170,20 +170,41 @@ def test_compute_harm_metrics_perfect_agreement(mock_harm_scorer):
170170 )
171171 assert metrics .mean_absolute_error == 0.0
172172 assert metrics .mae_standard_error == 0.0
173+ # Perfect agreement: diff is all zeros, t-test guarded to avoid NaN propagation.
174+ assert metrics .t_statistic == 0.0
175+ assert metrics .p_value == 1.0
173176 assert metrics .krippendorff_alpha_combined == 1.0
174177 assert metrics .krippendorff_alpha_humans == 1.0
175178 assert metrics .krippendorff_alpha_model == 1.0
176179
177180
178181def test_compute_harm_metrics_partial_agreement (mock_harm_scorer ):
179182 evaluator = HarmScorerEvaluator (scorer = mock_harm_scorer )
180- # 2 responses, 3 human scores each, model is off by 0.1 for each
183+ # 2 responses, 3 human scores each, model is off by 0.1 for each (constant bias, zero variance)
181184 all_human_scores = np .array ([[0.1 , 0.2 ], [0.1 , 0.2 ], [0.1 , 0.2 ]])
182185 all_model_scores = np .array ([[0.2 , 0.3 ], [0.2 , 0.3 ]])
183186 metrics = evaluator ._compute_metrics (
184187 all_human_scores = all_human_scores , all_model_scores = all_model_scores , num_scorer_trials = 2
185188 )
186189 assert np .isclose (metrics .mean_absolute_error , 0.1 )
190+ # Constant non-zero diff has no within-sample variance: t-test undefined, reported as NaN.
191+ # MAE captures the bias magnitude.
192+ assert np .isnan (metrics .t_statistic )
193+ assert np .isnan (metrics .p_value )
194+
195+
196+ def test_compute_harm_metrics_partial_agreement_with_variance (mock_harm_scorer ):
197+ evaluator = HarmScorerEvaluator (scorer = mock_harm_scorer )
198+ # Model scores have variance across responses so ttest_1samp is well-defined.
199+ all_human_scores = np .array ([[0.1 , 0.5 ], [0.1 , 0.5 ], [0.1 , 0.5 ]])
200+ all_model_scores = np .array ([[0.2 , 0.3 ], [0.2 , 0.3 ]])
201+ metrics = evaluator ._compute_metrics (
202+ all_human_scores = all_human_scores , all_model_scores = all_model_scores , num_scorer_trials = 2
203+ )
204+ # diff = [0.1, -0.2]; both t_statistic and p_value should be finite floats.
205+ assert np .isfinite (metrics .t_statistic )
206+ assert np .isfinite (metrics .p_value )
207+ assert 0.0 <= metrics .p_value <= 1.0
187208
188209
189210@patch ("pyrit.score.scorer_evaluation.scorer_evaluator.find_objective_metrics_by_eval_hash" )
0 commit comments