import numpy as np from evaluate_depth import depth_metrics, evaluate_depth_pair def test_depth_metrics_reports_perfect_prediction(): depth = np.array([[1.0, 2.0], [3.0, 4.0]]) metrics = depth_metrics(depth, depth) assert metrics["valid_pixel_count"] == 4 assert metrics["abs_rel"] == 0.0 assert metrics["rmse"] == 0.0 assert metrics["delta1"] == 1.0 def test_depth_pair_separates_relative_scale_from_raw_error(): ground_truth = np.array([[1.0, 2.0], [3.0, 4.0]]) prediction = ground_truth * 7.0 report = evaluate_depth_pair(prediction, ground_truth) assert report["raw"]["abs_rel"] > 5.0 assert report["median_scaled"]["rmse"] < 1e-12 assert abs(report["median_scale"] - 1.0 / 7.0) < 1e-12 def test_inverse_depth_option_converts_before_scoring(): ground_truth = np.array([[1.0, 2.0], [4.0, 8.0]]) report = evaluate_depth_pair(1.0 / ground_truth, ground_truth, prediction_is_inverse_depth=True) assert report["raw"]["rmse"] < 1e-12 def test_depth_metrics_respects_mask_and_rejects_shape_mismatch(): prediction = np.array([[1.0, 2.0], [30.0, 40.0]]) ground_truth = np.array([[1.0, 2.0], [3.0, 4.0]]) mask = np.array([[True, True], [False, False]]) assert depth_metrics(prediction, ground_truth, mask)["valid_pixel_count"] == 2 try: depth_metrics(prediction, ground_truth, np.ones((1, 1), dtype=bool)) except ValueError as exc: assert "valid_mask" in str(exc) else: raise AssertionError("shape mismatch should fail")