Skip to content

Fix TryGet returning false for empty subranges with exclusive parent boundaries#3

Merged
blaze6950 merged 3 commits intofeature/implement-data-related-logic-for-rangesfrom
copilot/sub-pr-2
Feb 3, 2026
Merged

Fix TryGet returning false for empty subranges with exclusive parent boundaries#3
blaze6950 merged 3 commits intofeature/implement-data-related-logic-for-rangesfrom
copilot/sub-pr-2

Conversation

Copy link
Contributor

Copilot AI commented Feb 3, 2026

TryGet(Range subRange, ...) incorrectly returned false for empty-but-contained subranges when the parent range had exclusive boundaries. Example: parent (10,20] with subrange (10,10] returned false instead of an empty RangeData.

Root Cause

After adjusting indices for boundary inclusiveness, endIndex could become negative for empty ranges. The negative-index guard rejected these before the empty-range check (count <= 0) could execute.

Changes

  • Reordered validation logic: Check count <= 0 before validating index bounds
  • Added comment: Clarified why empty-range detection must precede overflow checks
  • Test coverage: Added cases for empty subranges at exclusive boundaries
// Before: negative endIndex causes early return false
var count = endIndex - startIndex + 1;
if (startIndex < 0 || endIndex < 0) return false;  // ❌ Blocks empty ranges
if (count <= 0) return Empty(...);

// After: empty ranges detected first
var count = endIndex - startIndex + 1;
if (count <= 0) return Empty(...);  // ✅ Handles empty correctly
if (startIndex < 0 || endIndex < 0) return false;

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits February 3, 2026 01:49
…rt parents

Co-authored-by: blaze6950 <32897401+blaze6950@users.noreply.github.com>
…stead of empty RangeData

Co-authored-by: blaze6950 <32897401+blaze6950@users.noreply.github.com>
Copilot AI changed the title [WIP] Address feedback on data logic implementation for ranges Fix TryGet returning false for empty subranges with exclusive parent boundaries Feb 3, 2026
Copilot AI requested a review from blaze6950 February 3, 2026 01:54
@blaze6950 blaze6950 marked this pull request as ready for review February 3, 2026 01:59
Copilot AI review requested due to automatic review settings February 3, 2026 01:59
@blaze6950 blaze6950 merged commit c7390d3 into feature/implement-data-related-logic-for-ranges Feb 3, 2026
@blaze6950 blaze6950 deleted the copilot/sub-pr-2 branch February 3, 2026 01:59
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where TryGet(Range subRange, ...) incorrectly returned false for empty subranges when the parent range had exclusive boundaries. The issue occurred because negative indices (from boundary adjustments) were rejected before empty-range logic could execute.

Changes:

  • Reordered validation logic to check for empty ranges (count <= 0) before validating index bounds
  • Added clarifying comment explaining the ordering requirement
  • Added three test cases covering empty subranges at exclusive boundaries

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Intervals.NET.Data/RangeData.cs Moved empty-range check before negative-index guard to properly handle empty subranges at exclusive boundaries
tests/Intervals.NET.Data.Tests/RangeDataTests.cs Added three test cases verifying empty subranges return true with empty data when at exclusive parent boundaries

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

blaze6950 added a commit that referenced this pull request Feb 3, 2026
* Feature: Implement data-related logic for RangeData and update range factory methods for consistency

- Introduced RangeData abstraction to couple logical ranges with data sequences and domains.
- Updated RangeFactory methods to remove type parameters for cleaner usage.
- Added TryCreate method for Range with validation and error messaging.
- Enhanced Distance method in domain interfaces to ensure accurate step calculations.
- Revised tests to reflect changes in range factory methods and ensure correctness.
- Updated project metadata and CI/CD configurations for new data module.

* Feature: Add validation method for RangeData to ensure data sequence matches expected logical elements

* Feature: Add overview and implementation details for RangeData in README.md

* Feature: Add unit tests for RangeData extensions to validate adjacency and data integrity

* Feature: Add unit tests for RangeData extensions to validate equality, slicing, and domain interactions

* Feature: Add benchmarks for RangeData and RangeDataExtensions to evaluate performance and memory usage

* Feature: Integrate Codecov coverage reporting into CI workflows for all projects

* Feature: Enhance RangeData logic for sub-range and point access with validation and improved error handling

- Refine RangeData indexer to validate sub-range finiteness and containment, throwing specific exceptions for invalid cases
- Update TryGet methods to ensure points and sub-ranges are within bounds before accessing data
- Align index calculations with range inclusivity for accurate data mapping
- Improve XML documentation for IRangeDomain to clarify complexity of Distance implementations
- Update benchmarks and tests for readonly domain fields and minor cleanup
- Clarify package description and README section for RangeData usage and validation

* Feature: Update Microsoft.NET.Test.Sdk to version 17.11.1 in test project dependencies

* Feature: Update Microsoft.NET.Test.Sdk to version 17.11.1 in test project dependencies

* Feature: Update test execution paths and remove Codecov upload from Domain.Abstractions workflow

* Feature: Update test paths in CI configuration and enhance documentation for TryCreate method

* Feature: Update CI configuration to use test paths for dependency restoration, building, and testing

* Feature: Correct test path in CI configuration for Intervals.NET.Data.Tests

* Feature: Update CI configuration to use test path for dependency restoration and building

* Feature: Optimize null-check for domain parameter to avoid boxing in RangeData

* Feature: Enhance test coverage for RangeData and DateTime domains with edge case scenarios

* chore: get rid of redundant md files

* Feature: Update range comments and improve test method naming for clarity

* Feature: Refine distance calculation and improve exception messages in RangeData

* Feature: Improve range validation logic to handle overflow and enhance error messaging

* Feature: Enhance range validation to correctly handle infinity bounds and improve exception messaging

* Feature: Update range documentation for clarity and improve validation logic in TrimEnd method

* Feature: Enhance TrimStart and TrimEnd methods to support inclusive/exclusive boundaries and improve documentation

* Feature: Update documentation for RangeData methods to clarify return values and equality semantics

* Feature: Clarify documentation for range span calculation and return type details

* Feature: Update test data in IsTouching method to clarify range element counts

* Feature: Update test data in IsBeforeAndAdjacentTo method to clarify element counts for ranges

* Feature: Refine documentation and logic in RangeData extensions for clarity and consistency

* Feature: Enhance documentation for domain interfaces and implementations to clarify performance characteristics and equality semantics

* Feature: Update README to enhance structure and clarity of RangeData documentation

* Fix TryGet returning false for empty subranges with exclusive parent boundaries (#3)

* Initial plan

* Add test case demonstrating bug with empty subranges in exclusive-start parents

Co-authored-by: blaze6950 <32897401+blaze6950@users.noreply.github.com>

* Fix bug where empty subranges with negative indices returned false instead of empty RangeData

Co-authored-by: blaze6950 <32897401+blaze6950@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: blaze6950 <32897401+blaze6950@users.noreply.github.com>

---------

Co-authored-by: Mykyta Zotov <mykyta.zotov@ihsmarkit.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
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.

2 participants