Skip to content

Commit

Permalink
Merge branch 'release/4.0.0' into feature/generic_math
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverbooth committed Jun 12, 2024
2 parents 19c467d + 8eaa01b commit e51296d
Show file tree
Hide file tree
Showing 22 changed files with 289 additions and 295 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ jobs:
with:
dotnet-version: |
6.0.x
7.0.x
8.0.x
- name: Add NuGet source
Expand All @@ -39,9 +38,6 @@ jobs:
- name: Test .NET 6
run: dotnet test --no-build --verbosity normal --configuration Release --framework net6.0 --collect:"XPlat Code Coverage" --results-directory test-results/net6.0

- name: Test .NET 7
run: dotnet test --no-build --verbosity normal --configuration Release --framework net7.0 --collect:"XPlat Code Coverage" --results-directory test-results/net7.0

- name: Test .NET 8
run: dotnet test --no-build --verbosity normal --configuration Release --framework net8.0 --collect:"XPlat Code Coverage" --results-directory test-results/net8.0

Expand Down
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- X10D: Added `TextWriter.WriteLineNoAlloc(uint[, ReadOnlySpan<char>[, IFormatProvider]])`.
- X10D: Added `TextWriter.WriteLineNoAlloc(long[, ReadOnlySpan<char>[, IFormatProvider]])`.
- X10D: Added `TextWriter.WriteLineNoAlloc(ulong[, ReadOnlySpan<char>[, IFormatProvider]])`.
- X10D: Added `Range.GetEnumerator` (and `RangeEnumerator`), implementing Python-esque `for` loops in C#.
- X10D: Added `string.ConcatIf`.
- X10D: Added `string.MDBold`, `string.MDCode`, `string.MDCodeBlock([string])`, `string.MDHeading(int)`,
`string.MDItalic`, `string.MDLink`, `string.MDStrikeOut`, and `string.MDUnderline` for Markdown formatting.
Expand All @@ -39,7 +40,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
BigEndian/LittleEndian methods.
- X10D: `Stream.GetHash<>` and `Stream.TryWriteHash<>` now throw ArgumentException in lieu of
TypeInitializationException.
- X10D: `char.IsEmoji` no longer allocates for .NET 7.
- X10D: `char.IsEmoji` no longer allocates for .NET 7+.
- X10D: `string.Repeat` is now more efficient.

### Removed
Expand All @@ -48,6 +49,7 @@ TypeInitializationException.
- X10D: Removed `Endianness` enum.
- X10D: Removed `Span<T>.Replace(T, T)` for .NET 8 target.
- X10D: Removed .NET Standard 2.1 target.
- X10D: Removed extensions for `Progress<T>`. These are already provided by [`Observable.FromEventPattern`](https://learn.microsoft.com/en-us/previous-versions/dotnet/reactive-extensions/hh229424(v=vs.103)).
- X10D.Hosting: Removed .NET Standard 2.1 target.
- X10D.DSharpPlus: Complete sunset of library. This library will not be updated to support DSharpPlus v5.0.0 (#83).
- X10D.Unity: Complete sunset of library. This library will not be updated effective immediately (#86).
Expand All @@ -56,6 +58,7 @@ TypeInitializationException.

### Fixed

- X10D: Fixed `decimal.TryWriteBigEndianBytes` and `decimal.TryWriteLittleEndianBytes`.
- X10D.Hosting: Fixed `AddHostedSingleton` not accepting an interface as the service type.

## [3.3.0] - 2023-08-21
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ or submit a pull request.

### Pull request guidelines

This project uses C# 11.0 language features where feasible, and adheres to StyleCop rules with some minor adjustments.
This project uses C# 12.0 language features where feasible, and adheres to StyleCop rules with some minor adjustments.
There is an `.editorconfig` included in this repository. For quick and painless pull requests, ensure that the analyzer does not
throw warnings.

Expand All @@ -17,7 +17,7 @@ convetional commits specification.

Below are a few pointers to which you may refer, but keep in mind this is not an exhaustive list:

- Use C# 11.0 features where possible
- Use C# 12.0 features where possible
- Try to ensure code is CLS-compliant. Where this is not possible, decorate methods with `CLSCompliantAttribute` and pass `false`
- Follow all .NET guidelines and coding conventions.
See https://docs.microsoft.com/en-us/dotnet/csharp/fundamentals/coding-style/coding-conventions
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<LangVersion>11.0</LangVersion>
<LangVersion>12.0</LangVersion>
<Optimize>true</Optimize>
<ImplicitUsings>true</ImplicitUsings>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand Down
2 changes: 1 addition & 1 deletion X10D.Hosting/X10D.Hosting.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0;net6.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion X10D.Tests/X10D.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0;net6.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<CoverletOutputFormat>xml,cobertura</CoverletOutputFormat>
Expand Down
66 changes: 66 additions & 0 deletions X10D.Tests/src/Core/RangeTests.cs
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--;
}
}
}
72 changes: 72 additions & 0 deletions X10D.Tests/src/IO/DecimalTests.cs
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);
}
}
3 changes: 2 additions & 1 deletion X10D.Tests/src/IO/StreamTests.WriteDecimal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ public void WriteBigEndian_ShouldWriteBigEndian_GivenDecimalArgument()
Span<byte> actual = stackalloc byte[16];
ReadOnlySpan<byte> expected = stackalloc byte[]
{
0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x68, 0x10, 0x00, 0x00
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x68
};
int read = stream.Read(actual);
Trace.WriteLine(string.Join(' ', actual.ToArray()));

Assert.That(read, Is.EqualTo(16));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
Expand Down
67 changes: 0 additions & 67 deletions X10D.Tests/src/Reactive/ProgressTests.cs

This file was deleted.

2 changes: 1 addition & 1 deletion X10D/X10D.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0;net6.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
53 changes: 53 additions & 0 deletions X10D/src/Core/RangeEnumerator.cs
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;
}
}
Loading

0 comments on commit e51296d

Please sign in to comment.