mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-22 01:28:46 +00:00
Merge branch 'release/4.1.0' into release/5.0.0
This commit is contained in:
commit
d2cc9556a2
32
.github/workflows/docfx.yml
vendored
32
.github/workflows/docfx.yml
vendored
@ -10,22 +10,22 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
name: Publish Documentation
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Copy favicon
|
||||
run: |
|
||||
mkdir docfx_project/images
|
||||
cp branding_Icon.png docfx_project/images/favicon.png
|
||||
- name: Copy favicon
|
||||
run: |
|
||||
mkdir docfx_project/images
|
||||
cp branding_Icon.png docfx_project/images/favicon.png
|
||||
|
||||
- name: Build documentation
|
||||
uses: nikeee/docfx-action@v1.0.0
|
||||
with:
|
||||
args: docfx_project/docfx.json
|
||||
- name: Build documentation
|
||||
uses: nikeee/docfx-action@v1.0.0
|
||||
with:
|
||||
args: docfx_project/docfx.json
|
||||
|
||||
- name: Publish documentation on GitHub Pages
|
||||
uses: maxheld83/ghpages@master
|
||||
env:
|
||||
BUILD_DIR: docfx_project/_site
|
||||
GH_PAT: ${{ secrets.GH_PAT }}
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Publish documentation on GitHub Pages
|
||||
uses: maxheld83/ghpages@master
|
||||
env:
|
||||
BUILD_DIR: docfx_project/_site
|
||||
GH_PAT: ${{ secrets.GH_PAT }}
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
12
.github/workflows/dotnet.yml
vendored
12
.github/workflows/dotnet.yml
vendored
@ -17,14 +17,14 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v3
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: |
|
||||
6.0.x
|
||||
8.0.x
|
||||
9.0.x
|
||||
|
||||
- name: Add NuGet source
|
||||
run: dotnet nuget add source --username oliverbooth --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/oliverbooth/index.json"
|
||||
@ -35,12 +35,12 @@ jobs:
|
||||
- name: Build
|
||||
run: dotnet build --no-restore --configuration Release
|
||||
|
||||
- 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 8
|
||||
run: dotnet test --no-build --verbosity normal --configuration Release --framework net8.0 --collect:"XPlat Code Coverage" --results-directory test-results/net8.0
|
||||
|
||||
- name: Test .NET 9
|
||||
run: dotnet test --no-build --verbosity normal --configuration Release --framework net9.0 --collect:"XPlat Code Coverage" --results-directory test-results/net9.0
|
||||
|
||||
- name: Upload coverage reports to Codecov
|
||||
uses: codecov/codecov-action@v4.0.0
|
||||
with:
|
||||
|
6
.github/workflows/nightly.yml
vendored
6
.github/workflows/nightly.yml
vendored
@ -13,12 +13,12 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v3
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: 8.0.x
|
||||
dotnet-version: 9.0.x
|
||||
|
||||
- name: Add GitHub NuGet source
|
||||
run: dotnet nuget add source --username oliverbooth --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/oliverbooth/index.json"
|
||||
|
6
.github/workflows/prerelease.yml
vendored
6
.github/workflows/prerelease.yml
vendored
@ -12,12 +12,12 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v3
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: 8.0.x
|
||||
dotnet-version: 9.0.x
|
||||
|
||||
- name: Add GitHub NuGet source
|
||||
run: dotnet nuget add source --username oliverbooth --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/oliverbooth/index.json"
|
||||
|
6
.github/workflows/release.yml
vendored
6
.github/workflows/release.yml
vendored
@ -12,12 +12,12 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v3
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: 8.0.x
|
||||
dotnet-version: 9.0.x
|
||||
|
||||
- name: Add GitHub NuGet source
|
||||
run: dotnet nuget add source --username oliverbooth --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/oliverbooth/index.json"
|
||||
|
6
.github/workflows/source_validator.yml
vendored
6
.github/workflows/source_validator.yml
vendored
@ -14,12 +14,12 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v3
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: 8.0.x
|
||||
dotnet-version: 9.0.x
|
||||
|
||||
- name: Add GitHub NuGet source
|
||||
run: dotnet nuget add source --username oliverbooth --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/oliverbooth/index.json"
|
||||
|
25
CHANGELOG.md
25
CHANGELOG.md
@ -5,7 +5,27 @@ All notable changes to this project will be documented in this file.
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## 4.0.0 - [Unreleased]
|
||||
## 4.0.1 - [Unreleased]
|
||||
|
||||
### Changed
|
||||
|
||||
- X10D: Removed `IEnumerable<T>.GreatestCommonFactor` for all integer types in favour of generic math.
|
||||
- X10D: Removed `IEnumerable<T>.LowestCommonMultiple` for all integer types in favour of generic math.
|
||||
- X10D: Removed `T.MultiplicativePersistence` for all integer types in favour of generic math.
|
||||
- X10D: Removed `IEnumerable<T>.Product` for all integer types in favour of generic math.
|
||||
- X10D: Removed `IEnumerable<T>.RangeTo` for all integer types in favour of generic math.
|
||||
- X10D: Removed `T.Saturate` for all floating-point types in favour of generic math.
|
||||
- X10D: Removed `T.Sign` for all numeric types in favour of generic math.
|
||||
- X10D: Removed `T.Wrap` for all numeric types in favour of generic math.
|
||||
|
||||
### Removed
|
||||
|
||||
- X10D: Removed `DateOnly.Deconstruct` due to conflict with
|
||||
[`System.DateOnly.Deconstruct`](https://learn.microsoft.com/en-us/dotnet/api/system.datetime.deconstruct?view=net-8.0).
|
||||
- X10D: Removed `Span<T>.Split` for .NET 9.0 target due to conflicts with
|
||||
[`System.MemoryExtensions.Split`](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.split?view=net-9.0).
|
||||
|
||||
## [4.0.0] - 2024-06-12
|
||||
|
||||
### Added
|
||||
|
||||
@ -642,7 +662,8 @@ please [open an issue](https://github.com/oliverbooth/X10D/issues)!
|
||||
|
||||
Earlier versions of this package are undocumented and unlisted from package results.
|
||||
|
||||
[unreleased]: https://github.com/oliverbooth/X10D/compare/v3.3.1...main
|
||||
[unreleased]: https://github.com/oliverbooth/X10D/compare/v4.0.0...main
|
||||
[4.0.0]: https://github.com/oliverbooth/X10D/releases/tag/v4.0.0
|
||||
[3.3.1]: https://github.com/oliverbooth/X10D/releases/tag/v3.3.1
|
||||
[3.3.0]: https://github.com/oliverbooth/X10D/releases/tag/v3.3.0
|
||||
[3.2.2]: https://github.com/oliverbooth/X10D/releases/tag/v3.2.2
|
||||
|
@ -5,7 +5,7 @@ or submit a pull request.
|
||||
|
||||
### Pull request guidelines
|
||||
|
||||
This project uses C# 12.0 language features where feasible, and adheres to StyleCop rules with some minor adjustments.
|
||||
This project uses C# 13.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.
|
||||
|
||||
@ -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# 12.0 features where possible
|
||||
- Use C# 13.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
|
||||
|
@ -1,6 +1,6 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<LangVersion>12.0</LangVersion>
|
||||
<LangVersion>13.0</LangVersion>
|
||||
<Optimize>true</Optimize>
|
||||
<ImplicitUsings>true</ImplicitUsings>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
@ -8,7 +8,7 @@
|
||||
<EnableNETAnalyzers>true</EnableNETAnalyzers>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<VersionPrefix>4.0.0</VersionPrefix>
|
||||
<VersionPrefix>4.1.0</VersionPrefix>
|
||||
<Authors>Oliver Booth</Authors>
|
||||
<Nullable>enable</Nullable>
|
||||
<NeutralLanguage>en</NeutralLanguage>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net8.0;net6.0</TargetFrameworks>
|
||||
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net8.0;net6.0</TargetFrameworks>
|
||||
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
<CoverletOutputFormat>xml,cobertura</CoverletOutputFormat>
|
||||
@ -14,14 +14,14 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0"/>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
|
||||
<PackageReference Include="NSubstitute" Version="5.1.0"/>
|
||||
<PackageReference Include="NUnit" Version="3.14.0"/>
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0"/>
|
||||
<PackageReference Include="NUnit.Analyzers" Version="3.9.0"/>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0"/>
|
||||
<PackageReference Include="System.Reactive" Version="6.0.0"/>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.2"/>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.0"/>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1"/>
|
||||
<PackageReference Include="NSubstitute" Version="5.3.0"/>
|
||||
<PackageReference Include="NUnit" Version="4.2.2"/>
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0"/>
|
||||
<PackageReference Include="NUnit.Analyzers" Version="4.3.0"/>
|
||||
<PackageReference Include="System.Reactive" Version="6.0.1"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -11,7 +11,7 @@ internal static partial class ArrayTests
|
||||
[Test]
|
||||
public void AsReadOnly_ShouldReturnReadOnlyCollection_WhenArrayIsNotNull()
|
||||
{
|
||||
int[] array = {1, 2, 3};
|
||||
int[] array = [1, 2, 3];
|
||||
IReadOnlyCollection<int> result = array.AsReadOnly();
|
||||
Assert.That(result, Is.InstanceOf<IReadOnlyCollection<int>>());
|
||||
}
|
||||
@ -26,7 +26,7 @@ internal static partial class ArrayTests
|
||||
[Test]
|
||||
public void AsReadOnly_ShouldReturnCorrectCount_WhenArrayIsNotEmpty()
|
||||
{
|
||||
int[] array = {1, 2, 3};
|
||||
int[] array = [1, 2, 3];
|
||||
IReadOnlyCollection<int> result = array.AsReadOnly();
|
||||
Assert.That(result, Has.Count.EqualTo(array.Length));
|
||||
}
|
||||
@ -34,7 +34,7 @@ internal static partial class ArrayTests
|
||||
[Test]
|
||||
public void AsReadOnly_ShouldReturnEmptyCollection_WhenArrayIsEmpty()
|
||||
{
|
||||
int[] array = Array.Empty<int>();
|
||||
int[] array = [];
|
||||
IReadOnlyCollection<int> result = array.AsReadOnly();
|
||||
Assert.That(result, Is.Empty);
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ internal static partial class ArrayTests
|
||||
[Test]
|
||||
public void Clear_ShouldDoNothing_WhenArrayIsEmpty()
|
||||
{
|
||||
int[] array = Array.Empty<int>();
|
||||
int[] array = [];
|
||||
array.Clear();
|
||||
}
|
||||
|
||||
|
@ -105,7 +105,7 @@ internal class ByteTests
|
||||
Assert.Throws<ArgumentException>(() =>
|
||||
{
|
||||
const byte value = 0b11010100;
|
||||
Span<bool> bits = stackalloc bool[0];
|
||||
Span<bool> bits = [];
|
||||
value.Unpack(bits);
|
||||
});
|
||||
}
|
||||
|
@ -117,11 +117,11 @@ internal partial class EnumerableTests
|
||||
|
||||
IEnumerable<DummyClass> source = oneToTen.Select(i => new DummyClass {Value = i}).ToArray();
|
||||
IEnumerable<int> values = source.Select(o => o.Value);
|
||||
CollectionAssert.AreEqual(oneToTen, values.ToArray());
|
||||
Assert.That(values.ToArray(), Is.EqualTo(oneToTen).AsCollection);
|
||||
|
||||
source.For((i, o) => o.Value *= i);
|
||||
values = source.Select(o => o.Value);
|
||||
CollectionAssert.AreEqual(multipliedByIndex, values.ToArray());
|
||||
Assert.That(values.ToArray(), Is.EqualTo(multipliedByIndex).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -146,11 +146,11 @@ internal partial class EnumerableTests
|
||||
|
||||
IEnumerable<DummyClass> source = oneToTen.Select(i => new DummyClass {Value = i}).ToArray();
|
||||
IEnumerable<int> values = source.Select(o => o.Value);
|
||||
CollectionAssert.AreEqual(oneToTen, values.ToArray());
|
||||
Assert.That(values.ToArray(), Is.EqualTo(oneToTen).AsCollection);
|
||||
|
||||
source.ForEach(o => o.Value *= 2);
|
||||
values = source.Select(o => o.Value);
|
||||
CollectionAssert.AreEqual(oneToTenDoubled, values.ToArray());
|
||||
Assert.That(values.ToArray(), Is.EqualTo(oneToTenDoubled).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -245,10 +245,10 @@ internal partial class EnumerableTests
|
||||
int[] array = Enumerable.Range(1, 52).ToArray(); // 52! chance of being shuffled to the same order
|
||||
int[] shuffled = array[..];
|
||||
|
||||
CollectionAssert.AreEqual(array, shuffled);
|
||||
Assert.That(shuffled, Is.EqualTo(array).AsCollection);
|
||||
|
||||
shuffled = array.Shuffled().ToArray();
|
||||
CollectionAssert.AreNotEqual(array, shuffled);
|
||||
Assert.That(shuffled, Is.Not.EqualTo(array).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -256,7 +256,7 @@ internal partial class EnumerableTests
|
||||
{
|
||||
var enumerable = new[] {2, 4, 6, 7, 8, 9, 10};
|
||||
IEnumerable<int> result = enumerable.WhereNot(x => x % 2 == 0);
|
||||
CollectionAssert.AreEqual(new[] {7, 9}, result.ToArray());
|
||||
Assert.That(result.ToArray(), Is.EqualTo(new[] { 7, 9 }).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -285,7 +285,7 @@ internal partial class EnumerableTests
|
||||
|
||||
foreach (object o in array.WhereNotNull())
|
||||
{
|
||||
Assert.IsNotNull(o);
|
||||
Assert.That(o, Is.Not.Null);
|
||||
actualCount++;
|
||||
}
|
||||
|
||||
|
@ -126,7 +126,7 @@ internal class Int16Tests
|
||||
Assert.Throws<ArgumentException>(() =>
|
||||
{
|
||||
const short value = 0b11010100;
|
||||
Span<bool> bits = stackalloc bool[0];
|
||||
Span<bool> bits = [];
|
||||
value.Unpack(bits);
|
||||
});
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ internal class Int32Tests
|
||||
Assert.Throws<ArgumentException>(() =>
|
||||
{
|
||||
const int value = 0b11010100;
|
||||
Span<bool> bits = stackalloc bool[0];
|
||||
Span<bool> bits = [];
|
||||
value.Unpack(bits);
|
||||
});
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ internal class Int64Tests
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() =>
|
||||
{
|
||||
Span<bool> bits = stackalloc bool[0];
|
||||
Span<bool> bits = [];
|
||||
0b11010100L.Unpack(bits);
|
||||
});
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ namespace X10D.Tests.Collections;
|
||||
[TestFixture]
|
||||
internal class ListTests
|
||||
{
|
||||
[Test]
|
||||
[Test]
|
||||
[TestCase(1)]
|
||||
[TestCase(1, 2, 3)]
|
||||
[TestCase(1, 2, 3, 4, 5)]
|
||||
@ -15,17 +15,17 @@ internal class ListTests
|
||||
int[] all42 = Enumerable.Repeat(42, args.Length).ToArray();
|
||||
var list = new List<int>(args);
|
||||
|
||||
CollectionAssert.AreEqual(args, list);
|
||||
Assert.That(list, Is.EqualTo(args).AsCollection);
|
||||
|
||||
args.Fill(42);
|
||||
list.Fill(42);
|
||||
|
||||
CollectionAssert.AreEqual(args, list);
|
||||
CollectionAssert.AreEqual(all42, args);
|
||||
CollectionAssert.AreEqual(all42, list);
|
||||
Assert.That(list, Is.EqualTo(args).AsCollection);
|
||||
Assert.That(args, Is.EqualTo(all42).AsCollection);
|
||||
Assert.That(list, Is.EqualTo(all42).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Test]
|
||||
[TestCase(1)]
|
||||
[TestCase(1, 2, 3)]
|
||||
[TestCase(1, 2, 3, 4, 5)]
|
||||
@ -36,13 +36,13 @@ internal class ListTests
|
||||
|
||||
int[] comparison = Enumerable.Repeat(1, args.Length - 1).ToArray();
|
||||
Assert.That(args[0], Is.EqualTo(first));
|
||||
CollectionAssert.AreEqual(comparison, args[1..]);
|
||||
Assert.That(args[1..], Is.EqualTo(comparison).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Fill_ShouldThrow_GivenExceededCount()
|
||||
{
|
||||
int[] array = Array.Empty<int>();
|
||||
int[] array = [];
|
||||
var list = new List<int>();
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => array.Fill(0, 0, 1));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => list.Fill(0, 0, 1));
|
||||
@ -51,7 +51,7 @@ internal class ListTests
|
||||
[Test]
|
||||
public void Fill_ShouldThrow_GivenNegativeCount()
|
||||
{
|
||||
int[] array = Array.Empty<int>();
|
||||
int[] array = [];
|
||||
var list = new List<int>();
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => array.Fill(0, 0, -1));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => list.Fill(0, 0, -1));
|
||||
@ -60,7 +60,7 @@ internal class ListTests
|
||||
[Test]
|
||||
public void Fill_ShouldThrow_GivenNegativeStartIndex()
|
||||
{
|
||||
int[] array = Array.Empty<int>();
|
||||
int[] array = [];
|
||||
var list = new List<int>();
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => array.Fill(0, -1, 0));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => list.Fill(0, -1, 0));
|
||||
@ -80,7 +80,7 @@ internal class ListTests
|
||||
[Test]
|
||||
public void IndexOf_ShouldReturnCorrectValue_FromStartOfList()
|
||||
{
|
||||
int[] array = {0, 1, 2, 3, 4};
|
||||
int[] array = [0, 1, 2, 3, 4];
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(array.IndexOf(2), Is.EqualTo(2));
|
||||
@ -92,7 +92,7 @@ internal class ListTests
|
||||
[Test]
|
||||
public void IndexOf_ShouldReturnCorrectValue_GivenSubRange()
|
||||
{
|
||||
int[] array = {0, 1, 2, 3, 4, 0};
|
||||
int[] array = [0, 1, 2, 3, 4, 0];
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(array.IndexOf(0), Is.Zero);
|
||||
@ -107,7 +107,7 @@ internal class ListTests
|
||||
[Test]
|
||||
public void IndexOf_ShouldReturnNegative1_ForEmptyList()
|
||||
{
|
||||
int[] array = Array.Empty<int>();
|
||||
int[] array = [];
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(array.IndexOf(0), Is.EqualTo(-1));
|
||||
@ -131,14 +131,14 @@ internal class ListTests
|
||||
[Test]
|
||||
public void IndexOf_ShouldThrowArgumentOutOfRangeException_GivenNegativeCount()
|
||||
{
|
||||
int[] array = Array.Empty<int>();
|
||||
int[] array = [];
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => array.IndexOf(0, 0, -1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IndexOf_ShouldThrowArgumentOutOfRangeException_GivenNegativeStartIndex()
|
||||
{
|
||||
int[] array = Array.Empty<int>();
|
||||
int[] array = [];
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => array.IndexOf(0, -1));
|
||||
@ -149,7 +149,7 @@ internal class ListTests
|
||||
[Test]
|
||||
public void IndexOf_ShouldThrowArgumentOutOfRangeException_GivenInvalidStartIndexCountPair()
|
||||
{
|
||||
int[] array = {0, 1, 2};
|
||||
int[] array = [0, 1, 2];
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => array.IndexOf(0, 2, 4));
|
||||
}
|
||||
|
||||
@ -184,7 +184,7 @@ internal class ListTests
|
||||
public void RemoveRange_ShouldThrowArgumentOutOfRangeException_GivenEndIndexGreaterThanOrEqualToCount()
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new List<int>().RemoveRange(..0));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new List<int> {1}.RemoveRange(..2));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new List<int> { 1 }.RemoveRange(..2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -208,7 +208,7 @@ internal class ListTests
|
||||
list.RemoveRange(2..5);
|
||||
|
||||
Assert.That(list, Has.Count.EqualTo(6));
|
||||
CollectionAssert.AreEqual(new[] {1, 2, 7, 8, 9, 10}, list);
|
||||
Assert.That(list, Is.EqualTo(new[] { 1, 2, 7, 8, 9, 10 }).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -217,11 +217,11 @@ internal class ListTests
|
||||
var list = new List<int>(Enumerable.Range(1, 52)); // 52! chance of being shuffled to the same order
|
||||
var shuffled = new List<int>(list);
|
||||
|
||||
CollectionAssert.AreEqual(list, shuffled);
|
||||
Assert.That(shuffled, Is.EqualTo(list).AsCollection);
|
||||
|
||||
shuffled.Shuffle();
|
||||
|
||||
CollectionAssert.AreNotEqual(list, shuffled);
|
||||
Assert.That(shuffled, Is.Not.EqualTo(list).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -233,23 +233,23 @@ internal class ListTests
|
||||
[Test]
|
||||
public void Slice_ShouldReturnCorrectValue_GivenStartIndex()
|
||||
{
|
||||
int[] array = {0, 1, 2, 3, 4, 5};
|
||||
CollectionAssert.AreEqual(new[] {2, 3, 4, 5}, array.Slice(2).ToArray());
|
||||
int[] array = [0, 1, 2, 3, 4, 5];
|
||||
Assert.That(array.Slice(2).ToArray(), Is.EqualTo(new[] { 2, 3, 4, 5 }).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Slice_ShouldReturnCorrectValue_GivenStartIndexAndLength()
|
||||
{
|
||||
int[] array = {0, 1, 2, 3, 4, 5};
|
||||
CollectionAssert.AreEqual(new[] {2, 3, 4}, array.Slice(2, 3).ToArray());
|
||||
int[] array = [0, 1, 2, 3, 4, 5];
|
||||
Assert.That(array.Slice(2, 3).ToArray(), Is.EqualTo(new[] { 2, 3, 4 }).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Slice_ShouldReturnEmptyList_ForEmptyList()
|
||||
{
|
||||
int[] array = Array.Empty<int>();
|
||||
CollectionAssert.AreEqual(Array.Empty<int>(), array.Slice(0).ToArray());
|
||||
CollectionAssert.AreEqual(Array.Empty<int>(), array.Slice(0, 0).ToArray());
|
||||
int[] array = [];
|
||||
Assert.That(array.Slice(0).ToArray(), Is.EqualTo(Array.Empty<int>()).AsCollection);
|
||||
Assert.That(array.Slice(0, 0).ToArray(), Is.EqualTo(Array.Empty<int>()).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -263,14 +263,14 @@ internal class ListTests
|
||||
[Test]
|
||||
public void Slice_ShouldThrowArgumentOutOfRangeException_GivenNegativeCount()
|
||||
{
|
||||
int[] array = Array.Empty<int>();
|
||||
int[] array = [];
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => array.Slice(0, -1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Slice_ShouldThrowArgumentOutOfRangeException_GivenNegativeStartIndex()
|
||||
{
|
||||
int[] array = Array.Empty<int>();
|
||||
int[] array = [];
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => array.Slice(-1));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => array.Slice(-1, 0));
|
||||
}
|
||||
@ -278,7 +278,7 @@ internal class ListTests
|
||||
[Test]
|
||||
public void Slice_ShouldThrowArgumentOutOfRangeException_GivenInvalidStartIndexCountPair()
|
||||
{
|
||||
int[] array = {0, 1, 2};
|
||||
int[] array = [0, 1, 2];
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => array.Slice(2, 4));
|
||||
}
|
||||
|
||||
@ -297,18 +297,18 @@ internal class ListTests
|
||||
[Test]
|
||||
public void Swap_ShouldSwapElements_GivenMatchingElementCount()
|
||||
{
|
||||
var first = new List<int> {1, 2, 3};
|
||||
var second = new List<int> {4, 5, 6};
|
||||
var first = new List<int> { 1, 2, 3 };
|
||||
var second = new List<int> { 4, 5, 6 };
|
||||
|
||||
first.Swap(second);
|
||||
|
||||
CollectionAssert.AreEqual(new[] {4, 5, 6}, first, string.Join(' ', first));
|
||||
CollectionAssert.AreEqual(new[] {1, 2, 3}, second, string.Join(' ', second));
|
||||
Assert.That(first, Is.EqualTo(new[] { 4, 5, 6 }).AsCollection, string.Join(' ', first));
|
||||
Assert.That(second, Is.EqualTo(new[] { 1, 2, 3 }).AsCollection, string.Join(' ', second));
|
||||
|
||||
first.Swap(second);
|
||||
|
||||
CollectionAssert.AreEqual(new[] {1, 2, 3}, first, string.Join(' ', first));
|
||||
CollectionAssert.AreEqual(new[] {4, 5, 6}, second, string.Join(' ', second));
|
||||
Assert.That(first, Is.EqualTo(new[] { 1, 2, 3 }).AsCollection, string.Join(' ', first));
|
||||
Assert.That(second, Is.EqualTo(new[] { 4, 5, 6 }).AsCollection, string.Join(' ', second));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -322,16 +322,16 @@ internal class ListTests
|
||||
4,
|
||||
5
|
||||
};
|
||||
var second = new List<int> {6, 7};
|
||||
var second = new List<int> { 6, 7 };
|
||||
|
||||
first.Swap(second);
|
||||
|
||||
CollectionAssert.AreEqual(new[] {6, 7}, first, string.Join(' ', first));
|
||||
CollectionAssert.AreEqual(new[] {1, 2, 3, 4, 5}, second, string.Join(' ', second));
|
||||
Assert.That(first, Is.EqualTo(new[] { 6, 7 }).AsCollection, string.Join(' ', first));
|
||||
Assert.That(second, Is.EqualTo(new[] { 1, 2, 3, 4, 5 }).AsCollection, string.Join(' ', second));
|
||||
|
||||
first.Swap(second);
|
||||
|
||||
CollectionAssert.AreEqual(new[] {1, 2, 3, 4, 5}, first, string.Join(' ', first));
|
||||
CollectionAssert.AreEqual(new[] {6, 7}, second, string.Join(' ', second));
|
||||
Assert.That(first, Is.EqualTo(new[] { 1, 2, 3, 4, 5 }).AsCollection, string.Join(' ', first));
|
||||
Assert.That(second, Is.EqualTo(new[] { 6, 7 }).AsCollection, string.Join(' ', second));
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
using NUnit.Framework;
|
||||
#if !NET9_0_OR_GREATER
|
||||
using X10D.Collections;
|
||||
#endif
|
||||
|
||||
namespace X10D.Tests.Collections;
|
||||
|
||||
@ -29,7 +31,7 @@ internal class SpanTest
|
||||
[Test]
|
||||
public void Count_ShouldReturn8_GivenSpanWith8MatchingElements()
|
||||
{
|
||||
Span<int> span = stackalloc int[16] {1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2};
|
||||
Span<int> span = [1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2];
|
||||
|
||||
int count = span.Count(2);
|
||||
|
||||
@ -39,7 +41,7 @@ internal class SpanTest
|
||||
[Test]
|
||||
public void Count_ShouldReturn8_GivenReadOnlySpanWith8MatchingElements()
|
||||
{
|
||||
ReadOnlySpan<int> span = stackalloc int[16] {1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2};
|
||||
ReadOnlySpan<int> span = [1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2];
|
||||
|
||||
int count = span.Count(2);
|
||||
|
||||
@ -49,27 +51,28 @@ internal class SpanTest
|
||||
[Test]
|
||||
public void Replace_ShouldReplaceAllElements_GivenSpanOfInt32()
|
||||
{
|
||||
Span<int> span = stackalloc int[16] {1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2};
|
||||
Span<int> span = [1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2];
|
||||
span.Replace(2, 4);
|
||||
Assert.That(span.ToArray(), Is.EqualTo(new[] {1, 4, 3, 4, 5, 4, 7, 4, 9, 4, 11, 4, 13, 4, 15, 4}));
|
||||
Assert.That(span.ToArray(), Is.EqualTo(new[] { 1, 4, 3, 4, 5, 4, 7, 4, 9, 4, 11, 4, 13, 4, 15, 4 }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Replace_ShouldReplaceAllElements_GivenSpanOfChar()
|
||||
{
|
||||
Span<char> chars = stackalloc char[12] {'H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!'};
|
||||
Span<char> chars = ['H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!'];
|
||||
chars.Replace('l', 'w');
|
||||
CollectionAssert.AreEqual(chars.ToArray(), "Hewwo worwd!".ToCharArray());
|
||||
Assert.That("Hewwo worwd!".ToCharArray(), Is.EqualTo(chars.ToArray()).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Replace_ShouldDoNothing_GivenSpanWithNoMatchingElements()
|
||||
{
|
||||
Span<int> span = stackalloc int[16] {1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2};
|
||||
Span<int> span = [1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2];
|
||||
span.Replace(4, 8);
|
||||
Assert.That(span.ToArray(), Is.EqualTo(new[] {1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2}));
|
||||
Assert.That(span.ToArray(), Is.EqualTo(new[] { 1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2 }));
|
||||
}
|
||||
|
||||
#if !NET9_0_OR_GREATER
|
||||
[Test]
|
||||
public void Split_OnEmptySpan_ShouldYieldNothing_UsingCharDelimiter_GivenReadOnlySpan()
|
||||
{
|
||||
@ -497,4 +500,5 @@ internal class SpanTest
|
||||
|
||||
Assert.That(index, Is.EqualTo(3));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ internal class CoreTests
|
||||
// ReSharper disable once PossibleMultipleEnumeration
|
||||
object[] array = enumerable.ToArray();
|
||||
Assert.That(array, Has.Length.EqualTo(10));
|
||||
CollectionAssert.AreEqual(new[] {o, o, o, o, o, o, o, o, o, o}, array);
|
||||
Assert.That(array, Is.EqualTo(new[] { o, o, o, o, o, o, o, o, o, o }).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -1,4 +1,3 @@
|
||||
using System.Runtime.Intrinsics.Arm;
|
||||
using System.Runtime.Intrinsics.X86;
|
||||
using NUnit.Framework;
|
||||
using X10D.Core;
|
||||
@ -13,7 +12,7 @@ internal class SpanTest
|
||||
{
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
ReadOnlySpan<EnumByte> span = stackalloc EnumByte[1] {EnumByte.B};
|
||||
ReadOnlySpan<EnumByte> span = [EnumByte.B];
|
||||
Assert.That(span.Contains(EnumByte.A), Is.False);
|
||||
Assert.That(span.Contains(EnumByte.C), Is.False);
|
||||
});
|
||||
@ -24,7 +23,7 @@ internal class SpanTest
|
||||
{
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
ReadOnlySpan<EnumInt16> span = stackalloc EnumInt16[1] {EnumInt16.B};
|
||||
ReadOnlySpan<EnumInt16> span = [EnumInt16.B];
|
||||
Assert.That(span.Contains(EnumInt16.A), Is.False);
|
||||
Assert.That(span.Contains(EnumInt16.C), Is.False);
|
||||
});
|
||||
@ -35,7 +34,7 @@ internal class SpanTest
|
||||
{
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
ReadOnlySpan<EnumInt32> span = stackalloc EnumInt32[1] {EnumInt32.B};
|
||||
ReadOnlySpan<EnumInt32> span = [EnumInt32.B];
|
||||
Assert.That(span.Contains(EnumInt32.A), Is.False);
|
||||
Assert.That(span.Contains(EnumInt32.C), Is.False);
|
||||
});
|
||||
@ -46,7 +45,7 @@ internal class SpanTest
|
||||
{
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
ReadOnlySpan<EnumInt64> span = stackalloc EnumInt64[1] {EnumInt64.B};
|
||||
ReadOnlySpan<EnumInt64> span = [EnumInt64.B];
|
||||
|
||||
Assert.That(span.Contains(EnumInt64.A), Is.False);
|
||||
Assert.That(span.Contains(EnumInt64.C), Is.False);
|
||||
@ -56,7 +55,7 @@ internal class SpanTest
|
||||
[Test]
|
||||
public void Contains_ShouldReturnTrue_GivenReadOnlySpanWithMatchingElements_UsingByteEnum()
|
||||
{
|
||||
ReadOnlySpan<EnumByte> span = stackalloc EnumByte[1] {EnumByte.B};
|
||||
ReadOnlySpan<EnumByte> span = [EnumByte.B];
|
||||
|
||||
Assert.That(span.Contains(EnumByte.B));
|
||||
}
|
||||
@ -64,7 +63,7 @@ internal class SpanTest
|
||||
[Test]
|
||||
public void Contains_ShouldReturnTrue_GivenReadOnlySpanWithMatchingElements_UsingInt16Enum()
|
||||
{
|
||||
ReadOnlySpan<EnumInt16> span = stackalloc EnumInt16[1] {EnumInt16.B};
|
||||
ReadOnlySpan<EnumInt16> span = [EnumInt16.B];
|
||||
|
||||
Assert.That(span.Contains(EnumInt16.B));
|
||||
}
|
||||
@ -72,7 +71,7 @@ internal class SpanTest
|
||||
[Test]
|
||||
public void Contains_ShouldReturnTrue_GivenReadOnlySpanWithMatchingElements_UsingInt32Enum()
|
||||
{
|
||||
ReadOnlySpan<EnumInt32> span = stackalloc EnumInt32[1] {EnumInt32.B};
|
||||
ReadOnlySpan<EnumInt32> span = [EnumInt32.B];
|
||||
|
||||
Assert.That(span.Contains(EnumInt32.B));
|
||||
}
|
||||
@ -80,7 +79,7 @@ internal class SpanTest
|
||||
[Test]
|
||||
public void Contains_ShouldReturnTrue_GivenReadOnlySpanWithMatchingElements_UsingInt64Enum()
|
||||
{
|
||||
ReadOnlySpan<EnumInt64> span = stackalloc EnumInt64[1] {EnumInt64.B};
|
||||
ReadOnlySpan<EnumInt64> span = [EnumInt64.B];
|
||||
|
||||
Assert.That(span.Contains(EnumInt64.B));
|
||||
}
|
||||
@ -90,7 +89,7 @@ internal class SpanTest
|
||||
{
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<EnumByte> span = stackalloc EnumByte[1] {EnumByte.B};
|
||||
Span<EnumByte> span = [EnumByte.B];
|
||||
|
||||
Assert.That(span.Contains(EnumByte.A), Is.False);
|
||||
Assert.That(span.Contains(EnumByte.C), Is.False);
|
||||
@ -100,7 +99,7 @@ internal class SpanTest
|
||||
[Test]
|
||||
public void Contains_ShouldReturnFalse_GivenSpanWithNoMatchingElements_UsingInt16Enum()
|
||||
{
|
||||
Span<EnumInt16> span = stackalloc EnumInt16[1] {EnumInt16.B};
|
||||
Span<EnumInt16> span = [EnumInt16.B];
|
||||
|
||||
Assert.That(span.Contains(EnumInt16.A), Is.False);
|
||||
Assert.That(span.Contains(EnumInt16.C), Is.False);
|
||||
@ -109,7 +108,7 @@ internal class SpanTest
|
||||
[Test]
|
||||
public void Contains_ShouldReturnFalse_GivenSpanWithNoMatchingElements_UsingInt32Enum()
|
||||
{
|
||||
Span<EnumInt32> span = stackalloc EnumInt32[1] {EnumInt32.B};
|
||||
Span<EnumInt32> span = [EnumInt32.B];
|
||||
|
||||
Assert.That(span.Contains(EnumInt32.A), Is.False);
|
||||
Assert.That(span.Contains(EnumInt32.C), Is.False);
|
||||
@ -118,7 +117,7 @@ internal class SpanTest
|
||||
[Test]
|
||||
public void Contains_ShouldReturnFalse_GivenSpanWithNoMatchingElements_UsingInt64Enum()
|
||||
{
|
||||
Span<EnumInt64> span = stackalloc EnumInt64[1] {EnumInt64.B};
|
||||
Span<EnumInt64> span = [EnumInt64.B];
|
||||
|
||||
Assert.That(span.Contains(EnumInt64.A), Is.False);
|
||||
Assert.That(span.Contains(EnumInt64.C), Is.False);
|
||||
@ -127,7 +126,7 @@ internal class SpanTest
|
||||
[Test]
|
||||
public void Contains_ShouldReturnTrue_GivenSpanWithMatchingElements_UsingByteEnum()
|
||||
{
|
||||
Span<EnumByte> span = stackalloc EnumByte[1] {EnumByte.B};
|
||||
Span<EnumByte> span = [EnumByte.B];
|
||||
|
||||
Assert.That(span.Contains(EnumByte.B));
|
||||
}
|
||||
@ -135,7 +134,7 @@ internal class SpanTest
|
||||
[Test]
|
||||
public void Contains_ShouldReturnTrue_GivenSpanWithMatchingElements_UsingInt16Enum()
|
||||
{
|
||||
Span<EnumInt16> span = stackalloc EnumInt16[1] {EnumInt16.B};
|
||||
Span<EnumInt16> span = [EnumInt16.B];
|
||||
|
||||
Assert.That(span.Contains(EnumInt16.B));
|
||||
}
|
||||
@ -143,7 +142,7 @@ internal class SpanTest
|
||||
[Test]
|
||||
public void Contains_ShouldReturnTrue_GivenSpanWithMatchingElements_UsingInt32Enum()
|
||||
{
|
||||
Span<EnumInt32> span = stackalloc EnumInt32[1] {EnumInt32.B};
|
||||
Span<EnumInt32> span = [EnumInt32.B];
|
||||
|
||||
Assert.That(span.Contains(EnumInt32.B));
|
||||
}
|
||||
@ -151,7 +150,7 @@ internal class SpanTest
|
||||
[Test]
|
||||
public void Contains_ShouldReturnTrue_GivenSpanWithMatchingElements_UsingInt64Enum()
|
||||
{
|
||||
Span<EnumInt64> span = stackalloc EnumInt64[1] {EnumInt64.B};
|
||||
Span<EnumInt64> span = [EnumInt64.B];
|
||||
|
||||
Assert.That(span.Contains(EnumInt64.B));
|
||||
}
|
||||
@ -200,7 +199,7 @@ internal class SpanTest
|
||||
public void PackByteInternal_Fallback_ShouldReturnCorrectByte_GivenReadOnlySpan_Using()
|
||||
{
|
||||
const byte expected = 0b00110011;
|
||||
ReadOnlySpan<bool> span = stackalloc bool[8] {true, true, false, false, true, true, false, false};
|
||||
ReadOnlySpan<bool> span = [true, true, false, false, true, true, false, false];
|
||||
|
||||
byte actual = span.PackByteInternal_Fallback();
|
||||
|
||||
@ -216,7 +215,7 @@ internal class SpanTest
|
||||
}
|
||||
|
||||
const byte expected = 0b00110011;
|
||||
ReadOnlySpan<bool> span = stackalloc bool[8] {true, true, false, false, true, true, false, false};
|
||||
ReadOnlySpan<bool> span = [true, true, false, false, true, true, false, false];
|
||||
|
||||
byte actual = span.PackByteInternal_Sse2();
|
||||
|
||||
@ -226,7 +225,7 @@ internal class SpanTest
|
||||
[Test]
|
||||
public void PackInt16_ShouldReturnSameAsPackByte_WhenSpanHasLength8()
|
||||
{
|
||||
ReadOnlySpan<bool> span = stackalloc bool[8] {true, true, false, false, true, true, false, false};
|
||||
ReadOnlySpan<bool> span = [true, true, false, false, true, true, false, false];
|
||||
|
||||
short expected = span.PackByte();
|
||||
short actual = span.PackInt16();
|
||||
@ -238,10 +237,10 @@ internal class SpanTest
|
||||
public void PackInt16Internal_Fallback_ShouldReturnCorrectInt16_GivenReadOnlySpan()
|
||||
{
|
||||
const short expected = 0b00101101_11010100;
|
||||
ReadOnlySpan<bool> span = stackalloc bool[16]
|
||||
{
|
||||
false, false, true, false, true, false, true, true, true, false, true, true, false, true, false, false,
|
||||
};
|
||||
ReadOnlySpan<bool> span =
|
||||
[
|
||||
false, false, true, false, true, false, true, true, true, false, true, true, false, true, false, false
|
||||
];
|
||||
|
||||
short actual = span.PackInt16Internal_Fallback();
|
||||
|
||||
@ -257,10 +256,10 @@ internal class SpanTest
|
||||
}
|
||||
|
||||
const short expected = 0b00101101_11010100;
|
||||
ReadOnlySpan<bool> span = stackalloc bool[16]
|
||||
{
|
||||
false, false, true, false, true, false, true, true, true, false, true, true, false, true, false, false,
|
||||
};
|
||||
ReadOnlySpan<bool> span =
|
||||
[
|
||||
false, false, true, false, true, false, true, true, true, false, true, true, false, true, false, false
|
||||
];
|
||||
|
||||
short actual = span.PackInt16Internal_Sse2();
|
||||
|
||||
@ -271,11 +270,11 @@ internal class SpanTest
|
||||
public void PackInt32Internal_Fallback_ShouldReturnCorrectInt32_GivenReadOnlySpan()
|
||||
{
|
||||
const int expected = 0b01010101_10101010_01010101_10101010;
|
||||
ReadOnlySpan<bool> span = stackalloc bool[32]
|
||||
{
|
||||
ReadOnlySpan<bool> span =
|
||||
[
|
||||
false, true, false, true, false, true, false, true, true, false, true, false, true, false, true, false, false,
|
||||
true, false, true, false, true, false, true, true, false, true, false, true, false, true, false,
|
||||
};
|
||||
true, false, true, false, true, false, true, true, false, true, false, true, false, true, false
|
||||
];
|
||||
|
||||
int actual = span.PackInt32Internal_Fallback();
|
||||
|
||||
@ -291,11 +290,11 @@ internal class SpanTest
|
||||
}
|
||||
|
||||
const int expected = 0b01010101_10101010_01010101_10101010;
|
||||
ReadOnlySpan<bool> span = stackalloc bool[32]
|
||||
{
|
||||
ReadOnlySpan<bool> span =
|
||||
[
|
||||
false, true, false, true, false, true, false, true, true, false, true, false, true, false, true, false, false,
|
||||
true, false, true, false, true, false, true, true, false, true, false, true, false, true, false,
|
||||
};
|
||||
true, false, true, false, true, false, true, true, false, true, false, true, false, true, false
|
||||
];
|
||||
|
||||
int actual = span.PackInt32Internal_Sse2();
|
||||
|
||||
@ -311,11 +310,11 @@ internal class SpanTest
|
||||
}
|
||||
|
||||
const int expected = 0b01010101_10101010_01010101_10101010;
|
||||
ReadOnlySpan<bool> span = stackalloc bool[32]
|
||||
{
|
||||
ReadOnlySpan<bool> span =
|
||||
[
|
||||
false, true, false, true, false, true, false, true, true, false, true, false, true, false, true, false, false,
|
||||
true, false, true, false, true, false, true, true, false, true, false, true, false, true, false,
|
||||
};
|
||||
true, false, true, false, true, false, true, true, false, true, false, true, false, true, false
|
||||
];
|
||||
|
||||
int actual = span.PackInt32Internal_Avx2();
|
||||
|
||||
@ -325,7 +324,7 @@ internal class SpanTest
|
||||
[Test]
|
||||
public void PackInt32_ShouldReturnSameAsPackByte_WhenSpanHasLength8_UsingReadOnlySpan()
|
||||
{
|
||||
ReadOnlySpan<bool> span = stackalloc bool[8] {true, true, false, false, true, true, false, false};
|
||||
ReadOnlySpan<bool> span = [true, true, false, false, true, true, false, false];
|
||||
|
||||
int expected = span.PackByte();
|
||||
int actual = span.PackInt32();
|
||||
@ -336,7 +335,7 @@ internal class SpanTest
|
||||
[Test]
|
||||
public void PackInt32_ShouldReturnSameAsPackByte_WhenSpanHasLength8_UsingSpan()
|
||||
{
|
||||
Span<bool> span = stackalloc bool[8] {true, true, false, false, true, true, false, false};
|
||||
Span<bool> span = [true, true, false, false, true, true, false, false];
|
||||
|
||||
int expected = span.PackByte();
|
||||
int actual = span.PackInt32();
|
||||
@ -347,10 +346,10 @@ internal class SpanTest
|
||||
[Test]
|
||||
public void PackInt32_ShouldReturnSameAsPackInt16_WhenSpanHasLength16_UsingReadOnlySpan()
|
||||
{
|
||||
ReadOnlySpan<bool> span = stackalloc bool[16]
|
||||
{
|
||||
false, false, true, false, true, false, true, true, true, false, true, true, false, true, false, false,
|
||||
};
|
||||
ReadOnlySpan<bool> span =
|
||||
[
|
||||
false, false, true, false, true, false, true, true, true, false, true, true, false, true, false, false
|
||||
];
|
||||
|
||||
int expected = span.PackInt16();
|
||||
int actual = span.PackInt32();
|
||||
@ -361,10 +360,10 @@ internal class SpanTest
|
||||
[Test]
|
||||
public void PackInt32_ShouldReturnSameAsPackInt16_WhenSpanHasLength16_UsingSpan()
|
||||
{
|
||||
Span<bool> span = stackalloc bool[16]
|
||||
{
|
||||
false, false, true, false, true, false, true, true, true, false, true, true, false, true, false, false,
|
||||
};
|
||||
Span<bool> span =
|
||||
[
|
||||
false, false, true, false, true, false, true, true, true, false, true, true, false, true, false, false
|
||||
];
|
||||
|
||||
int expected = span.PackInt16();
|
||||
int actual = span.PackInt32();
|
||||
@ -376,13 +375,13 @@ internal class SpanTest
|
||||
public void PackInt64_ShouldReturnCorrectInt64_GivenReadOnlySpan()
|
||||
{
|
||||
const long expected = 0b01010101_11010110_01101001_11010110_00010010_10010111_00101100_10100101;
|
||||
ReadOnlySpan<bool> span = stackalloc bool[64]
|
||||
{
|
||||
ReadOnlySpan<bool> span =
|
||||
[
|
||||
true, false, true, false, false, true, false, true, false, false, true, true, false, true, false, false, true,
|
||||
true, true, false, true, false, false, true, false, true, false, false, true, false, false, false, false, true,
|
||||
true, false, true, false, true, true, true, false, false, true, false, true, true, false, false, true, true,
|
||||
false, true, false, true, true, true, false, true, false, true, false, true, false,
|
||||
};
|
||||
false, true, false, true, true, true, false, true, false, true, false, true, false
|
||||
];
|
||||
|
||||
long actual = span.PackInt64();
|
||||
|
||||
@ -393,13 +392,13 @@ internal class SpanTest
|
||||
public void PackInt64_ShouldReturnCorrectInt64_GivenSpan()
|
||||
{
|
||||
const long expected = 0b01010101_11010110_01101001_11010110_00010010_10010111_00101100_10100101;
|
||||
Span<bool> span = stackalloc bool[64]
|
||||
{
|
||||
Span<bool> span =
|
||||
[
|
||||
true, false, true, false, false, true, false, true, false, false, true, true, false, true, false, false, true,
|
||||
true, true, false, true, false, false, true, false, true, false, false, true, false, false, false, false, true,
|
||||
true, false, true, false, true, true, true, false, false, true, false, true, true, false, false, true, true,
|
||||
false, true, false, true, true, true, false, true, false, true, false, true, false,
|
||||
};
|
||||
false, true, false, true, true, true, false, true, false, true, false, true, false
|
||||
];
|
||||
|
||||
long actual = span.PackInt64();
|
||||
|
||||
@ -409,7 +408,7 @@ internal class SpanTest
|
||||
[Test]
|
||||
public void PackInt64_ShouldReturnSameAsPackByte_WhenSpanHasLength8_UsingReadOnlySpan()
|
||||
{
|
||||
ReadOnlySpan<bool> span = stackalloc bool[8] {true, true, false, false, true, true, false, false};
|
||||
ReadOnlySpan<bool> span = [true, true, false, false, true, true, false, false];
|
||||
|
||||
long expected = span.PackByte();
|
||||
long actual = span.PackInt64();
|
||||
@ -420,7 +419,7 @@ internal class SpanTest
|
||||
[Test]
|
||||
public void PackInt64_ShouldReturnSameAsPackByte_WhenSpanHasLength8_UsingSpan()
|
||||
{
|
||||
Span<bool> span = stackalloc bool[8] {true, true, false, false, true, true, false, false};
|
||||
Span<bool> span = [true, true, false, false, true, true, false, false];
|
||||
|
||||
long expected = span.PackByte();
|
||||
long actual = span.PackInt64();
|
||||
@ -431,10 +430,10 @@ internal class SpanTest
|
||||
[Test]
|
||||
public void PackInt64_ShouldReturnSameAsPackInt16_WhenSpanHasLength16_UsingReadOnlySpan()
|
||||
{
|
||||
ReadOnlySpan<bool> span = stackalloc bool[16]
|
||||
{
|
||||
false, false, true, false, true, false, true, true, true, false, true, true, false, true, false, false,
|
||||
};
|
||||
ReadOnlySpan<bool> span =
|
||||
[
|
||||
false, false, true, false, true, false, true, true, true, false, true, true, false, true, false, false
|
||||
];
|
||||
|
||||
long expected = span.PackInt16();
|
||||
long actual = span.PackInt64();
|
||||
@ -445,10 +444,10 @@ internal class SpanTest
|
||||
[Test]
|
||||
public void PackInt64_ShouldReturnSameAsPackInt16_WhenSpanHasLength16_UsingSpan()
|
||||
{
|
||||
Span<bool> span = stackalloc bool[16]
|
||||
{
|
||||
false, false, true, false, true, false, true, true, true, false, true, true, false, true, false, false,
|
||||
};
|
||||
Span<bool> span =
|
||||
[
|
||||
false, false, true, false, true, false, true, true, true, false, true, true, false, true, false, false
|
||||
];
|
||||
|
||||
long expected = span.PackInt16();
|
||||
long actual = span.PackInt64();
|
||||
@ -459,11 +458,11 @@ internal class SpanTest
|
||||
[Test]
|
||||
public void PackInt64_ShouldReturnSameAsPackInt32_WhenSpanHasLength16_UsingReadOnlySpan()
|
||||
{
|
||||
ReadOnlySpan<bool> span = stackalloc bool[32]
|
||||
{
|
||||
ReadOnlySpan<bool> span =
|
||||
[
|
||||
false, true, false, true, false, true, false, true, true, false, true, false, true, false, true, false, false,
|
||||
true, false, true, false, true, false, true, true, false, true, false, true, false, true, false,
|
||||
};
|
||||
true, false, true, false, true, false, true, true, false, true, false, true, false, true, false
|
||||
];
|
||||
|
||||
long expected = span.PackInt32();
|
||||
long actual = span.PackInt64();
|
||||
@ -474,11 +473,11 @@ internal class SpanTest
|
||||
[Test]
|
||||
public void PackInt64_ShouldReturnSameAsPackInt32_WhenSpanHasLength16_UsingSpan()
|
||||
{
|
||||
Span<bool> span = stackalloc bool[32]
|
||||
{
|
||||
Span<bool> span =
|
||||
[
|
||||
false, true, false, true, false, true, false, true, true, false, true, false, true, false, true, false, false,
|
||||
true, false, true, false, true, false, true, true, false, true, false, true, false, true, false,
|
||||
};
|
||||
true, false, true, false, true, false, true, true, false, true, false, true, false, true, false
|
||||
];
|
||||
|
||||
long expected = span.PackInt32();
|
||||
long actual = span.PackInt64();
|
||||
@ -490,7 +489,7 @@ internal class SpanTest
|
||||
public void PackInt64_ShouldFallbackAndReturnCorrectValue_GivenNonPowerOfTwoLength_UsingReadOnlySpan()
|
||||
{
|
||||
const long expected = 0b00000000_00000000_00000000_00000000_00000000_00000000_00000001_01010011;
|
||||
ReadOnlySpan<bool> span = stackalloc bool[10] {true, true, false, false, true, false, true, false, true, false};
|
||||
ReadOnlySpan<bool> span = [true, true, false, false, true, false, true, false, true, false];
|
||||
|
||||
long actual = span.PackInt64();
|
||||
|
||||
@ -501,7 +500,7 @@ internal class SpanTest
|
||||
public void PackInt64_ShouldFallbackAndReturnCorrectValue_GivenNonPowerOfTwoLength_UsingSpan()
|
||||
{
|
||||
const long expected = 0b00000000_00000000_00000000_00000000_00000000_00000000_00000001_01010011;
|
||||
Span<bool> span = stackalloc bool[10] {true, true, false, false, true, false, true, false, true, false};
|
||||
Span<bool> span = [true, true, false, false, true, false, true, false, true, false];
|
||||
|
||||
long actual = span.PackInt64();
|
||||
|
||||
|
@ -12,7 +12,7 @@ internal class PolygonFTests
|
||||
public void AddVertices_ShouldAddVertices()
|
||||
{
|
||||
var polygon = PolygonF.Empty;
|
||||
polygon.AddVertices(new[] {new PointF(1, 2), new PointF(3, 4)});
|
||||
polygon.AddVertices([new PointF(1, 2), new PointF(3, 4)]);
|
||||
Assert.That(polygon.VertexCount, Is.EqualTo(2));
|
||||
|
||||
// assert that the empty polygon was not modified
|
||||
@ -39,7 +39,7 @@ internal class PolygonFTests
|
||||
public void ClearVertices_ShouldClearVertices()
|
||||
{
|
||||
var polygon = PolygonF.Empty;
|
||||
polygon.AddVertices(new[] {new Vector2(1, 2), new Vector2(3, 4)});
|
||||
polygon.AddVertices([new Vector2(1, 2), new Vector2(3, 4)]);
|
||||
Assert.That(polygon.VertexCount, Is.EqualTo(2));
|
||||
|
||||
// assert that the empty polygon was not modified
|
||||
@ -52,8 +52,8 @@ internal class PolygonFTests
|
||||
[Test]
|
||||
public void Constructor_ShouldPopulateVertices_GivenPolygon()
|
||||
{
|
||||
var pointPolygon = new PolygonF(new[] {new PointF(1, 2), new PointF(3, 4)});
|
||||
var vectorPolygon = new PolygonF(new[] {new Vector2(1, 2), new Vector2(3, 4)});
|
||||
var pointPolygon = new PolygonF([new PointF(1, 2), new PointF(3, 4)]);
|
||||
var vectorPolygon = new PolygonF([new Vector2(1, 2), new Vector2(3, 4)]);
|
||||
|
||||
Assert.That(pointPolygon.VertexCount, Is.EqualTo(2));
|
||||
Assert.That(vectorPolygon.VertexCount, Is.EqualTo(2));
|
||||
@ -77,7 +77,7 @@ internal class PolygonFTests
|
||||
public void CopyConstructor_ShouldCopyVertices_GivenPolygon()
|
||||
{
|
||||
var first = PolygonF.Empty;
|
||||
first.AddVertices(new[] {new PointF(1, 2), new PointF(3, 4)});
|
||||
first.AddVertices([new PointF(1, 2), new PointF(3, 4)]);
|
||||
|
||||
var second = new PolygonF(first);
|
||||
Assert.That(first.VertexCount, Is.EqualTo(2));
|
||||
@ -85,7 +85,7 @@ internal class PolygonFTests
|
||||
|
||||
// we cannot use CollectionAssert here for reasons I am not entirely sure of.
|
||||
// it seems to dislike casting from IReadOnlyList<Point> to ICollection. but okay.
|
||||
CollectionAssert.AreEqual(first.Vertices, second.Vertices);
|
||||
Assert.That(second.Vertices, Is.EqualTo(first.Vertices).AsCollection);
|
||||
|
||||
// assert that the empty polygon was not modified
|
||||
Assert.That(PolygonF.Empty.VertexCount, Is.Zero);
|
||||
@ -178,7 +178,7 @@ internal class PolygonFTests
|
||||
Assert.That(converted, Is.EqualTo((Polygon)polygon));
|
||||
Assert.That(converted.IsConvex, Is.EqualTo(polygon.IsConvex));
|
||||
Assert.That(converted.VertexCount, Is.EqualTo(polygon.VertexCount));
|
||||
CollectionAssert.AreEqual(polygon.Vertices, converted.Vertices.Select(p => (PointF)p));
|
||||
Assert.That(converted.Vertices.Select(p => (PointF)p), Is.EqualTo(polygon.Vertices).AsCollection);
|
||||
});
|
||||
}
|
||||
|
||||
@ -194,7 +194,7 @@ internal class PolygonFTests
|
||||
Assert.That(converted == polygon);
|
||||
Assert.That(converted.IsConvex, Is.EqualTo(polygon.IsConvex));
|
||||
Assert.That(converted.VertexCount, Is.EqualTo(polygon.VertexCount));
|
||||
CollectionAssert.AreEqual(converted.Vertices, polygon.Vertices.Select(p => (PointF)p));
|
||||
Assert.That(polygon.Vertices.Select(p => (PointF)p), Is.EqualTo(converted.Vertices).AsCollection);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ internal class PolygonTests
|
||||
public void AddVertices_ShouldAddVertices()
|
||||
{
|
||||
var polygon = Polygon.Empty;
|
||||
polygon.AddVertices(new[] {new Point(1, 2), new Point(3, 4)});
|
||||
polygon.AddVertices([new Point(1, 2), new Point(3, 4)]);
|
||||
Assert.That(polygon.VertexCount, Is.EqualTo(2));
|
||||
|
||||
// assert that the empty polygon was not modified
|
||||
@ -30,7 +30,7 @@ internal class PolygonTests
|
||||
public void ClearVertices_ShouldClearVertices()
|
||||
{
|
||||
var polygon = Polygon.Empty;
|
||||
polygon.AddVertices(new[] {new Point(1, 2), new Point(3, 4)});
|
||||
polygon.AddVertices([new Point(1, 2), new Point(3, 4)]);
|
||||
Assert.That(polygon.VertexCount, Is.EqualTo(2));
|
||||
|
||||
// assert that the empty polygon was not modified
|
||||
@ -43,7 +43,7 @@ internal class PolygonTests
|
||||
[Test]
|
||||
public void Constructor_ShouldPopulateVertices_GivenPolygon()
|
||||
{
|
||||
var pointPolygon = new Polygon(new[] {new Point(1, 2), new Point(3, 4)});
|
||||
var pointPolygon = new Polygon([new Point(1, 2), new Point(3, 4)]);
|
||||
|
||||
Assert.That(pointPolygon.VertexCount, Is.EqualTo(2));
|
||||
}
|
||||
@ -59,7 +59,7 @@ internal class PolygonTests
|
||||
public void CopyConstructor_ShouldCopyVertices_GivenPolygon()
|
||||
{
|
||||
var first = Polygon.Empty;
|
||||
first.AddVertices(new[] {new Point(1, 2), new Point(3, 4)});
|
||||
first.AddVertices([new Point(1, 2), new Point(3, 4)]);
|
||||
|
||||
var second = new Polygon(first);
|
||||
Assert.That(first.VertexCount, Is.EqualTo(2));
|
||||
|
@ -11,7 +11,7 @@ internal class PolyhedronTests
|
||||
public void AddVertices_ShouldAddVertices()
|
||||
{
|
||||
var polyhedron = Polyhedron.Empty;
|
||||
polyhedron.AddVertices(new[] {new Vector3(1, 2, 3), new Vector3(4, 5, 6)});
|
||||
polyhedron.AddVertices([new Vector3(1, 2, 3), new Vector3(4, 5, 6)]);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
@ -34,7 +34,7 @@ internal class PolyhedronTests
|
||||
public void ClearVertices_ShouldClearVertices()
|
||||
{
|
||||
var polyhedron = Polyhedron.Empty;
|
||||
polyhedron.AddVertices(new[] {new Vector3(1, 2, 3), new Vector3(4, 5, 6)});
|
||||
polyhedron.AddVertices([new Vector3(1, 2, 3), new Vector3(4, 5, 6)]);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(polyhedron.VertexCount, Is.EqualTo(2));
|
||||
@ -50,7 +50,7 @@ internal class PolyhedronTests
|
||||
[Test]
|
||||
public void Constructor_ShouldPopulateVertices_GivenPolyhedron()
|
||||
{
|
||||
var polyhedron = new Polyhedron(new[] {new Vector3(1, 2, 3), new Vector3(4, 5, 6)});
|
||||
var polyhedron = new Polyhedron([new Vector3(1, 2, 3), new Vector3(4, 5, 6)]);
|
||||
Assert.That(polyhedron.VertexCount, Is.EqualTo(2));
|
||||
}
|
||||
|
||||
@ -65,7 +65,7 @@ internal class PolyhedronTests
|
||||
public void CopyConstructor_ShouldCopyVertices_GivenPolyhedron()
|
||||
{
|
||||
var first = Polyhedron.Empty;
|
||||
first.AddVertices(new[] {new Vector3(1, 2, 3), new Vector3(4, 5, 6)});
|
||||
first.AddVertices([new Vector3(1, 2, 3), new Vector3(4, 5, 6)]);
|
||||
|
||||
var second = new Polyhedron(first);
|
||||
Assert.Multiple(() =>
|
||||
@ -75,7 +75,7 @@ internal class PolyhedronTests
|
||||
|
||||
// we cannot use CollectionAssert here for reasons I am not entirely sure of.
|
||||
// it seems to dislike casting from IReadOnlyList<Point> to ICollection. but okay.
|
||||
CollectionAssert.AreEqual(first.Vertices, second.Vertices);
|
||||
Assert.That(second.Vertices, Is.EqualTo(first.Vertices).AsCollection);
|
||||
|
||||
// assert that the empty polyhedron was not modified
|
||||
Assert.That(Polyhedron.Empty.VertexCount, Is.Zero);
|
||||
@ -148,11 +148,11 @@ internal class PolyhedronTests
|
||||
Assert.That(converted, Is.EqualTo((Polyhedron)polygon));
|
||||
Assert.That(converted.VertexCount, Is.EqualTo(polygon.VertexCount));
|
||||
|
||||
CollectionAssert.AreEqual(converted.Vertices, polygon.Vertices.Select(p =>
|
||||
Assert.That(polygon.Vertices.Select(p =>
|
||||
{
|
||||
var point = p.ToVector2();
|
||||
return new Vector3(point.X, point.Y, 0);
|
||||
}));
|
||||
}), Is.EqualTo(converted.Vertices).AsCollection);
|
||||
});
|
||||
}
|
||||
|
||||
@ -166,11 +166,11 @@ internal class PolyhedronTests
|
||||
{
|
||||
Assert.That(converted, Is.EqualTo((Polyhedron)polygon));
|
||||
Assert.That(converted.VertexCount, Is.EqualTo(polygon.VertexCount));
|
||||
CollectionAssert.AreEqual(converted.Vertices, polygon.Vertices.Select(p =>
|
||||
Assert.That(converted.Vertices, Is.EqualTo(polygon.Vertices.Select(p =>
|
||||
{
|
||||
var point = p.ToVector2();
|
||||
return new Vector3(point.X, point.Y, 0);
|
||||
}));
|
||||
})).AsCollection);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -23,8 +23,8 @@ internal class ServiceCollectionTests
|
||||
{
|
||||
Assert.That(service, Is.Not.Null);
|
||||
Assert.That(hostedService, Is.Not.Null);
|
||||
Assert.IsAssignableFrom<TestService>(service);
|
||||
Assert.IsAssignableFrom<TestService>(hostedService);
|
||||
Assert.That(service, Is.AssignableFrom<TestService>());
|
||||
Assert.That(hostedService, Is.AssignableFrom<TestService>());
|
||||
Assert.That(hostedService, Is.SameAs(service));
|
||||
});
|
||||
}
|
||||
@ -44,8 +44,8 @@ internal class ServiceCollectionTests
|
||||
{
|
||||
Assert.That(service, Is.Not.Null);
|
||||
Assert.That(hostedService, Is.Not.Null);
|
||||
Assert.IsAssignableFrom<TestService>(service);
|
||||
Assert.IsAssignableFrom<TestService>(hostedService);
|
||||
Assert.That(service, Is.AssignableFrom<TestService>());
|
||||
Assert.That(hostedService, Is.AssignableFrom<TestService>());
|
||||
Assert.That(hostedService, Is.SameAs(service));
|
||||
});
|
||||
}
|
||||
@ -65,8 +65,8 @@ internal class ServiceCollectionTests
|
||||
{
|
||||
Assert.That(service, Is.Not.Null);
|
||||
Assert.That(hostedService, Is.Not.Null);
|
||||
Assert.IsAssignableFrom<TestService>(service);
|
||||
Assert.IsAssignableFrom<TestService>(hostedService);
|
||||
Assert.That(service, Is.AssignableFrom<TestService>());
|
||||
Assert.That(hostedService, Is.AssignableFrom<TestService>());
|
||||
Assert.That(hostedService, Is.SameAs(service));
|
||||
});
|
||||
}
|
||||
@ -86,8 +86,8 @@ internal class ServiceCollectionTests
|
||||
{
|
||||
Assert.That(service, Is.Not.Null);
|
||||
Assert.That(hostedService, Is.Not.Null);
|
||||
Assert.IsAssignableFrom<TestService>(service);
|
||||
Assert.IsAssignableFrom<TestService>(hostedService);
|
||||
Assert.That(service, Is.AssignableFrom<TestService>());
|
||||
Assert.That(hostedService, Is.AssignableFrom<TestService>());
|
||||
Assert.That(hostedService, Is.SameAs(service));
|
||||
});
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ internal class BooleanTests
|
||||
public void GetBytes_ReturnsArrayContaining1()
|
||||
{
|
||||
const bool value = true;
|
||||
CollectionAssert.AreEqual(new byte[] {1}, value.GetBytes());
|
||||
Assert.That(value.GetBytes(), Is.EqualTo(new byte[] { 1 }).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -19,14 +19,14 @@ internal class BooleanTests
|
||||
const bool value = true;
|
||||
Span<byte> buffer = stackalloc byte[1];
|
||||
Assert.That(value.TryWriteBytes(buffer));
|
||||
CollectionAssert.AreEqual(new byte[] {1}, buffer.ToArray());
|
||||
Assert.That(buffer.ToArray(), Is.EqualTo(new byte[] { 1 }).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TryWriteBytes_ReturnsFalse_GivenSmallSpan()
|
||||
{
|
||||
const bool value = true;
|
||||
Span<byte> buffer = stackalloc byte[0];
|
||||
Span<byte> buffer = [];
|
||||
Assert.That(value.TryWriteBytes(buffer), Is.False);
|
||||
}
|
||||
}
|
||||
|
@ -10,23 +10,26 @@ internal class ByteTests
|
||||
public void GetBytes_ReturnsArrayContainingItself()
|
||||
{
|
||||
const byte value = 0xFF;
|
||||
CollectionAssert.AreEqual(new[] {value}, value.GetBytes());
|
||||
Assert.That(value.GetBytes(), Is.EqualTo(new[] { value }).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TryWriteBytes_ReturnsTrue_FillsSpanContainingItself_GivenLargeEnoughSpan()
|
||||
{
|
||||
const byte value = 0xFF;
|
||||
Span<byte> buffer = stackalloc byte[1];
|
||||
Assert.That(value.TryWriteBytes(buffer));
|
||||
CollectionAssert.AreEqual(new[] {value}, buffer.ToArray());
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[1];
|
||||
Assert.That(value.TryWriteBytes(buffer));
|
||||
Assert.That(buffer.ToArray(), Is.EqualTo(new[] { value }).AsCollection);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TryWriteBytes_ReturnsFalse_GivenSmallSpan()
|
||||
{
|
||||
const byte value = 0x0F;
|
||||
Span<byte> buffer = stackalloc byte[0];
|
||||
Span<byte> buffer = [];
|
||||
Assert.That(value.TryWriteBytes(buffer), Is.False);
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ internal class DecimalTests
|
||||
|
||||
byte[] bytes = value.GetBigEndianBytes();
|
||||
|
||||
CollectionAssert.AreEqual(expected, bytes);
|
||||
Assert.That(bytes, Is.EqualTo(expected).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -25,7 +25,7 @@ internal class DecimalTests
|
||||
|
||||
byte[] bytes = value.GetLittleEndianBytes();
|
||||
|
||||
CollectionAssert.AreEqual(expected, bytes);
|
||||
Assert.That(bytes, Is.EqualTo(expected).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -34,10 +34,12 @@ internal class DecimalTests
|
||||
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());
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<byte> bytes = stackalloc byte[16];
|
||||
Assert.That(value.TryWriteBigEndianBytes(bytes));
|
||||
Assert.That(bytes.ToArray(), Is.EqualTo(expected).AsCollection);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -46,10 +48,12 @@ internal class DecimalTests
|
||||
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());
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<byte> bytes = stackalloc byte[16];
|
||||
Assert.That(value.TryWriteLittleEndianBytes(bytes));
|
||||
Assert.That(bytes.ToArray(), Is.EqualTo(expected).AsCollection);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -13,7 +13,7 @@ internal class DoubleTests
|
||||
|
||||
var expected = new byte[] { 0x40, 0x45, 0x40, 0, 0, 0, 0, 0 };
|
||||
byte[] actual = value.GetBigEndianBytes();
|
||||
CollectionAssert.AreEqual(expected, actual);
|
||||
Assert.That(actual, Is.EqualTo(expected).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -23,7 +23,7 @@ internal class DoubleTests
|
||||
|
||||
var expected = new byte[] { 0, 0, 0, 0, 0, 0x40, 0x45, 0x40 };
|
||||
byte[] actual = value.GetLittleEndianBytes();
|
||||
CollectionAssert.AreEqual(expected, actual);
|
||||
Assert.That(actual, Is.EqualTo(expected).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -32,9 +32,12 @@ internal class DoubleTests
|
||||
const double value = 42.5;
|
||||
|
||||
var expected = new byte[] { 0x40, 0x45, 0x40, 0, 0, 0, 0, 0 };
|
||||
Span<byte> actual = stackalloc byte[8];
|
||||
Assert.That(value.TryWriteBigEndianBytes(actual));
|
||||
CollectionAssert.AreEqual(expected, actual.ToArray());
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<byte> actual = stackalloc byte[8];
|
||||
Assert.That(value.TryWriteBigEndianBytes(actual));
|
||||
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -43,16 +46,19 @@ internal class DoubleTests
|
||||
const double value = 42.5;
|
||||
|
||||
var expected = new byte[] { 0, 0, 0, 0, 0, 0x40, 0x45, 0x40 };
|
||||
Span<byte> actual = stackalloc byte[8];
|
||||
Assert.That(value.TryWriteLittleEndianBytes(actual));
|
||||
CollectionAssert.AreEqual(expected, actual.ToArray());
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<byte> actual = stackalloc byte[8];
|
||||
Assert.That(value.TryWriteLittleEndianBytes(actual));
|
||||
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TryWriteBigEndian_ReturnsFalse_GivenSmallSpan()
|
||||
{
|
||||
const double value = 42.5;
|
||||
Span<byte> buffer = stackalloc byte[0];
|
||||
Span<byte> buffer = [];
|
||||
Assert.That(value.TryWriteBigEndianBytes(buffer), Is.False);
|
||||
}
|
||||
|
||||
@ -60,7 +66,7 @@ internal class DoubleTests
|
||||
public void TryWriteLittleEndian_RReturnsFalse_GivenSmallSpan()
|
||||
{
|
||||
const double value = 42.5;
|
||||
Span<byte> buffer = stackalloc byte[0];
|
||||
Span<byte> buffer = [];
|
||||
Assert.That(value.TryWriteLittleEndianBytes(buffer), Is.False);
|
||||
}
|
||||
}
|
||||
|
@ -21,15 +21,15 @@ internal class FileInfoTests
|
||||
|
||||
// SHA-1
|
||||
byte[] expectedHash =
|
||||
{
|
||||
[
|
||||
0x0A, 0x4D, 0x55, 0xA8, 0xD7, 0x78, 0xE5, 0x02, 0x2F, 0xAB, 0x70, 0x19, 0x77, 0xC5, 0xD8, 0x40, 0xBB, 0xC4, 0x86,
|
||||
0xD0
|
||||
};
|
||||
];
|
||||
|
||||
try
|
||||
{
|
||||
byte[] hash = new FileInfo(fileName).GetHash<SHA1>();
|
||||
CollectionAssert.AreEqual(expectedHash, hash);
|
||||
Assert.That(hash, Is.EqualTo(expectedHash).AsCollection);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@ -51,17 +51,21 @@ internal class FileInfoTests
|
||||
|
||||
// SHA-1
|
||||
byte[] expectedHash =
|
||||
{
|
||||
[
|
||||
0x0A, 0x4D, 0x55, 0xA8, 0xD7, 0x78, 0xE5, 0x02, 0x2F, 0xAB, 0x70, 0x19, 0x77, 0xC5, 0xD8, 0x40, 0xBB, 0xC4, 0x86,
|
||||
0xD0
|
||||
};
|
||||
];
|
||||
|
||||
try
|
||||
{
|
||||
Span<byte> hash = stackalloc byte[20];
|
||||
new FileInfo(fileName).TryWriteHash<SHA1>(hash, out int bytesWritten);
|
||||
Assert.That(bytesWritten, Is.EqualTo(expectedHash.Length));
|
||||
CollectionAssert.AreEqual(expectedHash, hash.ToArray());
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<byte> hash = stackalloc byte[20];
|
||||
new FileInfo(fileName).TryWriteHash<SHA1>(hash, out int bytesWritten);
|
||||
|
||||
Assert.That(bytesWritten, Is.EqualTo(expectedHash.Length));
|
||||
Assert.That(hash.ToArray(), Is.EqualTo(expectedHash).AsCollection);
|
||||
});
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -11,9 +11,9 @@ internal class Int16Tests
|
||||
{
|
||||
const short value = 0x0F;
|
||||
|
||||
byte[] expected = { 0x0F, 0 };
|
||||
byte[] expected = [0x0F, 0];
|
||||
byte[] actual = value.GetLittleEndianBytes();
|
||||
CollectionAssert.AreEqual(expected, actual);
|
||||
Assert.That(actual, Is.EqualTo(expected).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -21,9 +21,9 @@ internal class Int16Tests
|
||||
{
|
||||
const short value = 0x0F;
|
||||
|
||||
byte[] expected = { 0, 0x0F };
|
||||
byte[] expected = [0, 0x0F];
|
||||
byte[] actual = value.GetBigEndianBytes();
|
||||
CollectionAssert.AreEqual(expected, actual);
|
||||
Assert.That(actual, Is.EqualTo(expected).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -31,10 +31,13 @@ internal class Int16Tests
|
||||
{
|
||||
const short value = 0x0F;
|
||||
|
||||
byte[] expected = { 0x0F, 0 };
|
||||
Span<byte> actual = stackalloc byte[2];
|
||||
Assert.That(value.TryWriteLittleEndianBytes(actual));
|
||||
CollectionAssert.AreEqual(expected, actual.ToArray());
|
||||
byte[] expected = [0x0F, 0];
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<byte> actual = stackalloc byte[2];
|
||||
Assert.That(value.TryWriteLittleEndianBytes(actual));
|
||||
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -42,17 +45,20 @@ internal class Int16Tests
|
||||
{
|
||||
const short value = 0x0F;
|
||||
|
||||
byte[] expected = { 0, 0x0F };
|
||||
Span<byte> actual = stackalloc byte[2];
|
||||
Assert.That(value.TryWriteBigEndianBytes(actual));
|
||||
CollectionAssert.AreEqual(expected, actual.ToArray());
|
||||
byte[] expected = [0, 0x0F];
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<byte> actual = stackalloc byte[2];
|
||||
Assert.That(value.TryWriteBigEndianBytes(actual));
|
||||
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TryWriteLittleEndian_RReturnsFalse_GivenSmallSpan()
|
||||
{
|
||||
const short value = 0x0F;
|
||||
Span<byte> buffer = stackalloc byte[0];
|
||||
Span<byte> buffer = [];
|
||||
Assert.That(value.TryWriteLittleEndianBytes(buffer), Is.False);
|
||||
}
|
||||
|
||||
@ -60,7 +66,7 @@ internal class Int16Tests
|
||||
public void TryWriteBigEndian_ReturnsFalse_GivenSmallSpan()
|
||||
{
|
||||
const short value = 0x0F;
|
||||
Span<byte> buffer = stackalloc byte[0];
|
||||
Span<byte> buffer = [];
|
||||
Assert.That(value.TryWriteBigEndianBytes(buffer), Is.False);
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ internal class Int32Tests
|
||||
|
||||
var expected = new byte[] { 0, 0, 0, 0x0F };
|
||||
byte[] actual = value.GetBigEndianBytes();
|
||||
CollectionAssert.AreEqual(expected, actual);
|
||||
Assert.That(actual, Is.EqualTo(expected).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -23,7 +23,7 @@ internal class Int32Tests
|
||||
|
||||
var expected = new byte[] { 0x0F, 0, 0, 0 };
|
||||
byte[] actual = value.GetLittleEndianBytes();
|
||||
CollectionAssert.AreEqual(expected, actual);
|
||||
Assert.That(actual, Is.EqualTo(expected).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -32,9 +32,12 @@ internal class Int32Tests
|
||||
const int value = 0x0F;
|
||||
|
||||
var expected = new byte[] { 0, 0, 0, 0x0F };
|
||||
Span<byte> actual = stackalloc byte[4];
|
||||
Assert.That(value.TryWriteBigEndianBytes(actual));
|
||||
CollectionAssert.AreEqual(expected, actual.ToArray());
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<byte> actual = stackalloc byte[4];
|
||||
Assert.That(value.TryWriteBigEndianBytes(actual));
|
||||
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -43,16 +46,19 @@ internal class Int32Tests
|
||||
const int value = 0x0F;
|
||||
|
||||
var expected = new byte[] { 0x0F, 0, 0, 0 };
|
||||
Span<byte> actual = stackalloc byte[4];
|
||||
Assert.That(value.TryWriteLittleEndianBytes(actual));
|
||||
CollectionAssert.AreEqual(expected, actual.ToArray());
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<byte> actual = stackalloc byte[4];
|
||||
Assert.That(value.TryWriteLittleEndianBytes(actual));
|
||||
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TryWriteBigEndian_ReturnsFalse_GivenSmallSpan()
|
||||
{
|
||||
const int value = 0x0F;
|
||||
Span<byte> buffer = stackalloc byte[0];
|
||||
Span<byte> buffer = [];
|
||||
Assert.That(value.TryWriteBigEndianBytes(buffer), Is.False);
|
||||
}
|
||||
|
||||
@ -60,7 +66,7 @@ internal class Int32Tests
|
||||
public void TryWriteLittleEndian_RReturnsFalse_GivenSmallSpan()
|
||||
{
|
||||
const int value = 0x0F;
|
||||
Span<byte> buffer = stackalloc byte[0];
|
||||
Span<byte> buffer = [];
|
||||
Assert.That(value.TryWriteLittleEndianBytes(buffer), Is.False);
|
||||
}
|
||||
}
|
||||
|
@ -11,9 +11,9 @@ internal class Int64Tests
|
||||
{
|
||||
const long value = 0x0F;
|
||||
|
||||
byte[] expected = { 0x0F, 0, 0, 0, 0, 0, 0, 0 };
|
||||
byte[] expected = [0x0F, 0, 0, 0, 0, 0, 0, 0];
|
||||
byte[] actual = value.GetLittleEndianBytes();
|
||||
CollectionAssert.AreEqual(expected, actual);
|
||||
Assert.That(actual, Is.EqualTo(expected).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -21,9 +21,9 @@ internal class Int64Tests
|
||||
{
|
||||
const long value = 0x0F;
|
||||
|
||||
byte[] expected = { 0, 0, 0, 0, 0, 0, 0, 0x0F };
|
||||
byte[] expected = [0, 0, 0, 0, 0, 0, 0, 0x0F];
|
||||
byte[] actual = value.GetBigEndianBytes();
|
||||
CollectionAssert.AreEqual(expected, actual);
|
||||
Assert.That(actual, Is.EqualTo(expected).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -31,10 +31,13 @@ internal class Int64Tests
|
||||
{
|
||||
const long value = 0x0F;
|
||||
|
||||
byte[] expected = { 0x0F, 0, 0, 0, 0, 0, 0, 0 };
|
||||
Span<byte> actual = stackalloc byte[8];
|
||||
Assert.That(value.TryWriteLittleEndianBytes(actual));
|
||||
CollectionAssert.AreEqual(expected, actual.ToArray());
|
||||
byte[] expected = [0x0F, 0, 0, 0, 0, 0, 0, 0];
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<byte> actual = stackalloc byte[8];
|
||||
Assert.That(value.TryWriteLittleEndianBytes(actual));
|
||||
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -42,17 +45,20 @@ internal class Int64Tests
|
||||
{
|
||||
const long value = 0x0F;
|
||||
|
||||
byte[] expected = { 0, 0, 0, 0, 0, 0, 0, 0x0F };
|
||||
Span<byte> actual = stackalloc byte[8];
|
||||
Assert.That(value.TryWriteBigEndianBytes(actual));
|
||||
CollectionAssert.AreEqual(expected, actual.ToArray());
|
||||
byte[] expected = [0, 0, 0, 0, 0, 0, 0, 0x0F];
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<byte> actual = stackalloc byte[8];
|
||||
Assert.That(value.TryWriteBigEndianBytes(actual));
|
||||
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TryWriteLittleEndian_RReturnsFalse_GivenSmallSpan()
|
||||
{
|
||||
const long value = 0x0F;
|
||||
Span<byte> buffer = stackalloc byte[0];
|
||||
Span<byte> buffer = [];
|
||||
Assert.That(value.TryWriteLittleEndianBytes(buffer), Is.False);
|
||||
}
|
||||
|
||||
@ -60,7 +66,7 @@ internal class Int64Tests
|
||||
public void TryWriteBigEndian_ReturnsFalse_GivenSmallSpan()
|
||||
{
|
||||
const long value = 0x0F;
|
||||
Span<byte> buffer = stackalloc byte[0];
|
||||
Span<byte> buffer = [];
|
||||
Assert.That(value.TryWriteBigEndianBytes(buffer), Is.False);
|
||||
}
|
||||
}
|
||||
|
@ -10,23 +10,26 @@ internal class SByteTests
|
||||
public void GetBytes_ReturnsArrayContainingItself()
|
||||
{
|
||||
const sbyte value = 0x0F;
|
||||
CollectionAssert.AreEqual(new[] {(byte)value}, value.GetBytes());
|
||||
Assert.That(value.GetBytes(), Is.EqualTo(new[] { (byte)value }).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TryWriteBytes_ReturnsTrue_FillsSpanContainingItself_GivenLargeEnoughSpan()
|
||||
{
|
||||
const sbyte value = 0x0F;
|
||||
Span<byte> buffer = stackalloc byte[1];
|
||||
Assert.That(value.TryWriteBytes(buffer));
|
||||
CollectionAssert.AreEqual(new[] {(byte)value}, buffer.ToArray());
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[1];
|
||||
Assert.That(value.TryWriteBytes(buffer));
|
||||
Assert.That(buffer.ToArray(), Is.EqualTo(new[] { (byte)value }).AsCollection);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TryWriteBytes_ReturnsFalse_GivenSmallSpan()
|
||||
{
|
||||
const sbyte value = 0x0F;
|
||||
Span<byte> buffer = stackalloc byte[0];
|
||||
Span<byte> buffer = [];
|
||||
Assert.That(value.TryWriteBytes(buffer), Is.False);
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ internal class SingleTests
|
||||
|
||||
var expected = new byte[] { 0x42, 0x2A, 0, 0 };
|
||||
byte[] actual = value.GetBigEndianBytes();
|
||||
CollectionAssert.AreEqual(expected, actual);
|
||||
Assert.That(actual, Is.EqualTo(expected).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -23,7 +23,7 @@ internal class SingleTests
|
||||
|
||||
var expected = new byte[] { 0, 0, 0x2A, 0x42 };
|
||||
byte[] actual = value.GetLittleEndianBytes();
|
||||
CollectionAssert.AreEqual(expected, actual);
|
||||
Assert.That(actual, Is.EqualTo(expected).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -32,9 +32,12 @@ internal class SingleTests
|
||||
const float value = 42.5f;
|
||||
|
||||
var expected = new byte[] { 0x42, 0x2A, 0, 0 };
|
||||
Span<byte> actual = stackalloc byte[4];
|
||||
Assert.That(value.TryWriteBigEndianBytes(actual));
|
||||
CollectionAssert.AreEqual(expected, actual.ToArray());
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<byte> actual = stackalloc byte[4];
|
||||
Assert.That(value.TryWriteBigEndianBytes(actual));
|
||||
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -43,16 +46,19 @@ internal class SingleTests
|
||||
const float value = 42.5f;
|
||||
|
||||
var expected = new byte[] { 0, 0, 0x2A, 0x42 };
|
||||
Span<byte> actual = stackalloc byte[4];
|
||||
Assert.That(value.TryWriteLittleEndianBytes(actual));
|
||||
CollectionAssert.AreEqual(expected, actual.ToArray());
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<byte> actual = stackalloc byte[4];
|
||||
Assert.That(value.TryWriteLittleEndianBytes(actual));
|
||||
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TryWriteBigEndian_ReturnsFalse_GivenSmallSpan()
|
||||
{
|
||||
const float value = 42.5f;
|
||||
Span<byte> buffer = stackalloc byte[0];
|
||||
Span<byte> buffer = [];
|
||||
Assert.That(value.TryWriteBigEndianBytes(buffer), Is.False);
|
||||
}
|
||||
|
||||
@ -60,7 +66,7 @@ internal class SingleTests
|
||||
public void TryWriteLittleEndian_RReturnsFalse_GivenSmallSpan()
|
||||
{
|
||||
const float value = 42.5f;
|
||||
Span<byte> buffer = stackalloc byte[0];
|
||||
Span<byte> buffer = [];
|
||||
Assert.That(value.TryWriteLittleEndianBytes(buffer), Is.False);
|
||||
}
|
||||
}
|
||||
|
@ -40,10 +40,10 @@ internal partial class StreamTests
|
||||
public void ReadDecimalBigEndian_ShouldReadBigEndian()
|
||||
{
|
||||
using var stream = new MemoryStream();
|
||||
ReadOnlySpan<byte> bytes = stackalloc byte[]
|
||||
{
|
||||
ReadOnlySpan<byte> bytes =
|
||||
[
|
||||
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x68
|
||||
};
|
||||
];
|
||||
stream.Write(bytes);
|
||||
stream.Position = 0;
|
||||
|
||||
@ -61,10 +61,10 @@ internal partial class StreamTests
|
||||
public void ReadDecimalLittleEndian_ShouldWriteLittleEndian()
|
||||
{
|
||||
using var stream = new MemoryStream();
|
||||
ReadOnlySpan<byte> bytes = stackalloc byte[]
|
||||
{
|
||||
ReadOnlySpan<byte> bytes =
|
||||
[
|
||||
0x68, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00
|
||||
};
|
||||
];
|
||||
stream.Write(bytes);
|
||||
stream.Position = 0;
|
||||
|
||||
|
@ -40,7 +40,7 @@ internal partial class StreamTests
|
||||
public void ReadDoubleBigEndian_ShouldReadBigEndian()
|
||||
{
|
||||
using var stream = new MemoryStream();
|
||||
ReadOnlySpan<byte> bytes = stackalloc byte[] { 0x40, 0x7A, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
ReadOnlySpan<byte> bytes = [0x40, 0x7A, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00];
|
||||
stream.Write(bytes);
|
||||
stream.Position = 0;
|
||||
|
||||
@ -55,7 +55,7 @@ internal partial class StreamTests
|
||||
public void ReadDoubleLittleEndian_ShouldWriteLittleEndian()
|
||||
{
|
||||
using var stream = new MemoryStream();
|
||||
ReadOnlySpan<byte> bytes = stackalloc byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x7A, 0x40 };
|
||||
ReadOnlySpan<byte> bytes = [0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x7A, 0x40];
|
||||
stream.Write(bytes);
|
||||
stream.Position = 0;
|
||||
|
||||
|
@ -40,7 +40,7 @@ internal partial class StreamTests
|
||||
public void ReadInt16BigEndian_ShouldReadBigEndian()
|
||||
{
|
||||
using var stream = new MemoryStream();
|
||||
ReadOnlySpan<byte> bytes = stackalloc byte[] { 0x01, 0xA4 };
|
||||
ReadOnlySpan<byte> bytes = [0x01, 0xA4];
|
||||
stream.Write(bytes);
|
||||
stream.Position = 0;
|
||||
|
||||
@ -55,7 +55,7 @@ internal partial class StreamTests
|
||||
public void ReadInt16LittleEndian_ShouldReadLittleEndian()
|
||||
{
|
||||
using var stream = new MemoryStream();
|
||||
ReadOnlySpan<byte> bytes = stackalloc byte[] { 0xA4, 0x01 };
|
||||
ReadOnlySpan<byte> bytes = [0xA4, 0x01];
|
||||
stream.Write(bytes);
|
||||
stream.Position = 0;
|
||||
|
||||
|
@ -40,7 +40,7 @@ internal partial class StreamTests
|
||||
public void ReadInt32BigEndian_ShouldReadBigEndian()
|
||||
{
|
||||
using var stream = new MemoryStream();
|
||||
ReadOnlySpan<byte> bytes = stackalloc byte[] { 0x00, 0x00, 0x01, 0xA4 };
|
||||
ReadOnlySpan<byte> bytes = [0x00, 0x00, 0x01, 0xA4];
|
||||
stream.Write(bytes);
|
||||
stream.Position = 0;
|
||||
|
||||
@ -55,7 +55,7 @@ internal partial class StreamTests
|
||||
public void ReadInt32LittleEndian_ShouldReadLittleEndian()
|
||||
{
|
||||
using var stream = new MemoryStream();
|
||||
ReadOnlySpan<byte> bytes = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00 };
|
||||
ReadOnlySpan<byte> bytes = [0xA4, 0x01, 0x00, 0x00];
|
||||
stream.Write(bytes);
|
||||
stream.Position = 0;
|
||||
|
||||
|
@ -37,7 +37,7 @@ internal partial class StreamTests
|
||||
public void ReadInt64BigEndian_ShouldReadBigEndian()
|
||||
{
|
||||
using var stream = new MemoryStream();
|
||||
ReadOnlySpan<byte> bytes = stackalloc byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xA4 };
|
||||
ReadOnlySpan<byte> bytes = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xA4];
|
||||
stream.Write(bytes);
|
||||
stream.Position = 0;
|
||||
|
||||
@ -52,7 +52,7 @@ internal partial class StreamTests
|
||||
public void ReadInt64LittleEndian_ShouldWriteLittleEndian()
|
||||
{
|
||||
using var stream = new MemoryStream();
|
||||
ReadOnlySpan<byte> bytes = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
ReadOnlySpan<byte> bytes = [0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
|
||||
stream.Write(bytes);
|
||||
stream.Position = 0;
|
||||
|
||||
|
@ -40,7 +40,7 @@ internal partial class StreamTests
|
||||
public void ReadSingleBigEndian_ShouldReadBigEndian()
|
||||
{
|
||||
using var stream = new MemoryStream();
|
||||
ReadOnlySpan<byte> bytes = stackalloc byte[] { 0x43, 0xD2, 0x00, 0x00 };
|
||||
ReadOnlySpan<byte> bytes = [0x43, 0xD2, 0x00, 0x00];
|
||||
stream.Write(bytes);
|
||||
stream.Position = 0;
|
||||
|
||||
@ -55,7 +55,7 @@ internal partial class StreamTests
|
||||
public void ReadSingleLittleEndian_ShouldReadLittleEndian()
|
||||
{
|
||||
using var stream = new MemoryStream();
|
||||
ReadOnlySpan<byte> bytes = stackalloc byte[] { 0x00, 0x00, 0xD2, 0x43 };
|
||||
ReadOnlySpan<byte> bytes = [0x00, 0x00, 0xD2, 0x43];
|
||||
stream.Write(bytes);
|
||||
stream.Position = 0;
|
||||
|
||||
|
@ -40,7 +40,7 @@ internal partial class StreamTests
|
||||
public void ReadUInt16BigEndian_ShouldReadBigEndian()
|
||||
{
|
||||
using var stream = new MemoryStream();
|
||||
ReadOnlySpan<byte> bytes = stackalloc byte[] { 0x01, 0xA4 };
|
||||
ReadOnlySpan<byte> bytes = [0x01, 0xA4];
|
||||
stream.Write(bytes);
|
||||
stream.Position = 0;
|
||||
|
||||
@ -55,7 +55,7 @@ internal partial class StreamTests
|
||||
public void ReadUInt16LittleEndian_ShouldReadLittleEndian()
|
||||
{
|
||||
using var stream = new MemoryStream();
|
||||
ReadOnlySpan<byte> bytes = stackalloc byte[] { 0xA4, 0x01 };
|
||||
ReadOnlySpan<byte> bytes = [0xA4, 0x01];
|
||||
stream.Write(bytes);
|
||||
stream.Position = 0;
|
||||
|
||||
|
@ -40,7 +40,7 @@ internal partial class StreamTests
|
||||
public void ReadUInt32BigEndian_ShouldReadBigEndian()
|
||||
{
|
||||
using var stream = new MemoryStream();
|
||||
ReadOnlySpan<byte> bytes = stackalloc byte[] { 0x00, 0x00, 0x01, 0xA4 };
|
||||
ReadOnlySpan<byte> bytes = [0x00, 0x00, 0x01, 0xA4];
|
||||
stream.Write(bytes);
|
||||
stream.Position = 0;
|
||||
|
||||
@ -55,7 +55,7 @@ internal partial class StreamTests
|
||||
public void ReadUInt32LittleEndian_ShouldReadLittleEndian()
|
||||
{
|
||||
using var stream = new MemoryStream();
|
||||
ReadOnlySpan<byte> bytes = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00 };
|
||||
ReadOnlySpan<byte> bytes = [0xA4, 0x01, 0x00, 0x00];
|
||||
stream.Write(bytes);
|
||||
stream.Position = 0;
|
||||
|
||||
|
@ -40,7 +40,7 @@ internal partial class StreamTests
|
||||
public void ReadUInt64BigEndian_ShouldReadBigEndian()
|
||||
{
|
||||
using var stream = new MemoryStream();
|
||||
ReadOnlySpan<byte> bytes = stackalloc byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xA4 };
|
||||
ReadOnlySpan<byte> bytes = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xA4];
|
||||
stream.Write(bytes);
|
||||
stream.Position = 0;
|
||||
|
||||
@ -55,7 +55,7 @@ internal partial class StreamTests
|
||||
public void ReadUInt64LittleEndian_ShouldWriteLittleEndian()
|
||||
{
|
||||
using var stream = new MemoryStream();
|
||||
ReadOnlySpan<byte> bytes = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
ReadOnlySpan<byte> bytes = [0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
|
||||
stream.Write(bytes);
|
||||
stream.Position = 0;
|
||||
|
||||
|
@ -45,16 +45,19 @@ internal partial class StreamTests
|
||||
Assert.That(stream.Position, Is.EqualTo(16));
|
||||
stream.Position = 0;
|
||||
|
||||
Span<byte> actual = stackalloc byte[16];
|
||||
ReadOnlySpan<byte> expected = stackalloc byte[]
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
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()));
|
||||
Span<byte> actual = stackalloc byte[16];
|
||||
ReadOnlySpan<byte> expected =
|
||||
[
|
||||
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());
|
||||
Assert.That(read, Is.EqualTo(16));
|
||||
Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -65,16 +68,19 @@ internal partial class StreamTests
|
||||
Assert.That(stream.Position, Is.EqualTo(16));
|
||||
stream.Position = 0;
|
||||
|
||||
Span<byte> actual = stackalloc byte[16];
|
||||
ReadOnlySpan<byte> expected = stackalloc byte[]
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
0x68, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00
|
||||
};
|
||||
int read = stream.Read(actual);
|
||||
Span<byte> actual = stackalloc byte[16];
|
||||
ReadOnlySpan<byte> expected =
|
||||
[
|
||||
0x68, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00
|
||||
];
|
||||
int read = stream.Read(actual);
|
||||
|
||||
Trace.WriteLine(string.Join(", ", actual.ToArray().Select(b => $"0x{b:X2}")));
|
||||
Trace.WriteLine(string.Join(", ", actual.ToArray().Select(b => $"0x{b:X2}")));
|
||||
|
||||
Assert.That(read, Is.EqualTo(16));
|
||||
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
|
||||
Assert.That(read, Is.EqualTo(16));
|
||||
Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -44,12 +44,15 @@ internal partial class StreamTests
|
||||
Assert.That(stream.Position, Is.EqualTo(8));
|
||||
stream.Position = 0;
|
||||
|
||||
Span<byte> actual = stackalloc byte[8];
|
||||
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x40, 0x7A, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
int read = stream.Read(actual);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<byte> actual = stackalloc byte[8];
|
||||
ReadOnlySpan<byte> expected = [0x40, 0x7A, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00];
|
||||
int read = stream.Read(actual);
|
||||
|
||||
Assert.That(read, Is.EqualTo(8));
|
||||
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
|
||||
Assert.That(read, Is.EqualTo(8));
|
||||
Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -60,11 +63,14 @@ internal partial class StreamTests
|
||||
Assert.That(stream.Position, Is.EqualTo(8));
|
||||
stream.Position = 0;
|
||||
|
||||
Span<byte> actual = stackalloc byte[8];
|
||||
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x7A, 0x40 };
|
||||
int read = stream.Read(actual);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<byte> actual = stackalloc byte[8];
|
||||
ReadOnlySpan<byte> expected = [0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x7A, 0x40];
|
||||
int read = stream.Read(actual);
|
||||
|
||||
Assert.That(read, Is.EqualTo(8));
|
||||
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
|
||||
Assert.That(read, Is.EqualTo(8));
|
||||
Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -44,12 +44,15 @@ internal partial class StreamTests
|
||||
Assert.That(stream.Position, Is.EqualTo(2));
|
||||
stream.Position = 0;
|
||||
|
||||
Span<byte> actual = stackalloc byte[2];
|
||||
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x01, 0xA4 };
|
||||
int read = stream.Read(actual);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<byte> actual = stackalloc byte[2];
|
||||
ReadOnlySpan<byte> expected = [0x01, 0xA4];
|
||||
int read = stream.Read(actual);
|
||||
|
||||
Assert.That(read, Is.EqualTo(2));
|
||||
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
|
||||
Assert.That(read, Is.EqualTo(2));
|
||||
Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -60,11 +63,14 @@ internal partial class StreamTests
|
||||
Assert.That(stream.Position, Is.EqualTo(2));
|
||||
stream.Position = 0;
|
||||
|
||||
Span<byte> actual = stackalloc byte[2];
|
||||
ReadOnlySpan<byte> expected = stackalloc byte[] { 0xA4, 0x01 };
|
||||
int read = stream.Read(actual);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<byte> actual = stackalloc byte[2];
|
||||
ReadOnlySpan<byte> expected = [0xA4, 0x01];
|
||||
int read = stream.Read(actual);
|
||||
|
||||
Assert.That(read, Is.EqualTo(2));
|
||||
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
|
||||
Assert.That(read, Is.EqualTo(2));
|
||||
Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -44,12 +44,15 @@ internal partial class StreamTests
|
||||
Assert.That(stream.Position, Is.EqualTo(4));
|
||||
stream.Position = 0;
|
||||
|
||||
Span<byte> actual = stackalloc byte[4];
|
||||
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x00, 0x00, 0x01, 0xA4 };
|
||||
int read = stream.Read(actual);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<byte> actual = stackalloc byte[4];
|
||||
ReadOnlySpan<byte> expected = [0x00, 0x00, 0x01, 0xA4];
|
||||
int read = stream.Read(actual);
|
||||
|
||||
Assert.That(read, Is.EqualTo(4));
|
||||
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
|
||||
Assert.That(read, Is.EqualTo(4));
|
||||
Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -60,11 +63,14 @@ internal partial class StreamTests
|
||||
Assert.That(stream.Position, Is.EqualTo(4));
|
||||
stream.Position = 0;
|
||||
|
||||
Span<byte> actual = stackalloc byte[4];
|
||||
ReadOnlySpan<byte> expected = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00 };
|
||||
int read = stream.Read(actual);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<byte> actual = stackalloc byte[4];
|
||||
ReadOnlySpan<byte> expected = [0xA4, 0x01, 0x00, 0x00];
|
||||
int read = stream.Read(actual);
|
||||
|
||||
Assert.That(read, Is.EqualTo(4));
|
||||
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
|
||||
Assert.That(read, Is.EqualTo(4));
|
||||
Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -44,12 +44,15 @@ internal partial class StreamTests
|
||||
Assert.That(stream.Position, Is.EqualTo(8));
|
||||
stream.Position = 0;
|
||||
|
||||
Span<byte> actual = stackalloc byte[8];
|
||||
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xA4 };
|
||||
int read = stream.Read(actual);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<byte> actual = stackalloc byte[8];
|
||||
ReadOnlySpan<byte> expected = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xA4];
|
||||
int read = stream.Read(actual);
|
||||
|
||||
Assert.That(read, Is.EqualTo(8));
|
||||
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
|
||||
Assert.That(read, Is.EqualTo(8));
|
||||
Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -60,11 +63,14 @@ internal partial class StreamTests
|
||||
Assert.That(stream.Position, Is.EqualTo(8));
|
||||
stream.Position = 0;
|
||||
|
||||
Span<byte> actual = stackalloc byte[8];
|
||||
ReadOnlySpan<byte> expected = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
int read = stream.Read(actual);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<byte> actual = stackalloc byte[8];
|
||||
ReadOnlySpan<byte> expected = [0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
|
||||
int read = stream.Read(actual);
|
||||
|
||||
Assert.That(read, Is.EqualTo(8));
|
||||
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
|
||||
Assert.That(read, Is.EqualTo(8));
|
||||
Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -44,12 +44,15 @@ internal partial class StreamTests
|
||||
Assert.That(stream.Position, Is.EqualTo(4));
|
||||
stream.Position = 0;
|
||||
|
||||
Span<byte> actual = stackalloc byte[4];
|
||||
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x43, 0xD2, 0x00, 0x00 };
|
||||
int read = stream.Read(actual);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<byte> actual = stackalloc byte[4];
|
||||
ReadOnlySpan<byte> expected = [0x43, 0xD2, 0x00, 0x00];
|
||||
int read = stream.Read(actual);
|
||||
|
||||
Assert.That(read, Is.EqualTo(4));
|
||||
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
|
||||
Assert.That(read, Is.EqualTo(4));
|
||||
Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -60,11 +63,14 @@ internal partial class StreamTests
|
||||
Assert.That(stream.Position, Is.EqualTo(4));
|
||||
stream.Position = 0;
|
||||
|
||||
Span<byte> actual = stackalloc byte[4];
|
||||
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x00, 0x00, 0xD2, 0x43 };
|
||||
int read = stream.Read(actual);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<byte> actual = stackalloc byte[4];
|
||||
ReadOnlySpan<byte> expected = [0x00, 0x00, 0xD2, 0x43];
|
||||
int read = stream.Read(actual);
|
||||
|
||||
Assert.That(read, Is.EqualTo(4));
|
||||
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
|
||||
Assert.That(read, Is.EqualTo(4));
|
||||
Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -44,12 +44,15 @@ internal partial class StreamTests
|
||||
Assert.That(stream.Position, Is.EqualTo(2));
|
||||
stream.Position = 0;
|
||||
|
||||
Span<byte> actual = stackalloc byte[2];
|
||||
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x01, 0xA4 };
|
||||
int read = stream.Read(actual);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<byte> actual = stackalloc byte[2];
|
||||
ReadOnlySpan<byte> expected = [0x01, 0xA4];
|
||||
int read = stream.Read(actual);
|
||||
|
||||
Assert.That(read, Is.EqualTo(2));
|
||||
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
|
||||
Assert.That(read, Is.EqualTo(2));
|
||||
Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -60,11 +63,14 @@ internal partial class StreamTests
|
||||
Assert.That(stream.Position, Is.EqualTo(2));
|
||||
stream.Position = 0;
|
||||
|
||||
Span<byte> actual = stackalloc byte[2];
|
||||
ReadOnlySpan<byte> expected = stackalloc byte[] { 0xA4, 0x01 };
|
||||
int read = stream.Read(actual);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<byte> actual = stackalloc byte[2];
|
||||
ReadOnlySpan<byte> expected = [0xA4, 0x01];
|
||||
int read = stream.Read(actual);
|
||||
|
||||
Assert.That(read, Is.EqualTo(2));
|
||||
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
|
||||
Assert.That(read, Is.EqualTo(2));
|
||||
Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -44,12 +44,15 @@ internal partial class StreamTests
|
||||
Assert.That(stream.Position, Is.EqualTo(4));
|
||||
stream.Position = 0;
|
||||
|
||||
Span<byte> actual = stackalloc byte[4];
|
||||
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x00, 0x00, 0x01, 0xA4 };
|
||||
int read = stream.Read(actual);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<byte> actual = stackalloc byte[4];
|
||||
ReadOnlySpan<byte> expected = [0x00, 0x00, 0x01, 0xA4];
|
||||
int read = stream.Read(actual);
|
||||
|
||||
Assert.That(read, Is.EqualTo(4));
|
||||
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
|
||||
Assert.That(read, Is.EqualTo(4));
|
||||
Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -60,11 +63,14 @@ internal partial class StreamTests
|
||||
Assert.That(stream.Position, Is.EqualTo(4));
|
||||
stream.Position = 0;
|
||||
|
||||
Span<byte> actual = stackalloc byte[4];
|
||||
ReadOnlySpan<byte> expected = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00 };
|
||||
int read = stream.Read(actual);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<byte> actual = stackalloc byte[4];
|
||||
ReadOnlySpan<byte> expected = [0xA4, 0x01, 0x00, 0x00];
|
||||
int read = stream.Read(actual);
|
||||
|
||||
Assert.That(read, Is.EqualTo(4));
|
||||
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
|
||||
Assert.That(read, Is.EqualTo(4));
|
||||
Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -44,12 +44,15 @@ internal partial class StreamTests
|
||||
Assert.That(stream.Position, Is.EqualTo(8));
|
||||
stream.Position = 0;
|
||||
|
||||
Span<byte> actual = stackalloc byte[8];
|
||||
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xA4 };
|
||||
int read = stream.Read(actual);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<byte> actual = stackalloc byte[8];
|
||||
ReadOnlySpan<byte> expected = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xA4];
|
||||
int read = stream.Read(actual);
|
||||
|
||||
Assert.That(read, Is.EqualTo(8));
|
||||
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
|
||||
Assert.That(read, Is.EqualTo(8));
|
||||
Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -60,11 +63,14 @@ internal partial class StreamTests
|
||||
Assert.That(stream.Position, Is.EqualTo(8));
|
||||
stream.Position = 0;
|
||||
|
||||
Span<byte> actual = stackalloc byte[8];
|
||||
ReadOnlySpan<byte> expected = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
int read = stream.Read(actual);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<byte> actual = stackalloc byte[8];
|
||||
ReadOnlySpan<byte> expected = [0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
|
||||
int read = stream.Read(actual);
|
||||
|
||||
Assert.That(read, Is.EqualTo(8));
|
||||
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
|
||||
Assert.That(read, Is.EqualTo(8));
|
||||
Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -14,10 +14,10 @@ internal partial class StreamTests
|
||||
{
|
||||
// SHA-1
|
||||
byte[] expectedHash =
|
||||
{
|
||||
[
|
||||
0x0A, 0x4D, 0x55, 0xA8, 0xD7, 0x78, 0xE5, 0x02, 0x2F, 0xAB, 0x70, 0x19, 0x77, 0xC5, 0xD8, 0x40, 0xBB, 0xC4, 0x86,
|
||||
0xD0
|
||||
};
|
||||
];
|
||||
|
||||
using var stream = new MemoryStream();
|
||||
stream.Write(Encoding.UTF8.GetBytes("Hello World"));
|
||||
@ -26,7 +26,7 @@ internal partial class StreamTests
|
||||
byte[] hash = stream.GetHash<SHA1>();
|
||||
Trace.WriteLine($"Hash: {BitConverter.ToString(hash)}");
|
||||
Trace.WriteLine($"Expected: {BitConverter.ToString(expectedHash)}");
|
||||
CollectionAssert.AreEqual(expectedHash, hash);
|
||||
Assert.That(hash, Is.EqualTo(expectedHash).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -42,10 +42,10 @@ internal partial class StreamTests
|
||||
{
|
||||
// SHA-1
|
||||
byte[] expectedHash =
|
||||
{
|
||||
[
|
||||
0x0A, 0x4D, 0x55, 0xA8, 0xD7, 0x78, 0xE5, 0x02, 0x2F, 0xAB, 0x70, 0x19, 0x77, 0xC5, 0xD8, 0x40, 0xBB, 0xC4, 0x86,
|
||||
0xD0
|
||||
};
|
||||
];
|
||||
|
||||
using var stream = new MemoryStream();
|
||||
stream.Write(Encoding.UTF8.GetBytes("Hello World"));
|
||||
@ -54,7 +54,7 @@ internal partial class StreamTests
|
||||
Span<byte> hash = stackalloc byte[20];
|
||||
stream.TryWriteHash<SHA1>(hash, out int bytesWritten);
|
||||
Assert.That(bytesWritten, Is.EqualTo(expectedHash.Length));
|
||||
CollectionAssert.AreEqual(expectedHash, hash.ToArray());
|
||||
Assert.That(hash.ToArray(), Is.EqualTo(expectedHash).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -160,7 +160,7 @@ internal partial class StreamTests
|
||||
|
||||
protected override byte[] HashFinal()
|
||||
{
|
||||
return Array.Empty<byte>();
|
||||
return [];
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
@ -176,7 +176,7 @@ internal partial class StreamTests
|
||||
|
||||
protected override byte[] HashFinal()
|
||||
{
|
||||
return Array.Empty<byte>();
|
||||
return [];
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
|
@ -10,51 +10,55 @@ internal class UInt16Tests
|
||||
public void GetLittleEndianBytes_ReturnsCorrectValue_WithEndianness()
|
||||
{
|
||||
const ushort value = 0x0F;
|
||||
byte[] expected = { 0x0F, 0 };
|
||||
byte[] expected = [0x0F, 0];
|
||||
byte[] actual = value.GetLittleEndianBytes();
|
||||
|
||||
CollectionAssert.AreEqual(expected, actual);
|
||||
Assert.That(actual, Is.EqualTo(expected).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetBigEndianBytes_ReturnsCorrectValue_WithEndianness()
|
||||
{
|
||||
const ushort value = 0x0F;
|
||||
byte[] expected = { 0, 0x0F };
|
||||
byte[] expected = [0, 0x0F];
|
||||
byte[] actual = value.GetBigEndianBytes();
|
||||
|
||||
CollectionAssert.AreEqual(expected, actual);
|
||||
Assert.That(actual, Is.EqualTo(expected).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TryWriteLittleEndian_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan()
|
||||
{
|
||||
const ushort value = 0x0F;
|
||||
byte[] expected = { 0x0F, 0 };
|
||||
byte[] expected = [0x0F, 0];
|
||||
|
||||
Span<byte> actual = stackalloc byte[2];
|
||||
Assert.That(value.TryWriteLittleEndianBytes(actual));
|
||||
|
||||
CollectionAssert.AreEqual(expected, actual.ToArray());
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<byte> actual = stackalloc byte[2];
|
||||
Assert.That(value.TryWriteLittleEndianBytes(actual));
|
||||
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TryWriteBigEndian_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan()
|
||||
{
|
||||
const ushort value = 0x0F;
|
||||
byte[] expected = { 0, 0x0F };
|
||||
byte[] expected = [0, 0x0F];
|
||||
|
||||
Span<byte> actual = stackalloc byte[2];
|
||||
Assert.That(value.TryWriteBigEndianBytes(actual));
|
||||
|
||||
CollectionAssert.AreEqual(expected, actual.ToArray());
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<byte> actual = stackalloc byte[2];
|
||||
Assert.That(value.TryWriteBigEndianBytes(actual));
|
||||
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TryWriteLittleEndian_RReturnsFalse_GivenSmallSpan()
|
||||
{
|
||||
const ushort value = 0x0F;
|
||||
Span<byte> buffer = stackalloc byte[0];
|
||||
Span<byte> buffer = [];
|
||||
Assert.That(value.TryWriteLittleEndianBytes(buffer), Is.False);
|
||||
}
|
||||
|
||||
@ -62,7 +66,7 @@ internal class UInt16Tests
|
||||
public void TryWriteBigEndian_ReturnsFalse_GivenSmallSpan()
|
||||
{
|
||||
const ushort value = 0x0F;
|
||||
Span<byte> buffer = stackalloc byte[0];
|
||||
Span<byte> buffer = [];
|
||||
Assert.That(value.TryWriteBigEndianBytes(buffer), Is.False);
|
||||
}
|
||||
}
|
||||
|
@ -10,51 +10,55 @@ internal class UInt32Tests
|
||||
public void GetLittleEndianBytes_ReturnsCorrectValue_WithEndianness()
|
||||
{
|
||||
const uint value = 0x0F;
|
||||
byte[] expected = { 0x0F, 0, 0, 0 };
|
||||
byte[] expected = [0x0F, 0, 0, 0];
|
||||
byte[] actual = value.GetLittleEndianBytes();
|
||||
|
||||
CollectionAssert.AreEqual(expected, actual);
|
||||
Assert.That(actual, Is.EqualTo(expected).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetBigEndianBytes_ReturnsCorrectValue_WithEndianness()
|
||||
{
|
||||
const uint value = 0x0F;
|
||||
byte[] expected = { 0, 0, 0, 0x0F };
|
||||
byte[] expected = [0, 0, 0, 0x0F];
|
||||
byte[] actual = value.GetBigEndianBytes();
|
||||
|
||||
CollectionAssert.AreEqual(expected, actual);
|
||||
Assert.That(actual, Is.EqualTo(expected).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TryWriteLittleEndian_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan()
|
||||
{
|
||||
const uint value = 0x0F;
|
||||
byte[] expected = { 0x0F, 0, 0, 0 };
|
||||
byte[] expected = [0x0F, 0, 0, 0];
|
||||
|
||||
Span<byte> actual = stackalloc byte[4];
|
||||
Assert.That(value.TryWriteLittleEndianBytes(actual));
|
||||
|
||||
CollectionAssert.AreEqual(expected, actual.ToArray());
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<byte> actual = stackalloc byte[4];
|
||||
Assert.That(value.TryWriteLittleEndianBytes(actual));
|
||||
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TryWriteBigEndian_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan()
|
||||
{
|
||||
const uint value = 0x0F;
|
||||
byte[] expected = { 0, 0, 0, 0x0F };
|
||||
byte[] expected = [0, 0, 0, 0x0F];
|
||||
|
||||
Span<byte> actual = stackalloc byte[4];
|
||||
Assert.That(value.TryWriteBigEndianBytes(actual));
|
||||
|
||||
CollectionAssert.AreEqual(expected, actual.ToArray());
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<byte> actual = stackalloc byte[4];
|
||||
Assert.That(value.TryWriteBigEndianBytes(actual));
|
||||
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TryWriteLittleEndian_RReturnsFalse_GivenSmallSpan()
|
||||
{
|
||||
const uint value = 0x0F;
|
||||
Span<byte> buffer = stackalloc byte[0];
|
||||
Span<byte> buffer = [];
|
||||
Assert.That(value.TryWriteLittleEndianBytes(buffer), Is.False);
|
||||
}
|
||||
|
||||
@ -62,7 +66,7 @@ internal class UInt32Tests
|
||||
public void TryWriteBigEndian_ReturnsFalse_GivenSmallSpan()
|
||||
{
|
||||
const uint value = 0x0F;
|
||||
Span<byte> buffer = stackalloc byte[0];
|
||||
Span<byte> buffer = [];
|
||||
Assert.That(value.TryWriteBigEndianBytes(buffer), Is.False);
|
||||
}
|
||||
}
|
||||
|
@ -10,51 +10,55 @@ internal class UInt64Tests
|
||||
public void GetLittleEndianBytes_ReturnsCorrectValue_WithEndianness()
|
||||
{
|
||||
const ulong value = 0x0F;
|
||||
byte[] expected = { 0x0F, 0, 0, 0, 0, 0, 0, 0 };
|
||||
byte[] expected = [0x0F, 0, 0, 0, 0, 0, 0, 0];
|
||||
byte[] actual = value.GetLittleEndianBytes();
|
||||
|
||||
CollectionAssert.AreEqual(expected, actual);
|
||||
Assert.That(actual, Is.EqualTo(expected).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetBigEndianBytes_ReturnsCorrectValue_WithEndianness()
|
||||
{
|
||||
const ulong value = 0x0F;
|
||||
byte[] expected = { 0, 0, 0, 0, 0, 0, 0, 0x0F };
|
||||
byte[] expected = [0, 0, 0, 0, 0, 0, 0, 0x0F];
|
||||
byte[] actual = value.GetBigEndianBytes();
|
||||
|
||||
CollectionAssert.AreEqual(expected, actual);
|
||||
Assert.That(actual, Is.EqualTo(expected).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TryWriteLittleEndian_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan()
|
||||
{
|
||||
const ulong value = 0x0F;
|
||||
byte[] expected = { 0x0F, 0, 0, 0, 0, 0, 0, 0 };
|
||||
byte[] expected = [0x0F, 0, 0, 0, 0, 0, 0, 0];
|
||||
|
||||
Span<byte> actual = stackalloc byte[8];
|
||||
Assert.That(value.TryWriteLittleEndianBytes(actual));
|
||||
|
||||
CollectionAssert.AreEqual(expected, actual.ToArray());
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<byte> actual = stackalloc byte[8];
|
||||
Assert.That(value.TryWriteLittleEndianBytes(actual));
|
||||
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TryWriteBigEndian_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan()
|
||||
{
|
||||
const ulong value = 0x0F;
|
||||
byte[] expected = { 0, 0, 0, 0, 0, 0, 0, 0x0F };
|
||||
byte[] expected = [0, 0, 0, 0, 0, 0, 0, 0x0F];
|
||||
|
||||
Span<byte> actual = stackalloc byte[8];
|
||||
Assert.That(value.TryWriteBigEndianBytes(actual));
|
||||
|
||||
CollectionAssert.AreEqual(expected, actual.ToArray());
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<byte> actual = stackalloc byte[8];
|
||||
Assert.That(value.TryWriteBigEndianBytes(actual));
|
||||
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TryWriteLittleEndian_RReturnsFalse_GivenSmallSpan()
|
||||
{
|
||||
const ulong value = 0x0F;
|
||||
Span<byte> buffer = stackalloc byte[0];
|
||||
Span<byte> buffer = [];
|
||||
Assert.That(value.TryWriteLittleEndianBytes(buffer), Is.False);
|
||||
}
|
||||
|
||||
@ -62,7 +66,7 @@ internal class UInt64Tests
|
||||
public void TryWriteBigEndian_ReturnsFalse_GivenSmallSpan()
|
||||
{
|
||||
const ulong value = 0x0F;
|
||||
Span<byte> buffer = stackalloc byte[0];
|
||||
Span<byte> buffer = [];
|
||||
Assert.That(value.TryWriteBigEndianBytes(buffer), Is.False);
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ internal class ByteTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RangeTo_Byte_ShouldYieldCorrectValues()
|
||||
public void RangeTo_ShouldYieldCorrectValues()
|
||||
{
|
||||
const byte start = 1;
|
||||
const byte end = 10;
|
||||
@ -56,49 +56,4 @@ internal class ByteTests
|
||||
|
||||
Assert.That(current, Is.EqualTo(end));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RangeTo_Int16_ShouldYieldCorrectValues()
|
||||
{
|
||||
const byte start = 1;
|
||||
const short end = 10;
|
||||
|
||||
short current = 1;
|
||||
foreach (short value in start.RangeTo(end))
|
||||
{
|
||||
Assert.That(value, Is.EqualTo(current++));
|
||||
}
|
||||
|
||||
Assert.That(current, Is.EqualTo(end));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RangeTo_Int32_ShouldYieldCorrectValues()
|
||||
{
|
||||
const byte start = 1;
|
||||
const int end = 10;
|
||||
|
||||
int current = 1;
|
||||
foreach (int value in start.RangeTo(end))
|
||||
{
|
||||
Assert.That(value, Is.EqualTo(current++));
|
||||
}
|
||||
|
||||
Assert.That(current, Is.EqualTo(end));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RangeTo_Int64_ShouldYieldCorrectValues()
|
||||
{
|
||||
const byte start = 1;
|
||||
const long end = 10;
|
||||
|
||||
long current = 1;
|
||||
foreach (long value in start.RangeTo(end))
|
||||
{
|
||||
Assert.That(value, Is.EqualTo(current++));
|
||||
}
|
||||
|
||||
Assert.That(current, Is.EqualTo(end));
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ internal class EnumerableTests
|
||||
int[] source = Enumerable.Range(1, 10).ToArray();
|
||||
int[] result = source.Except(5).ToArray();
|
||||
|
||||
Assert.That(result, Is.EquivalentTo(new[] {1, 2, 3, 4, 6, 7, 8, 9, 10}));
|
||||
Assert.That(result, Is.EquivalentTo(new[] { 1, 2, 3, 4, 6, 7, 8, 9, 10 }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -54,7 +54,7 @@ internal class EnumerableTests
|
||||
[Test]
|
||||
public void MinMax_ShouldReturnCorrectSelectedValues_UsingDefaultComparer()
|
||||
{
|
||||
IEnumerable<Person> source = Enumerable.Range(1, 10).Select(i => new Person {Age = i});
|
||||
IEnumerable<Person> source = Enumerable.Range(1, 10).Select(i => new Person { Age = i });
|
||||
(int minimum, int maximum) = source.MinMax(p => p.Age);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
@ -62,7 +62,7 @@ internal class EnumerableTests
|
||||
Assert.That(maximum, Is.EqualTo(10));
|
||||
});
|
||||
|
||||
source = Enumerable.Range(1, 10).Select(i => new Person {Age = i}).ToArray();
|
||||
source = Enumerable.Range(1, 10).Select(i => new Person { Age = i }).ToArray();
|
||||
(minimum, maximum) = source.MinMax(p => p.Age);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
@ -74,7 +74,7 @@ internal class EnumerableTests
|
||||
[Test]
|
||||
public void MinMax_ShouldReturnOppositeSelectedValues_UsingInverseComparer()
|
||||
{
|
||||
IEnumerable<Person> source = Enumerable.Range(1, 10).Select(i => new Person {Age = i});
|
||||
IEnumerable<Person> source = Enumerable.Range(1, 10).Select(i => new Person { Age = i });
|
||||
(int minimum, int maximum) = source.MinMax(p => p.Age, new InverseComparer<int>());
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
@ -82,7 +82,7 @@ internal class EnumerableTests
|
||||
Assert.That(maximum, Is.EqualTo(1));
|
||||
});
|
||||
|
||||
source = Enumerable.Range(1, 10).Select(i => new Person {Age = i}).ToArray();
|
||||
source = Enumerable.Range(1, 10).Select(i => new Person { Age = i }).ToArray();
|
||||
(minimum, maximum) = source.MinMax(p => p.Age, new InverseComparer<int>());
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
@ -112,37 +112,66 @@ internal class EnumerableTests
|
||||
[Test]
|
||||
public void MinMax_ShouldThrowArgumentNullException_GivenNullSelector()
|
||||
{
|
||||
IEnumerable<int> source = Enumerable.Empty<int>();
|
||||
Assert.Throws<ArgumentNullException>(() => source.MinMax((Func<int, int>)(null!)));
|
||||
Assert.Throws<ArgumentNullException>(() => source.MinMax((Func<int, int>)(null!), null));
|
||||
IEnumerable<int> source = [];
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => source.MinMax((Func<int, int>)(null!)));
|
||||
Assert.Throws<ArgumentNullException>(() => source.MinMax((Func<int, int>)(null!), null));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MinMax_ShouldThrowArgumentNullException_GivenNullSource()
|
||||
{
|
||||
IEnumerable<int>? source = null;
|
||||
Assert.Throws<ArgumentNullException>(() => source!.MinMax());
|
||||
Assert.Throws<ArgumentNullException>(() => source!.MinMax(v => v));
|
||||
Assert.Throws<ArgumentNullException>(() => source!.MinMax(null));
|
||||
Assert.Throws<ArgumentNullException>(() => source!.MinMax(v => v, null));
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => source!.MinMax());
|
||||
Assert.Throws<ArgumentNullException>(() => source!.MinMax(v => v));
|
||||
Assert.Throws<ArgumentNullException>(() => source!.MinMax(null));
|
||||
Assert.Throws<ArgumentNullException>(() => source!.MinMax(v => v, null));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MinMax_ShouldThrowInvalidOperationException_GivenEmptySource()
|
||||
{
|
||||
Assert.Throws<InvalidOperationException>(() => Enumerable.Empty<int>().MinMax());
|
||||
Assert.Throws<InvalidOperationException>(() => Array.Empty<int>().MinMax());
|
||||
Assert.Throws<InvalidOperationException>(() => new List<int>().MinMax());
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.Throws<InvalidOperationException>(() =>
|
||||
{
|
||||
Empty().MinMax();
|
||||
return;
|
||||
|
||||
Assert.Throws<InvalidOperationException>(() => Enumerable.Empty<int>().MinMax(i => i * 2));
|
||||
Assert.Throws<InvalidOperationException>(() => Array.Empty<int>().MinMax(i => i * 2));
|
||||
Assert.Throws<InvalidOperationException>(() => new List<int>().MinMax(i => i * 2));
|
||||
static IEnumerable<int> Empty()
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
});
|
||||
Assert.Throws<InvalidOperationException>(() => Array.Empty<int>().MinMax());
|
||||
Assert.Throws<InvalidOperationException>(() => new List<int>().MinMax());
|
||||
|
||||
Assert.Throws<InvalidOperationException>(() =>
|
||||
{
|
||||
Empty().MinMax(i => i * 2);
|
||||
return;
|
||||
|
||||
static IEnumerable<int> Empty()
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
});
|
||||
Assert.Throws<InvalidOperationException>(() => Array.Empty<int>().MinMax(i => i * 2));
|
||||
Assert.Throws<InvalidOperationException>(() => new List<int>().MinMax(i => i * 2));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MinMaxBy_ShouldReturnCorrectSelectedValues_UsingDefaultComparer()
|
||||
{
|
||||
IEnumerable<Person> source = Enumerable.Range(1, 10).Select(i => new Person {Age = i});
|
||||
IEnumerable<Person> source = Enumerable.Range(1, 10).Select(i => new Person { Age = i });
|
||||
(Person minimum, Person maximum) = source.MinMaxBy(p => p.Age);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
@ -150,7 +179,7 @@ internal class EnumerableTests
|
||||
Assert.That(maximum.Age, Is.EqualTo(10));
|
||||
});
|
||||
|
||||
source = Enumerable.Range(1, 10).Select(i => new Person {Age = i}).ToArray();
|
||||
source = Enumerable.Range(1, 10).Select(i => new Person { Age = i }).ToArray();
|
||||
(minimum, maximum) = source.MinMaxBy(p => p.Age);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
@ -162,7 +191,7 @@ internal class EnumerableTests
|
||||
[Test]
|
||||
public void MinMaxBy_ShouldReturnOppositeSelectedValues_UsingInverseComparer()
|
||||
{
|
||||
IEnumerable<Person> source = Enumerable.Range(1, 10).Select(i => new Person {Age = i});
|
||||
IEnumerable<Person> source = Enumerable.Range(1, 10).Select(i => new Person { Age = i });
|
||||
(Person minimum, Person maximum) = source.MinMaxBy(p => p.Age, new InverseComparer<int>());
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
@ -170,7 +199,7 @@ internal class EnumerableTests
|
||||
Assert.That(maximum.Age, Is.EqualTo(1));
|
||||
});
|
||||
|
||||
source = Enumerable.Range(1, 10).Select(i => new Person {Age = i}).ToArray();
|
||||
source = Enumerable.Range(1, 10).Select(i => new Person { Age = i }).ToArray();
|
||||
(minimum, maximum) = source.MinMaxBy(p => p.Age, new InverseComparer<int>());
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
@ -182,7 +211,7 @@ internal class EnumerableTests
|
||||
[Test]
|
||||
public void MinMaxBy_ShouldThrowArgumentNullException_GivenNullSelector()
|
||||
{
|
||||
Person[] source = Enumerable.Range(1, 10).Select(i => new Person {Age = i}).ToArray();
|
||||
Person[] source = Enumerable.Range(1, 10).Select(i => new Person { Age = i }).ToArray();
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => source.MinMaxBy((Func<Person, int>)null!));
|
||||
Assert.Throws<ArgumentNullException>(() => source.MinMaxBy((Func<Person, int>)null!, null));
|
||||
@ -201,13 +230,19 @@ internal class EnumerableTests
|
||||
{
|
||||
Assert.Throws<InvalidOperationException>(() =>
|
||||
{
|
||||
IEnumerable<Person> source = Enumerable.Empty<Person>();
|
||||
IEnumerable<Person> source = Empty();
|
||||
_ = source.MinMaxBy(p => p.Age);
|
||||
return;
|
||||
|
||||
static IEnumerable<Person> Empty()
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
});
|
||||
|
||||
Assert.Throws<InvalidOperationException>(() =>
|
||||
{
|
||||
Person[] source = Array.Empty<Person>();
|
||||
Person[] source = [];
|
||||
_ = source.MinMaxBy(p => p.Age);
|
||||
});
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ internal class Int16Tests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RangeTo_Int16_ShouldYieldCorrectValues()
|
||||
public void RangeTo_ShouldYieldCorrectValues()
|
||||
{
|
||||
const short start = 1;
|
||||
const short end = 10;
|
||||
@ -60,36 +60,4 @@ internal class Int16Tests
|
||||
|
||||
Assert.That(current, Is.EqualTo(end));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RangeTo_Int32_ShouldYieldCorrectValues()
|
||||
{
|
||||
const short start = 1;
|
||||
const int end = 10;
|
||||
|
||||
var current = 1;
|
||||
|
||||
foreach (int value in start.RangeTo(end))
|
||||
{
|
||||
Assert.That(value, Is.EqualTo(current++));
|
||||
}
|
||||
|
||||
Assert.That(current, Is.EqualTo(end));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RangeTo_Int64_ShouldYieldCorrectValues()
|
||||
{
|
||||
const short start = 1;
|
||||
const long end = 10;
|
||||
|
||||
long current = 1;
|
||||
|
||||
foreach (long value in start.RangeTo(end))
|
||||
{
|
||||
Assert.That(value, Is.EqualTo(current++));
|
||||
}
|
||||
|
||||
Assert.That(current, Is.EqualTo(end));
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ internal class Int32Tests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RangeTo_Int32_ShouldYieldCorrectValues()
|
||||
public void RangeTo_ShouldYieldCorrectValues()
|
||||
{
|
||||
const int start = 1;
|
||||
const int end = 10;
|
||||
@ -64,18 +64,4 @@ internal class Int32Tests
|
||||
Assert.That(current, Is.EqualTo(end));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RangeTo_Int64_ShouldYieldCorrectValues()
|
||||
{
|
||||
const int start = 1;
|
||||
const long end = 10;
|
||||
|
||||
long current = 1;
|
||||
foreach (long value in start.RangeTo(end))
|
||||
{
|
||||
Assert.That(value, Is.EqualTo(current++));
|
||||
}
|
||||
|
||||
Assert.That(current, Is.EqualTo(end));
|
||||
}
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ internal class Int64Tests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RangeTo_Int64_ShouldYieldCorrectValues()
|
||||
public void RangeTo_ShouldYieldCorrectValues()
|
||||
{
|
||||
const long start = 1;
|
||||
const long end = 10;
|
||||
|
@ -9,29 +9,32 @@ internal class ReadOnlySpanTests
|
||||
[Test]
|
||||
public void AllShouldReturnTrueForEmptySpan()
|
||||
{
|
||||
var span = new ReadOnlySpan<int>();
|
||||
ReadOnlySpan<int> span = [];
|
||||
Assert.That(span.All(x => x > 0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllShouldBeCorrect()
|
||||
{
|
||||
var span = new ReadOnlySpan<int>(new[] { 2, 4, 6, 8, 10 });
|
||||
Assert.That(span.All(x => x % 2 == 0));
|
||||
Assert.That(span.All(x => x % 2 == 1), Is.False);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
ReadOnlySpan<int> span = [2, 4, 6, 8, 10];
|
||||
Assert.That(span.All(x => x % 2 == 0));
|
||||
Assert.That(span.All(x => x % 2 == 1), Is.False);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AnyShouldReturnFalseForEmptySpan()
|
||||
{
|
||||
var span = new ReadOnlySpan<int>();
|
||||
ReadOnlySpan<int> span = [];
|
||||
Assert.That(span.Any(x => x > 0), Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AnyShouldBeCorrect()
|
||||
{
|
||||
var span = new ReadOnlySpan<int>(new[] { 2, 4, 6, 8, 10 });
|
||||
ReadOnlySpan<int> span = [2, 4, 6, 8, 10];
|
||||
Assert.That(span.Any(x => x % 2 == 0));
|
||||
Assert.That(span.Any(x => x % 2 == 1), Is.False);
|
||||
}
|
||||
@ -41,7 +44,7 @@ internal class ReadOnlySpanTests
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() =>
|
||||
{
|
||||
var span = new ReadOnlySpan<int>();
|
||||
ReadOnlySpan<int> span = [];
|
||||
_ = span.All(null!);
|
||||
});
|
||||
}
|
||||
@ -51,7 +54,7 @@ internal class ReadOnlySpanTests
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() =>
|
||||
{
|
||||
var span = new ReadOnlySpan<int>();
|
||||
ReadOnlySpan<int> span = [];
|
||||
_ = span.Any(null!);
|
||||
});
|
||||
}
|
||||
@ -59,14 +62,14 @@ internal class ReadOnlySpanTests
|
||||
[Test]
|
||||
public void Count_ShouldReturn0_GivenEmptySpan()
|
||||
{
|
||||
var span = new ReadOnlySpan<int>();
|
||||
ReadOnlySpan<int> span = [];
|
||||
Assert.That(span.Count(i => i % 2 == 0), Is.Zero);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Count_ShouldReturn5_ForEvenNumbers_GivenNumbers1To10()
|
||||
{
|
||||
var span = new ReadOnlySpan<int>(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
||||
ReadOnlySpan<int> span = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||
Assert.That(span.Count(i => i % 2 == 0), Is.EqualTo(5));
|
||||
}
|
||||
|
||||
@ -75,7 +78,7 @@ internal class ReadOnlySpanTests
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() =>
|
||||
{
|
||||
var span = new ReadOnlySpan<int>();
|
||||
ReadOnlySpan<int> span = [];
|
||||
_ = span.Count((Predicate<int>)null!);
|
||||
});
|
||||
}
|
||||
|
@ -9,31 +9,37 @@ internal class SpanTests
|
||||
[Test]
|
||||
public void AllShouldReturnTrueForEmptySpan()
|
||||
{
|
||||
var span = new Span<int>();
|
||||
Span<int> span = [];
|
||||
Assert.That(span.All(x => x > 0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllShouldBeCorrect()
|
||||
{
|
||||
var span = new Span<int>(new[] { 2, 4, 6, 8, 10 });
|
||||
Assert.That(span.All(x => x % 2 == 0));
|
||||
Assert.That(span.All(x => x % 2 == 1), Is.False);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<int> span = [2, 4, 6, 8, 10];
|
||||
Assert.That(span.All(x => x % 2 == 0));
|
||||
Assert.That(span.All(x => x % 2 == 1), Is.False);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AnyShouldReturnFalseForEmptySpan()
|
||||
{
|
||||
var span = new Span<int>();
|
||||
Span<int> span = [];
|
||||
Assert.That(span.Any(x => x > 0), Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AnyShouldBeCorrect()
|
||||
{
|
||||
var span = new Span<int>(new[] { 2, 4, 6, 8, 10 });
|
||||
Assert.That(span.Any(x => x % 2 == 0));
|
||||
Assert.That(span.Any(x => x % 2 == 1), Is.False);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<int> span = [2, 4, 6, 8, 10];
|
||||
Assert.That(span.Any(x => x % 2 == 0));
|
||||
Assert.That(span.Any(x => x % 2 == 1), Is.False);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -41,7 +47,7 @@ internal class SpanTests
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() =>
|
||||
{
|
||||
var span = new Span<int>();
|
||||
Span<int> span = [];
|
||||
_ = span.All(null!);
|
||||
});
|
||||
}
|
||||
@ -51,7 +57,7 @@ internal class SpanTests
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() =>
|
||||
{
|
||||
var span = new Span<int>();
|
||||
Span<int> span = [];
|
||||
_ = span.Any(null!);
|
||||
});
|
||||
}
|
||||
@ -59,14 +65,14 @@ internal class SpanTests
|
||||
[Test]
|
||||
public void Count_ShouldReturn0_GivenEmptySpan()
|
||||
{
|
||||
var span = new Span<int>();
|
||||
Span<int> span = [];
|
||||
Assert.That(span.Count(i => i % 2 == 0), Is.Zero);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Count_ShouldReturn5_ForEvenNumbers_GivenNumbers1To10()
|
||||
{
|
||||
var span = new Span<int>(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
||||
Span<int> span = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||
Assert.That(span.Count(i => i % 2 == 0), Is.EqualTo(5));
|
||||
}
|
||||
|
||||
@ -75,7 +81,7 @@ internal class SpanTests
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() =>
|
||||
{
|
||||
var span = new Span<int>();
|
||||
Span<int> span = [];
|
||||
_ = span.Count((Predicate<int>)null!);
|
||||
});
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ internal class IsPrimeTests
|
||||
private static IReadOnlyList<int> LoadPrimes()
|
||||
{
|
||||
using var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("X10D.Tests.1000primes.txt");
|
||||
Assert.IsNotNull(stream);
|
||||
Assert.That(stream, Is.Not.Null);
|
||||
|
||||
using var reader = new StreamReader(stream, Encoding.UTF8);
|
||||
var primes = new List<int>();
|
||||
|
@ -20,7 +20,11 @@ internal class CoreTests
|
||||
int[] source = Enumerable.Range(1, 100).ToArray();
|
||||
string json = source.ToJson();
|
||||
int[]? target = json.FromJson<int[]>();
|
||||
CollectionAssert.AreEqual(source, target);
|
||||
CollectionAssert.AreEquivalent(source, target);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(target, Is.EqualTo(source).AsCollection);
|
||||
Assert.That(target, Is.EquivalentTo(source));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -10,45 +10,45 @@ internal class EnumerableTests
|
||||
public void Grep_ShouldFilterCorrectly_GivenPattern()
|
||||
{
|
||||
int year = DateTime.Now.Year;
|
||||
var source = new[] {"Hello", "World", "String 123", $"The year is {year}"};
|
||||
var expectedResult = new[] {"String 123", $"The year is {year}"};
|
||||
var source = new[] { "Hello", "World", "String 123", $"The year is {year}" };
|
||||
var expectedResult = new[] { "String 123", $"The year is {year}" };
|
||||
|
||||
const string pattern = /*lang=regex*/@"[0-9]+";
|
||||
string[] actualResult = source.Grep(pattern).ToArray();
|
||||
|
||||
CollectionAssert.AreEqual(expectedResult, actualResult);
|
||||
Assert.That(actualResult, Is.EqualTo(expectedResult).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Grep_ShouldYieldNoResults_GivenEmptySource()
|
||||
{
|
||||
string[] source = Array.Empty<string>();
|
||||
string[] expectedResult = Array.Empty<string>();
|
||||
string[] source = [];
|
||||
string[] expectedResult = [];
|
||||
|
||||
const string pattern = /*lang=regex*/@"[0-9]+";
|
||||
string[] actualResult = source.Grep(pattern).ToArray();
|
||||
|
||||
CollectionAssert.AreEqual(expectedResult, actualResult);
|
||||
Assert.That(actualResult, Is.EqualTo(expectedResult).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Grep_ShouldMatchUpperCase_GivenIgnoreCaseTrue()
|
||||
{
|
||||
int year = DateTime.Now.Year;
|
||||
var source = new[] {"Hello", "WORLD", "String 123", $"The year is {year}"};
|
||||
var expectedResult = new[] {"WORLD"};
|
||||
var source = new[] { "Hello", "WORLD", "String 123", $"The year is {year}" };
|
||||
var expectedResult = new[] { "WORLD" };
|
||||
|
||||
const string pattern = /*lang=regex*/@"world";
|
||||
string[] actualResult = source.Grep(pattern, true).ToArray();
|
||||
|
||||
CollectionAssert.AreEqual(expectedResult, actualResult);
|
||||
Assert.That(actualResult, Is.EqualTo(expectedResult).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Grep_ShouldNotMatchUpperCase_GivenIgnoreCaseFalse()
|
||||
{
|
||||
int year = DateTime.Now.Year;
|
||||
var source = new[] {"Hello", "WORLD", "String 123", $"The year is {year}"};
|
||||
var source = new[] { "Hello", "WORLD", "String 123", $"The year is {year}" };
|
||||
|
||||
const string pattern = /*lang=regex*/@"world";
|
||||
string[] actualResult = source.Grep(pattern, false).ToArray();
|
||||
@ -59,23 +59,29 @@ internal class EnumerableTests
|
||||
[Test]
|
||||
public void Grep_ShouldThrowArgumentNullException_GivenNullPattern()
|
||||
{
|
||||
IEnumerable<string> source = Enumerable.Empty<string>();
|
||||
Assert.Throws<ArgumentNullException>(() => source.Grep(null!).ToArray());
|
||||
Assert.Throws<ArgumentNullException>(() => source.Grep(null!, false).ToArray());
|
||||
IEnumerable<string> source = [];
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => source.Grep(null!).ToArray());
|
||||
Assert.Throws<ArgumentNullException>(() => source.Grep(null!, false).ToArray());
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Grep_ShouldThrowArgumentNullException_GivenNullSource()
|
||||
{
|
||||
IEnumerable<string> source = null!;
|
||||
Assert.Throws<ArgumentNullException>(() => source.Grep("foo").ToArray());
|
||||
Assert.Throws<ArgumentNullException>(() => source.Grep("foo", false).ToArray());
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => source.Grep("foo").ToArray());
|
||||
Assert.Throws<ArgumentNullException>(() => source.Grep("foo", false).ToArray());
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Grep_ShouldYieldNoElements_GivenNoMatchingStrings()
|
||||
{
|
||||
var source = new[] {"Hello", "World", "String"};
|
||||
var source = new[] { "Hello", "World", "String" };
|
||||
|
||||
const string pattern = /*lang=regex*/@"[0-9]+";
|
||||
string[] actualResult = source.Grep(pattern).ToArray();
|
||||
|
@ -22,18 +22,21 @@ internal class StringBuilderReaderTests
|
||||
{
|
||||
using var reader = new StringBuilderReader(new StringBuilder("Hello\nWorld"));
|
||||
|
||||
Assert.That(reader.Read(), Is.EqualTo('H'));
|
||||
Assert.That(reader.Read(), Is.EqualTo('e'));
|
||||
Assert.That(reader.Read(), Is.EqualTo('l'));
|
||||
Assert.That(reader.Read(), Is.EqualTo('l'));
|
||||
Assert.That(reader.Read(), Is.EqualTo('o'));
|
||||
Assert.That(reader.Read(), Is.EqualTo('\n'));
|
||||
Assert.That(reader.Read(), Is.EqualTo('W'));
|
||||
Assert.That(reader.Read(), Is.EqualTo('o'));
|
||||
Assert.That(reader.Read(), Is.EqualTo('r'));
|
||||
Assert.That(reader.Read(), Is.EqualTo('l'));
|
||||
Assert.That(reader.Read(), Is.EqualTo('d'));
|
||||
Assert.That(reader.Read(), Is.EqualTo(-1));
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(reader.Read(), Is.EqualTo('H'));
|
||||
Assert.That(reader.Read(), Is.EqualTo('e'));
|
||||
Assert.That(reader.Read(), Is.EqualTo('l'));
|
||||
Assert.That(reader.Read(), Is.EqualTo('l'));
|
||||
Assert.That(reader.Read(), Is.EqualTo('o'));
|
||||
Assert.That(reader.Read(), Is.EqualTo('\n'));
|
||||
Assert.That(reader.Read(), Is.EqualTo('W'));
|
||||
Assert.That(reader.Read(), Is.EqualTo('o'));
|
||||
Assert.That(reader.Read(), Is.EqualTo('r'));
|
||||
Assert.That(reader.Read(), Is.EqualTo('l'));
|
||||
Assert.That(reader.Read(), Is.EqualTo('d'));
|
||||
Assert.That(reader.Read(), Is.EqualTo(-1));
|
||||
});
|
||||
|
||||
reader.Close();
|
||||
}
|
||||
@ -45,9 +48,12 @@ internal class StringBuilderReaderTests
|
||||
|
||||
var array = new char[5];
|
||||
int read = reader.Read(array, 0, 5);
|
||||
Assert.That(read, Is.EqualTo(5));
|
||||
|
||||
CollectionAssert.AreEqual("Hello".ToCharArray(), array);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(read, Is.EqualTo(5));
|
||||
Assert.That(array, Is.EqualTo("Hello".ToCharArray()).AsCollection);
|
||||
});
|
||||
|
||||
reader.Close();
|
||||
}
|
||||
@ -114,11 +120,14 @@ internal class StringBuilderReaderTests
|
||||
{
|
||||
using var reader = new StringBuilderReader(new StringBuilder("Hello\nWorld"));
|
||||
|
||||
Span<char> span = stackalloc char[5];
|
||||
int read = reader.Read(span);
|
||||
Assert.That(read, Is.EqualTo(5));
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<char> span = stackalloc char[5];
|
||||
int read = reader.Read(span);
|
||||
|
||||
CollectionAssert.AreEqual("Hello".ToCharArray(), span.ToArray());
|
||||
Assert.That(read, Is.EqualTo(5));
|
||||
Assert.That(span.ToArray(), Is.EqualTo("Hello".ToCharArray()).AsCollection);
|
||||
});
|
||||
|
||||
reader.Close();
|
||||
}
|
||||
@ -130,9 +139,12 @@ internal class StringBuilderReaderTests
|
||||
|
||||
var array = new char[5];
|
||||
int read = reader.ReadAsync(array, 0, 5).GetAwaiter().GetResult();
|
||||
Assert.That(read, Is.EqualTo(5));
|
||||
|
||||
CollectionAssert.AreEqual("Hello".ToCharArray(), array);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(read, Is.EqualTo(5));
|
||||
Assert.That(array, Is.EqualTo("Hello".ToCharArray()).AsCollection);
|
||||
});
|
||||
|
||||
reader.Close();
|
||||
}
|
||||
@ -144,9 +156,12 @@ internal class StringBuilderReaderTests
|
||||
|
||||
Memory<char> memory = new char[5];
|
||||
int read = reader.ReadAsync(memory).GetAwaiter().GetResult();
|
||||
Assert.That(read, Is.EqualTo(5));
|
||||
|
||||
CollectionAssert.AreEqual("Hello".ToCharArray(), memory.ToArray());
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(read, Is.EqualTo(5));
|
||||
Assert.That(memory.ToArray(), Is.EqualTo("Hello".ToCharArray()).AsCollection);
|
||||
});
|
||||
|
||||
reader.Close();
|
||||
}
|
||||
@ -158,9 +173,12 @@ internal class StringBuilderReaderTests
|
||||
|
||||
var array = new char[5];
|
||||
int read = reader.ReadBlock(array, 0, 5);
|
||||
Assert.That(read, Is.EqualTo(5));
|
||||
|
||||
CollectionAssert.AreEqual("Hello".ToCharArray(), array);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(read, Is.EqualTo(5));
|
||||
Assert.That(array, Is.EqualTo("Hello".ToCharArray()).AsCollection);
|
||||
});
|
||||
|
||||
reader.Close();
|
||||
}
|
||||
@ -170,11 +188,14 @@ internal class StringBuilderReaderTests
|
||||
{
|
||||
using var reader = new StringBuilderReader(new StringBuilder("Hello\nWorld"));
|
||||
|
||||
Span<char> span = stackalloc char[5];
|
||||
int read = reader.ReadBlock(span);
|
||||
Assert.That(read, Is.EqualTo(5));
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Span<char> span = stackalloc char[5];
|
||||
int read = reader.ReadBlock(span);
|
||||
|
||||
CollectionAssert.AreEqual("Hello".ToCharArray(), span.ToArray());
|
||||
Assert.That(read, Is.EqualTo(5));
|
||||
Assert.That(span.ToArray(), Is.EqualTo("Hello".ToCharArray()).AsCollection);
|
||||
});
|
||||
|
||||
reader.Close();
|
||||
}
|
||||
@ -200,9 +221,12 @@ internal class StringBuilderReaderTests
|
||||
|
||||
var array = new char[5];
|
||||
int read = reader.ReadBlockAsync(array, 0, 5).GetAwaiter().GetResult();
|
||||
Assert.That(read, Is.EqualTo(5));
|
||||
|
||||
CollectionAssert.AreEqual("Hello".ToCharArray(), array);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(read, Is.EqualTo(5));
|
||||
Assert.That(array, Is.EqualTo("Hello".ToCharArray()).AsCollection);
|
||||
});
|
||||
|
||||
reader.Close();
|
||||
}
|
||||
@ -214,9 +238,12 @@ internal class StringBuilderReaderTests
|
||||
|
||||
Memory<char> memory = new char[5];
|
||||
int read = reader.ReadBlockAsync(memory).GetAwaiter().GetResult();
|
||||
Assert.That(read, Is.EqualTo(5));
|
||||
|
||||
CollectionAssert.AreEqual("Hello".ToCharArray(), memory.ToArray());
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(read, Is.EqualTo(5));
|
||||
Assert.That(memory.ToArray(), Is.EqualTo("Hello".ToCharArray()).AsCollection);
|
||||
});
|
||||
|
||||
reader.Close();
|
||||
}
|
||||
|
@ -423,7 +423,7 @@ internal class StringTests
|
||||
var target = json.FromJson<SampleStructure>();
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.IsInstanceOf<SampleStructure>(target);
|
||||
Assert.That(target, Is.InstanceOf<SampleStructure>());
|
||||
Assert.That(target.Values, Is.Not.Null);
|
||||
Assert.That(target.Values.Length, Is.EqualTo(3));
|
||||
Assert.That(target.Values[0], Is.EqualTo(1));
|
||||
@ -438,7 +438,7 @@ internal class StringTests
|
||||
var expected = new byte[] { 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64 };
|
||||
byte[] actual = "Hello World".GetBytes();
|
||||
|
||||
CollectionAssert.AreEqual(expected, actual);
|
||||
Assert.That(actual, Is.EqualTo(expected).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -447,7 +447,7 @@ internal class StringTests
|
||||
var expected = new byte[] { 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64 };
|
||||
byte[] actual = "Hello World".GetBytes(Encoding.ASCII);
|
||||
|
||||
CollectionAssert.AreEqual(expected, actual);
|
||||
Assert.That(actual, Is.EqualTo(expected).AsCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -1004,7 +1004,6 @@ internal class StringTests
|
||||
|
||||
private struct SampleStructure
|
||||
{
|
||||
[JsonPropertyName("values")]
|
||||
public int[] Values { get; set; }
|
||||
[JsonPropertyName("values")] public int[] Values { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -39,30 +39,6 @@ internal class DateOnlyTests
|
||||
Assert.That(age, Is.EqualTo(18));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Deconstruct_ShouldDeconstruct_GivenDateOnly()
|
||||
{
|
||||
var date = new DateOnly(2017, 12, 31);
|
||||
|
||||
date.Deconstruct(out int year, out int month, out int day);
|
||||
|
||||
Assert.That(year, Is.EqualTo(2017));
|
||||
Assert.That(month, Is.EqualTo(12));
|
||||
Assert.That(day, Is.EqualTo(31));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Deconstruct_ShouldDeconstructToTuple_GivenDateOnly()
|
||||
{
|
||||
var date = new DateOnly(2017, 12, 31);
|
||||
|
||||
(int year, int month, int day) = date;
|
||||
|
||||
Assert.That(year, Is.EqualTo(2017));
|
||||
Assert.That(month, Is.EqualTo(12));
|
||||
Assert.That(day, Is.EqualTo(31));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void First_ShouldBeSaturday_Given1Jan2000()
|
||||
{
|
||||
|
31
X10D.slnx
Normal file
31
X10D.slnx
Normal file
@ -0,0 +1,31 @@
|
||||
<Solution>
|
||||
<Folder Name="/Solution Items/">
|
||||
<File Path=".editorconfig"/>
|
||||
<File Path=".gitignore"/>
|
||||
<File Path="CHANGELOG.md"/>
|
||||
<File Path="CONTRIBUTING.md"/>
|
||||
<File Path="LICENSE.md"/>
|
||||
<File Path="README.md"/>
|
||||
<File Path="branding_Icon.png"/>
|
||||
<File Path="Directory.Build.props"/>
|
||||
<File Path="global.json"/>
|
||||
</Folder>
|
||||
<Folder Name="/Tools/">
|
||||
<Project Path="tools\Benchmarks\Benchmarks.csproj" Type="Classic C#"/>
|
||||
<Project Path="tools\SourceGenerator\SourceGenerator.csproj" Type="Classic C#"/>
|
||||
<Project Path="tools\SourceValidator\SourceValidator.csproj" Type="Classic C#"/>
|
||||
<Project Path="tools\X10D.MetaServices\X10D.MetaServices.csproj" Type="Classic C#"/>
|
||||
<File Path="tools\Directory.Build.props"/>
|
||||
</Folder>
|
||||
<Folder Name="/Workflows/">
|
||||
<File Path=".github\workflows\docfx.yml"/>
|
||||
<File Path=".github\workflows\dotnet.yml"/>
|
||||
<File Path=".github\workflows\nightly.yml"/>
|
||||
<File Path=".github\workflows\prerelease.yml"/>
|
||||
<File Path=".github\workflows\release.yml"/>
|
||||
<File Path=".github\workflows\source_validator.yml"/>
|
||||
</Folder>
|
||||
<Project Path="X10D.Hosting\X10D.Hosting.csproj" Type="Classic C#"/>
|
||||
<Project Path="X10D.Tests\X10D.Tests.csproj"/>
|
||||
<Project Path="X10D\X10D.csproj"/>
|
||||
</Solution>
|
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net8.0;net6.0</TargetFrameworks>
|
||||
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -1,4 +1,3 @@
|
||||
#if NET7_0_OR_GREATER
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Numerics;
|
||||
@ -95,4 +94,3 @@ public static class BinaryIntegerExtensions
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -1,7 +1,3 @@
|
||||
#if !NET7_0_OR_GREATER
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Diagnostics.Contracts;
|
||||
#endif
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.Intrinsics;
|
||||
using System.Runtime.Intrinsics.X86;
|
||||
@ -16,46 +12,6 @@ public static class ByteExtensions
|
||||
{
|
||||
private const int Size = sizeof(byte) * 8;
|
||||
|
||||
#if !NET7_0_OR_GREATER
|
||||
/// <summary>
|
||||
/// Unpacks this 8-bit unsigned integer into a boolean list, treating it as a bit field.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to unpack.</param>
|
||||
/// <returns>An array of <see cref="bool" /> with length 8.</returns>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static bool[] Unpack(this byte value)
|
||||
{
|
||||
var buffer = new bool[Size];
|
||||
value.Unpack(buffer);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unpacks this 8-bit unsigned integer into a boolean list, treating it as a bit field.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to unpack.</param>
|
||||
/// <param name="destination">When this method returns, contains the unpacked booleans from <paramref name="value" />.</param>
|
||||
/// <exception cref="ArgumentException"><paramref name="destination" /> is not large enough to contain the result.</exception>
|
||||
[ExcludeFromCodeCoverage]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static void Unpack(this byte value, Span<bool> destination)
|
||||
{
|
||||
if (destination.Length < Size)
|
||||
{
|
||||
throw new ArgumentException(ExceptionMessages.DestinationSpanLengthTooShort, nameof(destination));
|
||||
}
|
||||
|
||||
if (Sse3.IsSupported)
|
||||
{
|
||||
UnpackInternal_Ssse3(value, destination);
|
||||
return;
|
||||
}
|
||||
|
||||
UnpackInternal_Fallback(value, destination);
|
||||
}
|
||||
#endif
|
||||
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
internal static void UnpackInternal_Fallback(this byte value, Span<bool> destination)
|
||||
{
|
||||
|
@ -1,7 +1,3 @@
|
||||
#if !NET7_0_OR_GREATER
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Diagnostics.Contracts;
|
||||
#endif
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.Intrinsics;
|
||||
using System.Runtime.Intrinsics.X86;
|
||||
@ -16,46 +12,6 @@ public static class Int16Extensions
|
||||
{
|
||||
private const int Size = sizeof(short) * 8;
|
||||
|
||||
#if !NET7_0_OR_GREATER
|
||||
/// <summary>
|
||||
/// Unpacks this 16-bit signed integer into a boolean list, treating it as a bit field.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to unpack.</param>
|
||||
/// <returns>An array of <see cref="bool" /> with length 16.</returns>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static bool[] Unpack(this short value)
|
||||
{
|
||||
var ret = new bool[Size];
|
||||
value.Unpack(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unpacks this 16-bit signed integer into a boolean list, treating it as a bit field.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to unpack.</param>
|
||||
/// <param name="destination">When this method returns, contains the unpacked booleans from <paramref name="value" />.</param>
|
||||
/// <exception cref="ArgumentException"><paramref name="destination" /> is not large enough to contain the result.</exception>
|
||||
[ExcludeFromCodeCoverage]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static void Unpack(this short value, Span<bool> destination)
|
||||
{
|
||||
if (destination.Length < Size)
|
||||
{
|
||||
throw new ArgumentException(ExceptionMessages.DestinationSpanLengthTooShort, nameof(destination));
|
||||
}
|
||||
|
||||
if (Sse3.IsSupported)
|
||||
{
|
||||
UnpackInternal_Ssse3(value, destination);
|
||||
return;
|
||||
}
|
||||
|
||||
UnpackInternal_Fallback(value, destination);
|
||||
}
|
||||
#endif
|
||||
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
internal static void UnpackInternal_Fallback(this short value, Span<bool> destination)
|
||||
{
|
||||
|
@ -1,7 +1,3 @@
|
||||
#if !NET7_0_OR_GREATER
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Diagnostics.Contracts;
|
||||
#endif
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.Intrinsics;
|
||||
using System.Runtime.Intrinsics.X86;
|
||||
@ -16,52 +12,6 @@ public static class Int32Extensions
|
||||
{
|
||||
private const int Size = sizeof(int) * 8;
|
||||
|
||||
#if !NET7_0_OR_GREATER
|
||||
/// <summary>
|
||||
/// Unpacks this 32-bit signed integer into a boolean list, treating it as a bit field.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to unpack.</param>
|
||||
/// <returns>An array of <see cref="bool" /> with length 32.</returns>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static bool[] Unpack(this int value)
|
||||
{
|
||||
var ret = new bool[Size];
|
||||
value.Unpack(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unpacks this 32-bit signed integer into a boolean list, treating it as a bit field.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to unpack.</param>
|
||||
/// <param name="destination">When this method returns, contains the unpacked booleans from <paramref name="value" />.</param>
|
||||
/// <exception cref="ArgumentException"><paramref name="destination" /> is not large enough to contain the result.</exception>
|
||||
[ExcludeFromCodeCoverage]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static void Unpack(this int value, Span<bool> destination)
|
||||
{
|
||||
if (destination.Length < Size)
|
||||
{
|
||||
throw new ArgumentException(ExceptionMessages.DestinationSpanLengthTooShort, nameof(destination));
|
||||
}
|
||||
|
||||
if (Avx2.IsSupported)
|
||||
{
|
||||
UnpackInternal_Avx2(value, destination);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Sse3.IsSupported)
|
||||
{
|
||||
UnpackInternal_Ssse3(value, destination);
|
||||
return;
|
||||
}
|
||||
|
||||
UnpackInternal_Fallback(value, destination);
|
||||
}
|
||||
#endif
|
||||
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
internal static void UnpackInternal_Fallback(this int value, Span<bool> destination)
|
||||
{
|
||||
|
@ -1,45 +0,0 @@
|
||||
#if !NET7_0_OR_GREATER
|
||||
using System.Diagnostics.Contracts;
|
||||
|
||||
namespace X10D.Collections;
|
||||
|
||||
/// <summary>
|
||||
/// Collection-related extension methods for <see cref="long" />.
|
||||
/// </summary>
|
||||
public static class Int64Extensions
|
||||
{
|
||||
private const int Size = sizeof(long) * 8;
|
||||
|
||||
/// <summary>
|
||||
/// Unpacks this 64-bit signed integer into a boolean list, treating it as a bit field.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to unpack.</param>
|
||||
/// <returns>An array of <see cref="bool" /> with length 64.</returns>
|
||||
[Pure]
|
||||
public static bool[] Unpack(this long value)
|
||||
{
|
||||
var ret = new bool[Size];
|
||||
value.Unpack(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unpacks this 64-bit signed integer into a boolean list, treating it as a bit field.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to unpack.</param>
|
||||
/// <param name="destination">When this method returns, contains the unpacked booleans from <paramref name="value" />.</param>
|
||||
/// <exception cref="ArgumentException"><paramref name="destination" /> is not large enough to contain the result.</exception>
|
||||
public static void Unpack(this long value, Span<bool> destination)
|
||||
{
|
||||
if (destination.Length < Size)
|
||||
{
|
||||
throw new ArgumentException(ExceptionMessages.DestinationSpanLengthTooShort, nameof(destination));
|
||||
}
|
||||
|
||||
for (var index = 0; index < Size; index++)
|
||||
{
|
||||
destination[index] = (value & (1L << index)) != 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -75,6 +75,7 @@ public static class SpanExtensions
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !NET9_0_OR_GREATER
|
||||
/// <summary>
|
||||
/// Splits a span of elements into sub-spans based on a delimiting element.
|
||||
/// </summary>
|
||||
@ -134,4 +135,5 @@ public static class SpanExtensions
|
||||
{
|
||||
return new SpanSplitEnumerator<T>(source, delimiter);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ public static class Extensions
|
||||
[Pure]
|
||||
public static T[] AsArrayValue<T>(this T value)
|
||||
{
|
||||
return new[] {value};
|
||||
return [value];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -37,12 +37,7 @@ public static class IntrinsicExtensions
|
||||
for (var i = 0; i < Vector64<byte>.Count; i++)
|
||||
{
|
||||
ref byte writeElement = ref Unsafe.Add(ref Unsafe.As<Vector64<byte>, byte>(ref output), i);
|
||||
#if NET7_0_OR_GREATER
|
||||
writeElement = vector[i] == 0 ? (byte)0 : (byte)1;
|
||||
#else
|
||||
byte element = Unsafe.Add(ref Unsafe.As<Vector64<byte>, byte>(ref vector), i);
|
||||
writeElement = element == 0 ? (byte)0 : (byte)1;
|
||||
#endif
|
||||
}
|
||||
|
||||
return output;
|
||||
|
@ -1,3 +1,4 @@
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Runtime.CompilerServices;
|
||||
@ -6,10 +7,6 @@ using System.Runtime.Intrinsics;
|
||||
using System.Runtime.Intrinsics.X86;
|
||||
using X10D.CompilerServices;
|
||||
|
||||
#if NET7_0_OR_GREATER
|
||||
using System.Diagnostics;
|
||||
#endif
|
||||
|
||||
namespace X10D.Core;
|
||||
|
||||
/// <summary>
|
||||
@ -93,11 +90,7 @@ public static class SpanExtensions
|
||||
|
||||
// dotcover disable
|
||||
default:
|
||||
#if NET7_0_OR_GREATER
|
||||
throw new UnreachableException(string.Format(ExceptionMessages.EnumSizeIsUnexpected, Unsafe.SizeOf<T>()));
|
||||
#else
|
||||
throw new ArgumentException(string.Format(ExceptionMessages.EnumSizeIsUnexpected, Unsafe.SizeOf<T>()));
|
||||
#endif
|
||||
// dotcover enable
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ namespace X10D.Drawing;
|
||||
/// </summary>
|
||||
public class Polygon : IEquatable<Polygon>
|
||||
{
|
||||
private readonly List<Point> _vertices = new();
|
||||
private readonly List<Point> _vertices = [];
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Polygon" /> class.
|
||||
@ -27,7 +27,7 @@ public class Polygon : IEquatable<Polygon>
|
||||
throw new ArgumentNullException(nameof(polygon));
|
||||
}
|
||||
|
||||
_vertices = new List<Point>();
|
||||
_vertices = [];
|
||||
for (var index = 0; index < polygon._vertices.Count; index++)
|
||||
{
|
||||
Point vertex = polygon._vertices[index];
|
||||
@ -46,7 +46,7 @@ public class Polygon : IEquatable<Polygon>
|
||||
throw new ArgumentNullException(nameof(vertices));
|
||||
}
|
||||
|
||||
_vertices = new List<Point>(vertices);
|
||||
_vertices = [..vertices];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -10,7 +10,7 @@ namespace X10D.Drawing;
|
||||
/// </summary>
|
||||
public class PolygonF
|
||||
{
|
||||
private readonly List<PointF> _vertices = new();
|
||||
private readonly List<PointF> _vertices = [];
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PolygonF" /> class.
|
||||
@ -29,7 +29,7 @@ public class PolygonF
|
||||
{
|
||||
throw new ArgumentNullException(nameof(polygon));
|
||||
}
|
||||
_vertices = new List<PointF>();
|
||||
_vertices = [];
|
||||
for (var index = 0; index < polygon._vertices.Count; index++)
|
||||
{
|
||||
PointF vertex = polygon._vertices[index];
|
||||
@ -49,7 +49,7 @@ public class PolygonF
|
||||
throw new ArgumentNullException(nameof(vertices));
|
||||
}
|
||||
|
||||
_vertices = new List<PointF>();
|
||||
_vertices = [];
|
||||
foreach (Vector2 vertex in vertices)
|
||||
{
|
||||
_vertices.Add(vertex.ToPointF());
|
||||
@ -68,7 +68,7 @@ public class PolygonF
|
||||
throw new ArgumentNullException(nameof(vertices));
|
||||
}
|
||||
|
||||
_vertices = new List<PointF>(vertices);
|
||||
_vertices = [..vertices];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -9,7 +9,7 @@ namespace X10D.Drawing;
|
||||
/// </summary>
|
||||
public class Polyhedron : IEquatable<Polyhedron>
|
||||
{
|
||||
private readonly List<Vector3> _vertices = new();
|
||||
private readonly List<Vector3> _vertices = [];
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Polyhedron" /> class.
|
||||
@ -39,7 +39,7 @@ public class Polyhedron : IEquatable<Polyhedron>
|
||||
throw new ArgumentNullException(nameof(vertices));
|
||||
}
|
||||
|
||||
_vertices = new List<Vector3>(vertices);
|
||||
_vertices = [..vertices];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -1,6 +1,5 @@
|
||||
using System.Buffers.Binary;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace X10D.IO;
|
||||
|
||||
|
@ -1,161 +0,0 @@
|
||||
using System.Diagnostics.Contracts;
|
||||
|
||||
namespace X10D.Linq;
|
||||
|
||||
/// <summary>
|
||||
/// LINQ-inspired extension methods for <see cref="IEnumerable{T}" /> of <see cref="byte" />.
|
||||
/// </summary>
|
||||
public static class ByteExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Computes the product of a sequence of <see cref="byte" /> values.
|
||||
/// </summary>
|
||||
/// <param name="source">A sequence of <see cref="byte" /> values that are used to calculate the product.</param>
|
||||
/// <returns>The product the values in the sequence.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
|
||||
public static byte Product(this IEnumerable<byte> source)
|
||||
{
|
||||
if (source is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(source));
|
||||
}
|
||||
|
||||
return source.Aggregate((byte)1, (current, value) => (byte)(current * value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes the product of a sequence of <see cref="sbyte" /> values.
|
||||
/// </summary>
|
||||
/// <param name="source">A sequence of <see cref="sbyte" /> values that are used to calculate the product.</param>
|
||||
/// <returns>The product the values in the sequence.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
|
||||
[CLSCompliant(false)]
|
||||
public static sbyte Product(this IEnumerable<sbyte> source)
|
||||
{
|
||||
if (source is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(source));
|
||||
}
|
||||
|
||||
return source.Aggregate((sbyte)1, (current, value) => (sbyte)(current * value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes the product of a sequence of <see cref="byte" /> values that are obtained by invoking a transform function
|
||||
/// on each element of the input sequence.
|
||||
/// </summary>
|
||||
/// <param name="source">A sequence of values that are used to calculate a product.</param>
|
||||
/// <param name="selector">A transform function to apply to each element.</param>
|
||||
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
|
||||
/// <returns>The product of the projected values.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
|
||||
public static byte Product<TSource>(this IEnumerable<TSource> source, Func<TSource, byte> selector)
|
||||
{
|
||||
if (source is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(source));
|
||||
}
|
||||
|
||||
return source.Select(selector).Product();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes the product of a sequence of <see cref="sbyte" /> values that are obtained by invoking a transform function
|
||||
/// on each element of the input sequence.
|
||||
/// </summary>
|
||||
/// <param name="source">A sequence of values that are used to calculate a product.</param>
|
||||
/// <param name="selector">A transform function to apply to each element.</param>
|
||||
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
|
||||
/// <returns>The product of the projected values.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
|
||||
[CLSCompliant(false)]
|
||||
public static sbyte Product<TSource>(this IEnumerable<TSource> source, Func<TSource, sbyte> selector)
|
||||
{
|
||||
if (source is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(source));
|
||||
}
|
||||
|
||||
return source.Select(selector).Product();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerable sequence of 8-bit integers ranging from the current value to a specified value.
|
||||
/// </summary>
|
||||
/// <param name="value">The starting value of the sequence.</param>
|
||||
/// <param name="end">The ending value of the sequence.</param>
|
||||
/// <returns>
|
||||
/// An enumerable collection of 8-bit integers, ranging from <paramref name="value" /> to <paramref name="end" />.
|
||||
/// </returns>
|
||||
[Pure]
|
||||
public static IEnumerable<byte> RangeTo(this byte value, byte end)
|
||||
{
|
||||
byte start = System.Math.Min(value, end);
|
||||
end = System.Math.Max(value, end);
|
||||
|
||||
for (byte current = start; current < end; current++)
|
||||
{
|
||||
yield return current;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerable sequence of 16-bit integers ranging from the current value to a specified value.
|
||||
/// </summary>
|
||||
/// <param name="value">The starting value of the sequence.</param>
|
||||
/// <param name="end">The ending value of the sequence.</param>
|
||||
/// <returns>
|
||||
/// An enumerable collection of 16-bit integers, ranging from <paramref name="value" /> to <paramref name="end" />.
|
||||
/// </returns>
|
||||
[Pure]
|
||||
public static IEnumerable<short> RangeTo(this byte value, short end)
|
||||
{
|
||||
short start = System.Math.Min(value, end);
|
||||
end = System.Math.Max(value, end);
|
||||
|
||||
for (short current = start; current < end; current++)
|
||||
{
|
||||
yield return current;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerable sequence of 32-bit integers ranging from the current value to a specified value.
|
||||
/// </summary>
|
||||
/// <param name="value">The starting value of the sequence.</param>
|
||||
/// <param name="end">The ending value of the sequence.</param>
|
||||
/// <returns>
|
||||
/// An enumerable collection of 32-bit integers, ranging from <paramref name="value" /> to <paramref name="end" />.
|
||||
/// </returns>
|
||||
[Pure]
|
||||
public static IEnumerable<int> RangeTo(this byte value, int end)
|
||||
{
|
||||
int start = System.Math.Min(value, end);
|
||||
end = System.Math.Max(value, end);
|
||||
|
||||
for (int current = start; current < end; current++)
|
||||
{
|
||||
yield return current;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerable sequence of 64-bit integers ranging from the current value to a specified value.
|
||||
/// </summary>
|
||||
/// <param name="value">The starting value of the sequence.</param>
|
||||
/// <param name="end">The ending value of the sequence.</param>
|
||||
/// <returns>
|
||||
/// An enumerable collection of 64-bit integers, ranging from <paramref name="value" /> to <paramref name="end" />.
|
||||
/// </returns>
|
||||
[Pure]
|
||||
public static IEnumerable<long> RangeTo(this byte value, long end)
|
||||
{
|
||||
long start = System.Math.Min(value, end);
|
||||
end = System.Math.Max(value, end);
|
||||
|
||||
for (long current = start; current < end; current++)
|
||||
{
|
||||
yield return current;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
namespace X10D.Linq;
|
||||
|
||||
/// <summary>
|
||||
/// LINQ-inspired extension methods for <see cref="IEnumerable{T}" /> of <see cref="decimal" />.
|
||||
/// </summary>
|
||||
public static class DecimalExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Computes the product of a sequence of <see cref="decimal" /> values.
|
||||
/// </summary>
|
||||
/// <param name="source">A sequence of <see cref="decimal" /> values that are used to calculate the product.</param>
|
||||
/// <returns>The product the values in the sequence.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
|
||||
public static decimal Product(this IEnumerable<decimal> source)
|
||||
{
|
||||
if (source is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(source));
|
||||
}
|
||||
|
||||
return source.Aggregate(1m, (current, value) => (current * value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes the product of a sequence of <see cref="decimal" /> values that are obtained by invoking a transform function
|
||||
/// on each element of the input sequence.
|
||||
/// </summary>
|
||||
/// <param name="source">A sequence of values that are used to calculate a product.</param>
|
||||
/// <param name="selector">A transform function to apply to each element.</param>
|
||||
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
|
||||
/// <returns>The product of the projected values.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
|
||||
public static decimal Product<TSource>(this IEnumerable<TSource> source, Func<TSource, decimal> selector)
|
||||
{
|
||||
if (source is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(source));
|
||||
}
|
||||
|
||||
return source.Select(selector).Product();
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
namespace X10D.Linq;
|
||||
|
||||
/// <summary>
|
||||
/// LINQ-inspired extension methods for <see cref="IEnumerable{T}" /> of <see cref="double" />.
|
||||
/// </summary>
|
||||
public static class DoubleExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Computes the product of a sequence of <see cref="double" /> values.
|
||||
/// </summary>
|
||||
/// <param name="source">A sequence of <see cref="double" /> values that are used to calculate the product.</param>
|
||||
/// <returns>The product the values in the sequence.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
|
||||
public static double Product(this IEnumerable<double> source)
|
||||
{
|
||||
if (source is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(source));
|
||||
}
|
||||
|
||||
return source.Aggregate(1.0, (current, value) => (current * value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes the product of a sequence of <see cref="double" /> values that are obtained by invoking a transform function
|
||||
/// on each element of the input sequence.
|
||||
/// </summary>
|
||||
/// <param name="source">A sequence of values that are used to calculate a product.</param>
|
||||
/// <param name="selector">A transform function to apply to each element.</param>
|
||||
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
|
||||
/// <returns>The product of the projected values.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
|
||||
public static double Product<TSource>(this IEnumerable<TSource> source, Func<TSource, double> selector)
|
||||
{
|
||||
if (source is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(source));
|
||||
}
|
||||
|
||||
return source.Select(selector).Product();
|
||||
}
|
||||
}
|
@ -1,117 +0,0 @@
|
||||
using System.Diagnostics.Contracts;
|
||||
|
||||
namespace X10D.Linq;
|
||||
|
||||
/// <summary>
|
||||
/// LINQ-inspired extension methods for <see cref="IEnumerable{T}" /> of <see cref="long" />.
|
||||
/// </summary>
|
||||
public static class Int16Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Computes the product of a sequence of <see cref="short" /> values.
|
||||
/// </summary>
|
||||
/// <param name="source">A sequence of <see cref="short" /> values that are used to calculate the product.</param>
|
||||
/// <returns>The product the values in the sequence.</returns>
|
||||
public static short Product(this IEnumerable<short> source)
|
||||
{
|
||||
return source.Aggregate((short)1, (current, value) => (short)(current * value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes the product of a sequence of <see cref="ushort" /> values.
|
||||
/// </summary>
|
||||
/// <param name="source">A sequence of <see cref="ushort" /> values that are used to calculate the product.</param>
|
||||
/// <returns>The product the values in the sequence.</returns>
|
||||
[CLSCompliant(false)]
|
||||
public static ushort Product(this IEnumerable<ushort> source)
|
||||
{
|
||||
return source.Aggregate((ushort)1, (current, value) => (ushort)(current * value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes the product of a sequence of <see cref="short" /> values that are obtained by invoking a transform function
|
||||
/// on each element of the input sequence.
|
||||
/// </summary>
|
||||
/// <param name="source">A sequence of values that are used to calculate a product.</param>
|
||||
/// <param name="selector">A transform function to apply to each element.</param>
|
||||
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
|
||||
/// <returns>The product of the projected values.</returns>
|
||||
public static short Product<TSource>(this IEnumerable<TSource> source, Func<TSource, short> selector)
|
||||
{
|
||||
return source.Select(selector).Product();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes the product of a sequence of <see cref="ushort" /> values that are obtained by invoking a transform function
|
||||
/// on each element of the input sequence.
|
||||
/// </summary>
|
||||
/// <param name="source">A sequence of values that are used to calculate a product.</param>
|
||||
/// <param name="selector">A transform function to apply to each element.</param>
|
||||
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
|
||||
/// <returns>The product of the projected values.</returns>
|
||||
[CLSCompliant(false)]
|
||||
public static ushort Product<TSource>(this IEnumerable<TSource> source, Func<TSource, ushort> selector)
|
||||
{
|
||||
return source.Select(selector).Product();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerable sequence of 16-bit integers ranging from the current value to a specified value.
|
||||
/// </summary>
|
||||
/// <param name="value">The starting value of the sequence.</param>
|
||||
/// <param name="end">The ending value of the sequence.</param>
|
||||
/// <returns>
|
||||
/// An enumerable collection of 16-bit integers, ranging from <paramref name="value" /> to <paramref name="end" />.
|
||||
/// </returns>
|
||||
[Pure]
|
||||
public static IEnumerable<short> RangeTo(this short value, short end)
|
||||
{
|
||||
short start = System.Math.Min(value, end);
|
||||
end = System.Math.Max(value, end);
|
||||
|
||||
for (short current = start; current < end; current++)
|
||||
{
|
||||
yield return current;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerable sequence of 32-bit integers ranging from the current value to a specified value.
|
||||
/// </summary>
|
||||
/// <param name="value">The starting value of the sequence.</param>
|
||||
/// <param name="end">The ending value of the sequence.</param>
|
||||
/// <returns>
|
||||
/// An enumerable collection of 32-bit integers, ranging from <paramref name="value" /> to <paramref name="end" />.
|
||||
/// </returns>
|
||||
[Pure]
|
||||
public static IEnumerable<int> RangeTo(this short value, int end)
|
||||
{
|
||||
int start = System.Math.Min(value, end);
|
||||
end = System.Math.Max(value, end);
|
||||
|
||||
for (int current = start; current < end; current++)
|
||||
{
|
||||
yield return current;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerable sequence of 64-bit integers ranging from the current value to a specified value.
|
||||
/// </summary>
|
||||
/// <param name="value">The starting value of the sequence.</param>
|
||||
/// <param name="end">The ending value of the sequence.</param>
|
||||
/// <returns>
|
||||
/// An enumerable collection of 64-bit integers, ranging from <paramref name="value" /> to <paramref name="end" />.
|
||||
/// </returns>
|
||||
[Pure]
|
||||
public static IEnumerable<long> RangeTo(this short value, long end)
|
||||
{
|
||||
long start = System.Math.Min(value, end);
|
||||
end = System.Math.Max(value, end);
|
||||
|
||||
for (long current = start; current < end; current++)
|
||||
{
|
||||
yield return current;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,121 +0,0 @@
|
||||
using System.Diagnostics.Contracts;
|
||||
|
||||
namespace X10D.Linq;
|
||||
|
||||
/// <summary>
|
||||
/// LINQ-inspired extension methods for <see cref="IEnumerable{T}" /> of <see cref="int" />.
|
||||
/// </summary>
|
||||
public static class Int32Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Computes the product of a sequence of <see cref="int" /> values.
|
||||
/// </summary>
|
||||
/// <param name="source">A sequence of <see cref="int" /> values that are used to calculate the product.</param>
|
||||
/// <returns>The product the values in the sequence.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
|
||||
public static int Product(this IEnumerable<int> source)
|
||||
{
|
||||
if (source is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(source));
|
||||
}
|
||||
|
||||
return source.Aggregate(1, (current, value) => current * value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes the product of a sequence of <see cref="uint" /> values.
|
||||
/// </summary>
|
||||
/// <param name="source">A sequence of <see cref="uint" /> values that are used to calculate the product.</param>
|
||||
/// <returns>The product the values in the sequence.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
|
||||
[CLSCompliant(false)]
|
||||
public static uint Product(this IEnumerable<uint> source)
|
||||
{
|
||||
if (source is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(source));
|
||||
}
|
||||
|
||||
return source.Aggregate(1u, (current, value) => current * value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes the product of a sequence of <see cref="int" /> values that are obtained by invoking a transform function on
|
||||
/// each element of the input sequence.
|
||||
/// </summary>
|
||||
/// <param name="source">A sequence of values that are used to calculate a product.</param>
|
||||
/// <param name="selector">A transform function to apply to each element.</param>
|
||||
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
|
||||
/// <returns>The product of the projected values.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
|
||||
public static int Product<TSource>(this IEnumerable<TSource> source, Func<TSource, int> selector)
|
||||
{
|
||||
if (source is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(source));
|
||||
}
|
||||
|
||||
return source.Select(selector).Product();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes the product of a sequence of <see cref="uint" /> values that are obtained by invoking a transform function on
|
||||
/// each element of the input sequence.
|
||||
/// </summary>
|
||||
/// <param name="source">A sequence of values that are used to calculate a product.</param>
|
||||
/// <param name="selector">A transform function to apply to each element.</param>
|
||||
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
|
||||
/// <returns>The product of the projected values.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
|
||||
[CLSCompliant(false)]
|
||||
public static uint Product<TSource>(this IEnumerable<TSource> source, Func<TSource, uint> selector)
|
||||
{
|
||||
if (source is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(source));
|
||||
}
|
||||
|
||||
return source.Select(selector).Product();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerable sequence of 32-bit integers ranging from the current value to a specified value.
|
||||
/// </summary>
|
||||
/// <param name="value">The starting value of the sequence.</param>
|
||||
/// <param name="end">The ending value of the sequence.</param>
|
||||
/// <returns>
|
||||
/// An enumerable collection of 32-bit integers, ranging from <paramref name="value" /> to <paramref name="end" />.
|
||||
/// </returns>
|
||||
[Pure]
|
||||
public static IEnumerable<int> RangeTo(this int value, int end)
|
||||
{
|
||||
int start = System.Math.Min(value, end);
|
||||
end = System.Math.Max(value, end);
|
||||
|
||||
for (int current = start; current < end; current++)
|
||||
{
|
||||
yield return current;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerable sequence of 64-bit integers ranging from the current value to a specified value.
|
||||
/// </summary>
|
||||
/// <param name="value">The starting value of the sequence.</param>
|
||||
/// <param name="end">The ending value of the sequence.</param>
|
||||
/// <returns>
|
||||
/// An enumerable collection of 64-bit integers, ranging from <paramref name="value" /> to <paramref name="end" />.
|
||||
/// </returns>
|
||||
[Pure]
|
||||
public static IEnumerable<long> RangeTo(this int value, long end)
|
||||
{
|
||||
long start = System.Math.Min(value, end);
|
||||
end = System.Math.Max(value, end);
|
||||
|
||||
for (long current = start; current < end; current++)
|
||||
{
|
||||
yield return current;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,101 +0,0 @@
|
||||
using System.Diagnostics.Contracts;
|
||||
|
||||
namespace X10D.Linq;
|
||||
|
||||
/// <summary>
|
||||
/// LINQ-inspired extension methods for <see cref="IEnumerable{T}" /> of <see cref="long" />.
|
||||
/// </summary>
|
||||
public static class Int64Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Computes the product of a sequence of <see cref="long" /> values.
|
||||
/// </summary>
|
||||
/// <param name="source">A sequence of <see cref="long" /> values that are used to calculate the product.</param>
|
||||
/// <returns>The product the values in the sequence.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
|
||||
public static long Product(this IEnumerable<long> source)
|
||||
{
|
||||
if (source is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(source));
|
||||
}
|
||||
|
||||
return source.Aggregate(1L, (current, value) => current * value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes the product of a sequence of <see cref="ulong" /> values.
|
||||
/// </summary>
|
||||
/// <param name="source">A sequence of <see cref="ulong" /> values that are used to calculate the product.</param>
|
||||
/// <returns>The product the values in the sequence.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
|
||||
[CLSCompliant(false)]
|
||||
public static ulong Product(this IEnumerable<ulong> source)
|
||||
{
|
||||
if (source is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(source));
|
||||
}
|
||||
|
||||
return source.Aggregate(1UL, (current, value) => current * value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes the product of a sequence of <see cref="long" /> values that are obtained by invoking a transform function on
|
||||
/// each element of the input sequence.
|
||||
/// </summary>
|
||||
/// <param name="source">A sequence of values that are used to calculate a product.</param>
|
||||
/// <param name="selector">A transform function to apply to each element.</param>
|
||||
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
|
||||
/// <returns>The product of the projected values.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
|
||||
public static long Product<TSource>(this IEnumerable<TSource> source, Func<TSource, long> selector)
|
||||
{
|
||||
if (source is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(source));
|
||||
}
|
||||
|
||||
return source.Select(selector).Product();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes the product of a sequence of <see cref="ulong" /> values that are obtained by invoking a transform function
|
||||
/// on each element of the input sequence.
|
||||
/// </summary>
|
||||
/// <param name="source">A sequence of values that are used to calculate a product.</param>
|
||||
/// <param name="selector">A transform function to apply to each element.</param>
|
||||
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
|
||||
/// <returns>The product of the projected values.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
|
||||
[CLSCompliant(false)]
|
||||
public static ulong Product<TSource>(this IEnumerable<TSource> source, Func<TSource, ulong> selector)
|
||||
{
|
||||
if (source is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(source));
|
||||
}
|
||||
|
||||
return source.Select(selector).Product();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerable sequence of 64-bit integers ranging from the current value to a specified value.
|
||||
/// </summary>
|
||||
/// <param name="value">The starting value of the sequence.</param>
|
||||
/// <param name="end">The ending value of the sequence.</param>
|
||||
/// <returns>
|
||||
/// An enumerable collection of 64-bit integers, ranging from <paramref name="value" /> to <paramref name="end" />.
|
||||
/// </returns>
|
||||
[Pure]
|
||||
public static IEnumerable<long> RangeTo(this long value, long end)
|
||||
{
|
||||
long start = System.Math.Min(value, end);
|
||||
end = System.Math.Max(value, end);
|
||||
|
||||
for (long current = start; current < end; current++)
|
||||
{
|
||||
yield return current;
|
||||
}
|
||||
}
|
||||
}
|
72
X10D/src/Linq/NumberExtensions.cs
Normal file
72
X10D/src/Linq/NumberExtensions.cs
Normal file
@ -0,0 +1,72 @@
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Numerics;
|
||||
|
||||
namespace X10D.Linq;
|
||||
|
||||
/// <summary>
|
||||
/// LINQ-inspired extension methods for <see cref="IEnumerable{T}" /> of <see cref="INumber{TSelf}" />.
|
||||
/// </summary>
|
||||
public static class NumberExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Computes the product of a sequence of <see cref="INumber{TSelf}" /> values.
|
||||
/// </summary>
|
||||
/// <param name="source">A sequence of <see cref="int" /> values that are used to calculate the product.</param>
|
||||
/// <typeparam name="TNumber">The type of the number for which to compute the product.</typeparam>
|
||||
/// <returns>The product the values in the sequence.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
|
||||
public static TNumber Product<TNumber>(this IEnumerable<TNumber> source)
|
||||
where TNumber : INumber<TNumber>
|
||||
{
|
||||
if (source is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(source));
|
||||
}
|
||||
|
||||
return source.Aggregate(TNumber.MultiplicativeIdentity, (current, value) => current * value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes the product of a sequence of <see cref="INumber{TSelf}" /> values that are obtained by invoking a transform
|
||||
/// function on each element of the input sequence.
|
||||
/// </summary>
|
||||
/// <param name="source">A sequence of values that are used to calculate a product.</param>
|
||||
/// <param name="selector">A transform function to apply to each element.</param>
|
||||
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
|
||||
/// <typeparam name="TNumber">The type of the number for which to compute the product.</typeparam>
|
||||
/// <returns>The product of the projected values.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
|
||||
public static TNumber Product<TSource, TNumber>(this IEnumerable<TSource> source, Func<TSource, TNumber> selector)
|
||||
where TNumber : INumber<TNumber>
|
||||
{
|
||||
if (source is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(source));
|
||||
}
|
||||
|
||||
return source.Select(selector).Product();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerable sequence of numbers ranging from the current value to a specified value.
|
||||
/// </summary>
|
||||
/// <param name="value">The starting value of the sequence.</param>
|
||||
/// <param name="end">The ending value of the sequence.</param>
|
||||
/// <typeparam name="TNumber">The type of the number for which to compute the product.</typeparam>
|
||||
/// <returns>
|
||||
/// An enumerable collection of <typeparamref name="TNumber"/>, ranging from <paramref name="value" /> to
|
||||
/// <paramref name="end" />.
|
||||
/// </returns>
|
||||
[Pure]
|
||||
public static IEnumerable<TNumber> RangeTo<TNumber>(this TNumber value, TNumber end)
|
||||
where TNumber : INumber<TNumber>
|
||||
{
|
||||
TNumber start = TNumber.Min(value, end);
|
||||
end = TNumber.Max(value, end);
|
||||
|
||||
for (TNumber current = start; current < end; current++)
|
||||
{
|
||||
yield return current;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
namespace X10D.Linq;
|
||||
|
||||
/// <summary>
|
||||
/// LINQ-inspired extension methods for <see cref="IEnumerable{T}" /> of <see cref="float" />.
|
||||
/// </summary>
|
||||
public static class SingleExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Computes the product of a sequence of <see cref="float" /> values.
|
||||
/// </summary>
|
||||
/// <param name="source">A sequence of <see cref="float" /> values that are used to calculate the product.</param>
|
||||
/// <returns>The product the values in the sequence.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
|
||||
public static float Product(this IEnumerable<float> source)
|
||||
{
|
||||
if (source is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(source));
|
||||
}
|
||||
|
||||
return source.Aggregate(1f, (current, value) => (current * value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes the product of a sequence of <see cref="float" /> values that are obtained by invoking a transform function
|
||||
/// on each element of the input sequence.
|
||||
/// </summary>
|
||||
/// <param name="source">A sequence of values that are used to calculate a product.</param>
|
||||
/// <param name="selector">A transform function to apply to each element.</param>
|
||||
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
|
||||
/// <returns>The product of the projected values.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
|
||||
public static float Product<TSource>(this IEnumerable<TSource> source, Func<TSource, float> selector)
|
||||
{
|
||||
if (source is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(source));
|
||||
}
|
||||
|
||||
return source.Select(selector).Product();
|
||||
}
|
||||
}
|
@ -10,41 +10,6 @@ namespace X10D.Math;
|
||||
/// </summary>
|
||||
public static class BigIntegerExtensions
|
||||
{
|
||||
#if !NET7_0_OR_GREATER
|
||||
/// <summary>
|
||||
/// Returns the number of digits in the current integer.
|
||||
/// </summary>
|
||||
/// <param name="value">The value whose digit count to compute.</param>
|
||||
/// <returns>The number of digits in <paramref name="value" />.</returns>
|
||||
public static int CountDigits(this BigInteger value)
|
||||
{
|
||||
if (value == 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return (int)(1 + BigInteger.Log10(BigInteger.Abs(value)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes the digital root of this 8-bit integer.
|
||||
/// </summary>
|
||||
/// <param name="value">The value whose digital root to compute.</param>
|
||||
/// <returns>The digital root of <paramref name="value" />.</returns>
|
||||
/// <remarks>The digital root is defined as the recursive sum of digits until that result is a single digit.</remarks>
|
||||
/// <remarks>
|
||||
/// <para>The digital root is defined as the recursive sum of digits until that result is a single digit.</para>
|
||||
/// <para>For example, the digital root of 239 is 5: <c>2 + 3 + 9 = 14</c>, then <c>1 + 4 = 5</c>.</para>
|
||||
/// </remarks>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static int DigitalRoot(this BigInteger value)
|
||||
{
|
||||
BigInteger root = BigInteger.Abs(value).Mod(9);
|
||||
return (int)(root == 0 ? 9 : root);
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Returns the factorial of the current 64-bit signed integer.
|
||||
/// </summary>
|
||||
@ -74,24 +39,6 @@ public static class BigIntegerExtensions
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the greatest common factor between this, and another, <see cref="BigInteger" />.
|
||||
/// </summary>
|
||||
/// <param name="value">The first value.</param>
|
||||
/// <param name="other">The second value.</param>
|
||||
/// <returns>The greatest common factor between <paramref name="value" /> and <paramref name="other" />.</returns>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static BigInteger GreatestCommonFactor(this BigInteger value, BigInteger other)
|
||||
{
|
||||
while (other != 0)
|
||||
{
|
||||
(value, other) = (other, value % other);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a value indicating whether the current value is not evenly divisible by 2.
|
||||
/// </summary>
|
||||
@ -143,130 +90,4 @@ public static class BigIntegerExtensions
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the lowest common multiple between the current 64-bit signed integer, and another 64-bit signed integer.
|
||||
/// </summary>
|
||||
/// <param name="value">The first value.</param>
|
||||
/// <param name="other">The second value.</param>
|
||||
/// <returns>The lowest common multiple between <paramref name="value" /> and <paramref name="other" />.</returns>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static BigInteger LowestCommonMultiple(this BigInteger value, BigInteger other)
|
||||
{
|
||||
if (value == 0 || other == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (value == 1)
|
||||
{
|
||||
return other;
|
||||
}
|
||||
|
||||
if (other == 1)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
return value * other / value.GreatestCommonFactor(other);
|
||||
}
|
||||
|
||||
#if !NET7_0_OR_GREATER
|
||||
/// <summary>
|
||||
/// Performs a modulo operation which supports a negative dividend.
|
||||
/// </summary>
|
||||
/// <param name="dividend">The dividend.</param>
|
||||
/// <param name="divisor">The divisor.</param>
|
||||
/// <returns>The result of <c>dividend mod divisor</c>.</returns>
|
||||
/// <remarks>
|
||||
/// The <c>%</c> operator (commonly called the modulo operator) in C# is not defined to be modulo, but is instead
|
||||
/// remainder. This quirk inherently makes it difficult to use modulo in a negative context, as <c>x % y</c> where x is
|
||||
/// negative will return a negative value, akin to <c>-(x % y)</c>, even if precedence is forced. This method provides a
|
||||
/// modulo operation which supports negative dividends.
|
||||
/// </remarks>
|
||||
/// <author>ShreevatsaR, https://stackoverflow.com/a/1082938/1467293</author>
|
||||
/// <license>CC-BY-SA 2.5</license>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static BigInteger Mod(this BigInteger dividend, BigInteger divisor)
|
||||
{
|
||||
BigInteger r = dividend % divisor;
|
||||
return r < 0 ? r + divisor : r;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Returns the multiplicative persistence of a specified value.
|
||||
/// </summary>
|
||||
/// <param name="value">The value whose multiplicative persistence to calculate.</param>
|
||||
/// <returns>The multiplicative persistence.</returns>
|
||||
/// <remarks>
|
||||
/// Multiplicative persistence is defined as the recursive digital product until that product is a single digit.
|
||||
/// </remarks>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static int MultiplicativePersistence(this BigInteger value)
|
||||
{
|
||||
var persistence = 0;
|
||||
BigInteger product = BigInteger.Abs(value);
|
||||
|
||||
while (product > 9)
|
||||
{
|
||||
if (value % 10 == 0)
|
||||
{
|
||||
return persistence + 1;
|
||||
}
|
||||
|
||||
while (value > 9)
|
||||
{
|
||||
value /= 10;
|
||||
if (value % 10 == 0)
|
||||
{
|
||||
return persistence + 1;
|
||||
}
|
||||
}
|
||||
|
||||
BigInteger newProduct = 1;
|
||||
BigInteger currentProduct = product;
|
||||
while (currentProduct > 0)
|
||||
{
|
||||
newProduct *= currentProduct % 10;
|
||||
currentProduct /= 10;
|
||||
}
|
||||
|
||||
product = newProduct;
|
||||
persistence++;
|
||||
}
|
||||
|
||||
return persistence;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wraps the current integer between a low and a high value.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to wrap.</param>
|
||||
/// <param name="low">The inclusive lower bound.</param>
|
||||
/// <param name="high">The exclusive upper bound.</param>
|
||||
/// <returns>The wrapped value.</returns>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static BigInteger Wrap(this BigInteger value, BigInteger low, BigInteger high)
|
||||
{
|
||||
BigInteger difference = high - low;
|
||||
return low + (((value - low) % difference) + difference) % difference;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wraps the current integer between 0 and a high value.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to wrap.</param>
|
||||
/// <param name="length">The exclusive upper bound.</param>
|
||||
/// <returns>The wrapped value.</returns>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static BigInteger Wrap(this BigInteger value, BigInteger length)
|
||||
{
|
||||
return ((value % length) + length) % length;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
#if NET7_0_OR_GREATER
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
@ -70,7 +69,7 @@ public static class BinaryIntegerExtensions
|
||||
return 1;
|
||||
}
|
||||
|
||||
var result = 1L;
|
||||
long result = 1L;
|
||||
for (TInteger i = TInteger.One; i <= value; i++)
|
||||
{
|
||||
result *= long.CreateChecked(i);
|
||||
@ -80,22 +79,52 @@ public static class BinaryIntegerExtensions
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the greatest common factor between the current binary integer, and another binary integer.
|
||||
/// Returns the multiplicative persistence of the current integer.
|
||||
/// </summary>
|
||||
/// <param name="value">The first value.</param>
|
||||
/// <param name="other">The second value.</param>
|
||||
/// <returns>The greatest common factor between <paramref name="value" /> and <paramref name="other" />.</returns>
|
||||
/// <param name="value">The value whose multiplicative persistence to calculate.</param>
|
||||
/// <returns>The multiplicative persistence.</returns>
|
||||
/// <remarks>
|
||||
/// Multiplicative persistence is defined as the recursive digital product until that product is a single digit.
|
||||
/// </remarks>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static TInteger GreatestCommonFactor<TInteger>(this TInteger value, TInteger other)
|
||||
public static int MultiplicativePersistence<TInteger>(this TInteger value)
|
||||
where TInteger : IBinaryInteger<TInteger>
|
||||
{
|
||||
while (other != TInteger.Zero)
|
||||
var nine = TInteger.CreateChecked(9);
|
||||
var ten = TInteger.CreateChecked(10);
|
||||
|
||||
var persistence = 0;
|
||||
TInteger product = TInteger.Abs(value);
|
||||
|
||||
while (product > nine)
|
||||
{
|
||||
(value, other) = (other, value % other);
|
||||
if (value % ten == TInteger.Zero)
|
||||
{
|
||||
return persistence + 1;
|
||||
}
|
||||
|
||||
while (value > nine)
|
||||
{
|
||||
value /= ten;
|
||||
if (value % ten == TInteger.Zero)
|
||||
{
|
||||
return persistence + 1;
|
||||
}
|
||||
}
|
||||
|
||||
TInteger newProduct = TInteger.One;
|
||||
TInteger currentProduct = product;
|
||||
while (currentProduct > TInteger.Zero)
|
||||
{
|
||||
newProduct *= currentProduct % ten;
|
||||
currentProduct /= ten;
|
||||
}
|
||||
|
||||
product = newProduct;
|
||||
persistence++;
|
||||
}
|
||||
|
||||
return value;
|
||||
return persistence;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -1,6 +1,4 @@
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Runtime.CompilerServices;
|
||||
using X10D.CompilerServices;
|
||||
|
||||
namespace X10D.Math;
|
||||
|
||||
@ -9,107 +7,6 @@ namespace X10D.Math;
|
||||
/// </summary>
|
||||
public static class ByteExtensions
|
||||
{
|
||||
#if !NET7_0_OR_GREATER
|
||||
/// <summary>
|
||||
/// Returns the number of digits in the current 8-bit unsigned integer.
|
||||
/// </summary>
|
||||
/// <param name="value">The value whose digit count to compute.</param>
|
||||
/// <returns>The number of digits in <paramref name="value" />.</returns>
|
||||
public static int CountDigits(this byte value)
|
||||
{
|
||||
if (value == 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return ((ulong)value).CountDigits();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes the digital root of this 8-bit integer.
|
||||
/// </summary>
|
||||
/// <param name="value">The value whose digital root to compute.</param>
|
||||
/// <returns>The digital root of <paramref name="value" />.</returns>
|
||||
/// <remarks>The digital root is defined as the recursive sum of digits until that result is a single digit.</remarks>
|
||||
/// <remarks>
|
||||
/// <para>The digital root is defined as the recursive sum of digits until that result is a single digit.</para>
|
||||
/// <para>For example, the digital root of 239 is 5: <c>2 + 3 + 9 = 14</c>, then <c>1 + 4 = 5</c>.</para>
|
||||
/// </remarks>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static byte DigitalRoot(this byte value)
|
||||
{
|
||||
int root = value % 9;
|
||||
return (byte)(root == 0 ? 9 : root);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the factorial of the current 8-bit unsigned integer.
|
||||
/// </summary>
|
||||
/// <param name="value">The value whose factorial to compute.</param>
|
||||
/// <returns>The factorial of <paramref name="value" />.</returns>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static long Factorial(this byte value)
|
||||
{
|
||||
if (value == 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
var result = 1L;
|
||||
for (byte i = 1; i <= value; i++)
|
||||
{
|
||||
result *= i;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the greatest common factor between the current 8-bit unsigned integer, and another 8-bit unsigned integer.
|
||||
/// </summary>
|
||||
/// <param name="value">The first value.</param>
|
||||
/// <param name="other">The second value.</param>
|
||||
/// <returns>The greatest common factor between <paramref name="value" /> and <paramref name="other" />.</returns>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static byte GreatestCommonFactor(this byte value, byte other)
|
||||
{
|
||||
return (byte)((long)value).GreatestCommonFactor(other);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a value indicating whether the current value is evenly divisible by 2.
|
||||
/// </summary>
|
||||
/// <param name="value">The value whose parity to check.</param>
|
||||
/// <returns>
|
||||
/// <see langword="true" /> if <paramref name="value" /> is evenly divisible by 2, or <see langword="false" />
|
||||
/// otherwise.
|
||||
/// </returns>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static bool IsEven(this byte value)
|
||||
{
|
||||
return (value & 1) == 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a value indicating whether the current value is not evenly divisible by 2.
|
||||
/// </summary>
|
||||
/// <param name="value">The value whose parity to check.</param>
|
||||
/// <returns>
|
||||
/// <see langword="true" /> if <paramref name="value" /> is not evenly divisible by 2, or <see langword="false" />
|
||||
/// otherwise.
|
||||
/// </returns>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static bool IsOdd(this byte value)
|
||||
{
|
||||
return !value.IsEven();
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Returns a value indicating whether the current value is a prime number.
|
||||
/// </summary>
|
||||
@ -122,59 +19,4 @@ public static class ByteExtensions
|
||||
{
|
||||
return ((long)value).IsPrime();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the lowest common multiple between the current 8-bit signed integer, and another 8-bit signed integer.
|
||||
/// </summary>
|
||||
/// <param name="value">The first value.</param>
|
||||
/// <param name="other">The second value.</param>
|
||||
/// <returns>The lowest common multiple between <paramref name="value" /> and <paramref name="other" />.</returns>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static byte LowestCommonMultiple(this byte value, byte other)
|
||||
{
|
||||
return (byte)((long)value).LowestCommonMultiple(other);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the multiplicative persistence of a specified value.
|
||||
/// </summary>
|
||||
/// <param name="value">The value whose multiplicative persistence to calculate.</param>
|
||||
/// <returns>The multiplicative persistence.</returns>
|
||||
/// <remarks>
|
||||
/// Multiplicative persistence is defined as the recursive digital product until that product is a single digit.
|
||||
/// </remarks>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static int MultiplicativePersistence(this byte value)
|
||||
{
|
||||
return ((long)value).MultiplicativePersistence();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wraps the current 8-bit unsigned integer between a low and a high value.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to wrap.</param>
|
||||
/// <param name="low">The inclusive lower bound.</param>
|
||||
/// <param name="high">The exclusive upper bound.</param>
|
||||
/// <returns>The wrapped value.</returns>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static byte Wrap(this byte value, byte low, byte high)
|
||||
{
|
||||
return (byte)((ulong)value).Wrap(low, high);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wraps the current 8-bit unsigned integer between 0 and a high value.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to wrap.</param>
|
||||
/// <param name="length">The exclusive upper bound.</param>
|
||||
/// <returns>The wrapped value.</returns>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static byte Wrap(this byte value, byte length)
|
||||
{
|
||||
return (byte)((ulong)value).Wrap(length);
|
||||
}
|
||||
}
|
||||
|
@ -77,53 +77,6 @@ public static class DecimalExtensions
|
||||
return System.Math.Round(value / nearest) * nearest;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saturates this decimal number.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to saturate.</param>
|
||||
/// <returns>The saturated value.</returns>
|
||||
/// <remarks>This method clamps <paramref name="value" /> between 0 and 1.</remarks>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static decimal Saturate(this decimal value)
|
||||
{
|
||||
return System.Math.Clamp(value, 0.0m, 1.0m);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an integer that indicates the sign of this decimal number.
|
||||
/// </summary>
|
||||
/// <param name="value">A signed number.</param>
|
||||
/// <returns>
|
||||
/// A number that indicates the sign of <paramref name="value" />, as shown in the following table.
|
||||
///
|
||||
/// <list type="table">
|
||||
/// <listheader>
|
||||
/// <term>Return value</term>
|
||||
/// <description>Meaning</description>
|
||||
/// </listheader>
|
||||
///
|
||||
/// <item>
|
||||
/// <term>-1</term>
|
||||
/// <description><paramref name="value" /> is less than zero.</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>0</term>
|
||||
/// <description><paramref name="value" /> is equal to zero.</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>1</term>
|
||||
/// <description><paramref name="value" /> is greater than zero.</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </returns>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static int Sign(this decimal value)
|
||||
{
|
||||
return System.Math.Sign(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the square root of this decimal number.
|
||||
/// </summary>
|
||||
@ -174,32 +127,4 @@ public static class DecimalExtensions
|
||||
|
||||
return current;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wraps the current decimal number between a low and a high value.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to wrap.</param>
|
||||
/// <param name="low">The inclusive lower bound.</param>
|
||||
/// <param name="high">The exclusive upper bound.</param>
|
||||
/// <returns>The wrapped value.</returns>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static decimal Wrap(this decimal value, decimal low, decimal high)
|
||||
{
|
||||
decimal difference = high - low;
|
||||
return low + (((value - low) % difference) + difference) % difference;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wraps the current decimal number between 0 and a high value.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to wrap.</param>
|
||||
/// <param name="length">The exclusive upper bound.</param>
|
||||
/// <returns>The wrapped value.</returns>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static decimal Wrap(this decimal value, decimal length)
|
||||
{
|
||||
return ((value % length) + length) % length;
|
||||
}
|
||||
}
|
||||
|
@ -255,19 +255,6 @@ public static class DoubleExtensions
|
||||
return System.Math.Round(value / nearest) * nearest;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saturates this double-precision floating-point number.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to saturate.</param>
|
||||
/// <returns>The saturated value.</returns>
|
||||
/// <remarks>This method clamps <paramref name="value" /> between 0 and 1.</remarks>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static double Saturate(this double value)
|
||||
{
|
||||
return System.Math.Clamp(value, 0.0, 1.0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the sine of the specified angle.
|
||||
/// </summary>
|
||||
@ -300,41 +287,6 @@ public static class DoubleExtensions
|
||||
return System.Math.Sinh(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an integer that indicates the sign of this double-precision floating-point number.
|
||||
/// </summary>
|
||||
/// <param name="value">A signed number.</param>
|
||||
/// <returns>
|
||||
/// A number that indicates the sign of <paramref name="value" />, as shown in the following table.
|
||||
///
|
||||
/// <list type="table">
|
||||
/// <listheader>
|
||||
/// <term>Return value</term>
|
||||
/// <description>Meaning</description>
|
||||
/// </listheader>
|
||||
///
|
||||
/// <item>
|
||||
/// <term>-1</term>
|
||||
/// <description><paramref name="value" /> is less than zero.</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>0</term>
|
||||
/// <description><paramref name="value" /> is equal to zero.</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>1</term>
|
||||
/// <description><paramref name="value" /> is greater than zero.</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </returns>
|
||||
/// <exception cref="ArithmeticException"><paramref name="value" /> is equal to <see cref="double.NaN" />.</exception>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static int Sign(this double value)
|
||||
{
|
||||
return System.Math.Sign(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the square root of this double-precision floating-point number.
|
||||
/// </summary>
|
||||
@ -421,32 +373,4 @@ public static class DoubleExtensions
|
||||
{
|
||||
return System.Math.Tanh(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wraps the current double-precision floating-point number between a low and a high value.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to wrap.</param>
|
||||
/// <param name="low">The inclusive lower bound.</param>
|
||||
/// <param name="high">The exclusive upper bound.</param>
|
||||
/// <returns>The wrapped value.</returns>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static double Wrap(this double value, double low, double high)
|
||||
{
|
||||
double difference = high - low;
|
||||
return low + (((value - low) % difference) + difference) % difference;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wraps the current double-precision floating-point number between 0 and a high value.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to wrap.</param>
|
||||
/// <param name="length">The exclusive upper bound.</param>
|
||||
/// <returns>The wrapped value.</returns>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static double Wrap(this double value, double length)
|
||||
{
|
||||
return ((value % length) + length) % length;
|
||||
}
|
||||
}
|
||||
|
@ -9,112 +9,6 @@ namespace X10D.Math;
|
||||
/// </summary>
|
||||
public static class Int16Extensions
|
||||
{
|
||||
#if !NET7_0_OR_GREATER
|
||||
/// <summary>
|
||||
/// Returns the number of digits in the current 16-bit signed integer.
|
||||
/// </summary>
|
||||
/// <param name="value">The value whose digit count to compute.</param>
|
||||
/// <returns>The number of digits in <paramref name="value" />.</returns>
|
||||
public static int CountDigits(this short value)
|
||||
{
|
||||
if (value == 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return ((long)value).CountDigits();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes the digital root of this 16-bit integer.
|
||||
/// </summary>
|
||||
/// <param name="value">The value whose digital root to compute.</param>
|
||||
/// <returns>The digital root of <paramref name="value" />.</returns>
|
||||
/// <remarks>
|
||||
/// <para>The digital root is defined as the recursive sum of digits until that result is a single digit.</para>
|
||||
/// <para>For example, the digital root of 239 is 5: <c>2 + 3 + 9 = 14</c>, then <c>1 + 4 = 5</c>.</para>
|
||||
/// </remarks>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static short DigitalRoot(this short value)
|
||||
{
|
||||
short root = System.Math.Abs(value).Mod(9);
|
||||
return root < 1 ? (short)(9 - root) : root;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the factorial of the current 16-bit signed integer.
|
||||
/// </summary>
|
||||
/// <param name="value">The value whose factorial to compute.</param>
|
||||
/// <returns>The factorial of <paramref name="value" />.</returns>
|
||||
/// <exception cref="ArithmeticException"><paramref name="value" /> is less than 0.</exception>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static long Factorial(this short value)
|
||||
{
|
||||
if (value < 0)
|
||||
{
|
||||
throw new ArithmeticException(nameof(value));
|
||||
}
|
||||
|
||||
if (value == 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
var result = 1L;
|
||||
for (short i = 1; i <= value; i++)
|
||||
{
|
||||
result *= i;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the greatest common factor between the current 16-bit signed integer, and another 16-bit signed integer.
|
||||
/// </summary>
|
||||
/// <param name="value">The first value.</param>
|
||||
/// <param name="other">The second value.</param>
|
||||
/// <returns>The greatest common factor between <paramref name="value" /> and <paramref name="other" />.</returns>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static short GreatestCommonFactor(this short value, short other)
|
||||
{
|
||||
return (short)((long)value).GreatestCommonFactor(other);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a value indicating whether the current value is evenly divisible by 2.
|
||||
/// </summary>
|
||||
/// <param name="value">The value whose parity to check.</param>
|
||||
/// <returns>
|
||||
/// <see langword="true" /> if <paramref name="value" /> is evenly divisible by 2, or <see langword="false" />
|
||||
/// otherwise.
|
||||
/// </returns>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static bool IsEven(this short value)
|
||||
{
|
||||
return (value & 1) == 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a value indicating whether the current value is not evenly divisible by 2.
|
||||
/// </summary>
|
||||
/// <param name="value">The value whose parity to check.</param>
|
||||
/// <returns>
|
||||
/// <see langword="true" /> if <paramref name="value" /> is not evenly divisible by 2, or <see langword="false" />
|
||||
/// otherwise.
|
||||
/// </returns>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static bool IsOdd(this short value)
|
||||
{
|
||||
return !value.IsEven();
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Returns a value indicating whether the current value is a prime number.
|
||||
/// </summary>
|
||||
@ -128,117 +22,4 @@ public static class Int16Extensions
|
||||
{
|
||||
return ((long)value).IsPrime();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the lowest common multiple between the current 16-bit signed integer, and another 16-bit signed integer.
|
||||
/// </summary>
|
||||
/// <param name="value">The first value.</param>
|
||||
/// <param name="other">The second value.</param>
|
||||
/// <returns>The lowest common multiple between <paramref name="value" /> and <paramref name="other" />.</returns>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static short LowestCommonMultiple(this short value, short other)
|
||||
{
|
||||
return (short)((long)value).LowestCommonMultiple(other);
|
||||
}
|
||||
|
||||
#if !NET7_0_OR_GREATER
|
||||
/// <summary>
|
||||
/// Performs a modulo operation which supports a negative dividend.
|
||||
/// </summary>
|
||||
/// <param name="dividend">The dividend.</param>
|
||||
/// <param name="divisor">The divisor.</param>
|
||||
/// <returns>The result of <c>dividend mod divisor</c>.</returns>
|
||||
/// <remarks>
|
||||
/// The <c>%</c> operator (commonly called the modulo operator) in C# is not defined to be modulo, but is instead
|
||||
/// remainder. This quirk inherently makes it difficult to use modulo in a negative context, as <c>x % y</c> where x is
|
||||
/// negative will return a negative value, akin to <c>-(x % y)</c>, even if precedence is forced. This method provides a
|
||||
/// modulo operation which supports negative dividends.
|
||||
/// </remarks>
|
||||
/// <author>ShreevatsaR, https://stackoverflow.com/a/1082938/1467293</author>
|
||||
/// <license>CC-BY-SA 2.5</license>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static short Mod(this short dividend, short divisor)
|
||||
{
|
||||
int r = dividend % divisor;
|
||||
return (short)(r < 0 ? r + divisor : r);
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Returns the multiplicative persistence of a specified value.
|
||||
/// </summary>
|
||||
/// <param name="value">The value whose multiplicative persistence to calculate.</param>
|
||||
/// <returns>The multiplicative persistence.</returns>
|
||||
/// <remarks>
|
||||
/// Multiplicative persistence is defined as the recursive digital product until that product is a single digit.
|
||||
/// </remarks>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static int MultiplicativePersistence(this short value)
|
||||
{
|
||||
return ((long)value).MultiplicativePersistence();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an integer that indicates the sign of this 16-bit signed integer.
|
||||
/// </summary>
|
||||
/// <param name="value">A signed number.</param>
|
||||
/// <returns>
|
||||
/// A number that indicates the sign of <paramref name="value" />, as shown in the following table.
|
||||
///
|
||||
/// <list type="table">
|
||||
/// <listheader>
|
||||
/// <term>Return value</term>
|
||||
/// <description>Meaning</description>
|
||||
/// </listheader>
|
||||
///
|
||||
/// <item>
|
||||
/// <term>-1</term>
|
||||
/// <description><paramref name="value" /> is less than zero.</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>0</term>
|
||||
/// <description><paramref name="value" /> is equal to zero.</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>1</term>
|
||||
/// <description><paramref name="value" /> is greater than zero.</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </returns>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static int Sign(this short value)
|
||||
{
|
||||
return System.Math.Sign(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wraps the current 16-bit signed integer between a low and a high value.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to wrap.</param>
|
||||
/// <param name="low">The inclusive lower bound.</param>
|
||||
/// <param name="high">The exclusive upper bound.</param>
|
||||
/// <returns>The wrapped value.</returns>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static short Wrap(this short value, short low, short high)
|
||||
{
|
||||
return (short)((long)value).Wrap(low, high);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wraps the current 16-bit signed integer between 0 and a high value.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to wrap.</param>
|
||||
/// <param name="length">The exclusive upper bound.</param>
|
||||
/// <returns>The wrapped value.</returns>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static short Wrap(this short value, short length)
|
||||
{
|
||||
return (short)((long)value).Wrap(length);
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user