Skip to content

BOT: Fix #454: Deduplicate interval coverage bounds-check logic#1097

Draft
nikosbosse wants to merge 1 commit intomainfrom
fix/454-deduplicate-coverage
Draft

BOT: Fix #454: Deduplicate interval coverage bounds-check logic#1097
nikosbosse wants to merge 1 commit intomainfrom
fix/454-deduplicate-coverage

Conversation

@nikosbosse
Copy link
Collaborator

Summary

  • Extracts duplicated bounds-check logic (observed >= lower) & (observed <= upper) into a shared internal helper check_interval_coverage()
  • Both get_coverage() (R/get-coverage.R) and interval_coverage() (R/metrics-quantile.R) now call this helper instead of independently implementing the same logic
  • Adds regression tests verifying both code paths produce identical results

Fixes #454

Root cause

Both get_coverage() and interval_coverage() independently implemented the same interval bounds check after calling quantile_to_interval(). The logic was identical but the operand order differed (observed <= upper & observed >= lower vs observed >= lower & observed <= upper).

What the fix does

  1. Creates check_interval_coverage(observed, lower, upper) in R/helper-quantile-interval-range.R
  2. Updates both get_coverage() and interval_coverage() to call the shared helper
  3. Standardizes the operand order to (observed >= lower) & (observed <= upper)

Test coverage added

  • get_coverage() interval coverage matches interval_coverage() for same data
  • Known-input correctness test with hand-crafted data
  • Observation outside all intervals agreement test
  • Full example dataset regression guard comparing get_coverage() vs score()
  • Boundary cases (observation on lower/upper bound)
  • Multiple interval ranges test

🤖 Generated with Claude Code

Extract shared bounds-check `(observed >= lower) & (observed <= upper)`
into `check_interval_coverage()` helper, used by both `get_coverage()`
and `interval_coverage()` to eliminate duplicated logic.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Feb 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.83%. Comparing base (ac0c01a) to head (3a69991).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1097   +/-   ##
=======================================
  Coverage   97.83%   97.83%           
=======================================
  Files          35       35           
  Lines        1845     1846    +1     
=======================================
+ Hits         1805     1806    +1     
  Misses         40       40           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator Author

@nikosbosse nikosbosse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CLAUDE: Approve — Clean, minimal refactoring that correctly extracts the duplicated bounds-check logic into a shared internal helper check_interval_coverage(). The change is purely mechanical with no behavioral impact. Both original implementations computed the same expression — the helper standardizes the operand order. Well-guarded by 6 new regression tests covering cross-validation between code paths, boundary cases, and full-dataset comparison against score() output. No issues found.

@nikosbosse nikosbosse marked this pull request as draft February 13, 2026 08:28
@nikosbosse nikosbosse changed the title Fix #454: Deduplicate interval coverage bounds-check logic BOT: Fix #454: Deduplicate interval coverage bounds-check logic Feb 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Code refactoring: Deduplicate code in get_coverage() and interval_coverage_deviation_quantile()

1 participant

Comments