-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/4.0.0' into feature/generic_math
- Loading branch information
Showing
22 changed files
with
289 additions
and
295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using NUnit.Framework; | ||
using X10D.Core; | ||
|
||
namespace X10D.Tests.Core; | ||
|
||
[TestFixture] | ||
internal class RangeTests | ||
{ | ||
[Test] | ||
public void Range_GetEnumerator_ShouldReturnRangeEnumerator() | ||
{ | ||
Assert.Multiple(() => | ||
{ | ||
Assert.That(5..10, Is.TypeOf<Range>()); | ||
Assert.That((5..10).GetEnumerator(), Is.TypeOf<RangeEnumerator>()); | ||
}); | ||
} | ||
|
||
[Test] | ||
public void Loop_OverRange0To10_ShouldCountFrom0To10Inclusive() | ||
{ | ||
int value = 0; | ||
|
||
foreach (int i in 0..10) | ||
{ | ||
Assert.That(i, Is.EqualTo(value)); | ||
value++; | ||
} | ||
} | ||
|
||
[Test] | ||
public void Loop_OverRangeNegative5To5_ShouldCountFromNegative5To5Inclusive() | ||
{ | ||
int value = -5; | ||
|
||
foreach (int i in ^5..5) | ||
{ | ||
Assert.That(i, Is.EqualTo(value)); | ||
value++; | ||
} | ||
} | ||
|
||
[Test] | ||
public void Loop_OverRange5ToNegative5_ShouldCountFrom5ToNegative5Inclusive() | ||
{ | ||
int value = 5; | ||
|
||
foreach (int i in 5..^5) | ||
{ | ||
Assert.That(i, Is.EqualTo(value)); | ||
value--; | ||
} | ||
} | ||
|
||
[Test] | ||
public void Loop_OverRange10To0_ShouldCountFrom10To0Inclusive() | ||
{ | ||
int value = 10; | ||
|
||
foreach (int i in 10..0) | ||
{ | ||
Assert.That(i, Is.EqualTo(value)); | ||
value--; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using NUnit.Framework; | ||
using X10D.IO; | ||
|
||
namespace X10D.Tests.IO; | ||
|
||
[TestFixture] | ||
internal class DecimalTests | ||
{ | ||
[Test] | ||
public void GetBigEndianBytes_ShouldReturnBytes_InBigEndian() | ||
{ | ||
const decimal value = 1234m; | ||
byte[] expected = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 210]; | ||
|
||
byte[] bytes = value.GetBigEndianBytes(); | ||
|
||
CollectionAssert.AreEqual(expected, bytes); | ||
} | ||
|
||
[Test] | ||
public void GetLittleEndianBytes_ShouldReturnBytes_InLittleEndian() | ||
{ | ||
const decimal value = 1234m; | ||
byte[] expected = [210, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; | ||
|
||
byte[] bytes = value.GetLittleEndianBytes(); | ||
|
||
CollectionAssert.AreEqual(expected, bytes); | ||
} | ||
|
||
[Test] | ||
public void TryWriteBigEndianBytes_ShouldWriteBytes_InBigEndian() | ||
{ | ||
const decimal value = 1234m; | ||
byte[] expected = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 210]; | ||
|
||
Span<byte> bytes = stackalloc byte[16]; | ||
Assert.That(value.TryWriteBigEndianBytes(bytes)); | ||
|
||
CollectionAssert.AreEqual(expected, bytes.ToArray()); | ||
} | ||
|
||
[Test] | ||
public void TryWriteLittleEndianBytes_ShouldWriteBytes_InLittleEndian() | ||
{ | ||
const decimal value = 1234m; | ||
byte[] expected = [210, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; | ||
|
||
Span<byte> bytes = stackalloc byte[16]; | ||
Assert.That(value.TryWriteLittleEndianBytes(bytes)); | ||
|
||
CollectionAssert.AreEqual(expected, bytes.ToArray()); | ||
} | ||
|
||
[Test] | ||
public void TryWriteBigEndianBytes_ShouldReturnFalse_GivenSmallSpan() | ||
{ | ||
const decimal value = 1234m; | ||
|
||
Span<byte> bytes = Span<byte>.Empty; | ||
Assert.That(value.TryWriteBigEndianBytes(bytes), Is.False); | ||
} | ||
|
||
[Test] | ||
public void TryWriteLittleEndianBytes_ShouldReturnFalse_GivenSmallSpan() | ||
{ | ||
const decimal value = 1234m; | ||
|
||
Span<byte> bytes = Span<byte>.Empty; | ||
Assert.That(value.TryWriteLittleEndianBytes(bytes), Is.False); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
namespace X10D.Core; | ||
|
||
/// <summary> | ||
/// Enumerates the indices of a <see cref="Range" />. | ||
/// </summary> | ||
public struct RangeEnumerator | ||
{ | ||
private readonly bool _decrement; | ||
private readonly int _endValue; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="RangeEnumerator" /> structure. | ||
/// </summary> | ||
/// <param name="range">The range over which to enumerate.</param> | ||
public RangeEnumerator(Range range) | ||
{ | ||
Index start = range.Start; | ||
Index end = range.End; | ||
|
||
int startValue = start.IsFromEnd ? -start.Value : start.Value; | ||
_endValue = end.IsFromEnd ? -end.Value : end.Value; | ||
|
||
_decrement = _endValue < startValue; | ||
Current = _decrement ? startValue + 1 : startValue - 1; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the element in the collection at the current position of the enumerator. | ||
/// </summary> | ||
/// <value>The element in the collection at the current position of the enumerator.</value> | ||
public int Current { get; private set; } | ||
|
||
/// <summary> | ||
/// Advances the enumerator to the next element of the collection. | ||
/// </summary> | ||
/// <returns> | ||
/// <see langword="true" /> if the enumerator was successfully advanced to the next element; <see langword="false" /> if | ||
/// the enumerator has passed the end of the collection. | ||
/// </returns> | ||
public bool MoveNext() | ||
{ | ||
int value = Current; | ||
|
||
if (_decrement) | ||
{ | ||
Current--; | ||
return value > _endValue; | ||
} | ||
|
||
Current++; | ||
return value < _endValue; | ||
} | ||
} |
Oops, something went wrong.