Skip to content

Commit 6f077b5

Browse files
author
Mykyta Zotov
committed
Update Range struct to support 'with' keyword for property initialization and increment version to 0.0.2
1 parent b9ed8ab commit 6f077b5

File tree

3 files changed

+22
-31
lines changed

3 files changed

+22
-31
lines changed

src/Intervals.NET/Intervals.NET.csproj

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,10 @@
66
<Nullable>enable</Nullable>
77
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
88
<PackageId>Intervals.NET</PackageId>
9-
<Version>0.0.1</Version>
9+
<Version>0.0.2</Version>
1010
<Authors>blaze6950</Authors>
1111
<Description>Production-ready .NET library for type-safe mathematical intervals and ranges. Zero-allocation struct-based design with comprehensive set operations (intersection, union, contains, overlaps), explicit infinity support, span-based parsing, and custom interpolated string handler. Generic over IComparable&lt;T&gt; with 100% test coverage. Built for correctness and performance.</Description>
12-
<PackageReleaseNotes>🎉 Initial Release (v0.0.1):
13-
14-
✨ Core Features:
15-
- Type-safe range operations with all boundary types: [a,b], (a,b), [a,b), (a,b]
16-
- Rich API: Overlaps, Contains, Intersect, Union, Except, IsAdjacent, IsBefore, IsAfter
17-
- Explicit infinity support with RangeValue&lt;T&gt; (no nullable confusion)
18-
- Zero-allocation struct-based design (all operations stack-allocated)
19-
20-
⚡ Performance:
21-
- 3.6× faster parsing with interpolated string handler
22-
- 1.7× faster containment checks vs naive implementations
23-
- Zero heap allocations for all set operations
24-
- Span-based parsing with ReadOnlySpan&lt;char&gt;
25-
26-
🎯 Developer Experience:
27-
- Generic over any IComparable&lt;T&gt; (int, double, DateTime, custom types)
28-
- Comprehensive extension methods for fluent API
29-
- Culture-aware parsing with IFormatProvider support
30-
- Infinity symbol support (∞, -∞) in string parsing
31-
- Full XML documentation and IntelliSense
32-
33-
🛡️ Quality:
34-
- 100% test coverage
35-
- Fail-fast validation with comprehensive edge case handling
36-
- Production-ready correctness over raw speed
37-
- .NET 8.0 target with modern C# features</PackageReleaseNotes>
12+
<PackageReleaseNotes>Range record was updated by making all properties as init in order to allow the creation of new Range struct using the with keyword</PackageReleaseNotes>
3813
<PackageTags>range;interval;math;mathematics;intervals;ranges;span;performance;zero-allocation;generic;comparable;infinity;parsing;set-operations;intersection;union;datetime;numeric</PackageTags>
3914
<RepositoryUrl>https://github.com/blaze6950/Intervals.NET</RepositoryUrl>
4015
<PackageProjectUrl>https://github.com/blaze6950/Intervals.NET</PackageProjectUrl>

src/Intervals.NET/Range.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,25 +69,25 @@ internal Range(RangeValue<T> start, RangeValue<T> end, bool isStartInclusive, bo
6969
/// The start value of the range.
7070
/// Can be finite, negative infinity, or positive infinity.
7171
/// </summary>
72-
public RangeValue<T> Start { get; }
72+
public RangeValue<T> Start { get; init; }
7373

7474
/// <summary>
7575
/// The end value of the range.
7676
/// Can be finite, negative infinity, or positive infinity.
7777
/// </summary>
78-
public RangeValue<T> End { get; }
78+
public RangeValue<T> End { get; init; }
7979

8080
/// <summary>
8181
/// Indicates whether the start value is inclusive.
8282
/// Meaning the range includes the start value: [start, ...
8383
/// </summary>
84-
public bool IsStartInclusive { get; }
84+
public bool IsStartInclusive { get; init; }
8585

8686
/// <summary>
8787
/// Indicates whether the end value is inclusive.
8888
/// Meaning the range includes the end value: ..., end]
8989
/// </summary>
90-
public bool IsEndInclusive { get; }
90+
public bool IsEndInclusive { get; init; }
9191

9292
/// <summary>
9393
/// Returns a string representation of the range.

tests/Intervals.NET.Tests/RangeStructTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,22 @@ public void RecordStruct_GetHashCode_DifferentRangesHaveDifferentHashCodes()
697697
Assert.NotEqual(hash1, hash2);
698698
}
699699

700+
[Fact]
701+
public void RecordStruct_CreateNewWith_NewNotEqualToSource()
702+
{
703+
// Arrange
704+
var range1 = new Range<int>(new RangeValue<int>(10), new RangeValue<int>(20), true, false);
705+
706+
// Act
707+
var range2 = range1 with { Start = 11 };
708+
709+
// Assert
710+
Assert.NotEqual(range1.Start, range2.Start);
711+
Assert.Equal(range1.End, range2.End);
712+
Assert.Equal(range1.IsStartInclusive, range2.IsStartInclusive);
713+
Assert.Equal(range1.IsEndInclusive, range2.IsEndInclusive);
714+
}
715+
700716
#endregion
701717

702718
#region Edge Cases and Different Types

0 commit comments

Comments
 (0)