From 75ad708116922464360381fa8f39af61b87b18e4 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Tue, 12 Nov 2024 17:22:43 +0000 Subject: [PATCH 01/27] chore!: remove net6.0 target (#92) --- X10D.Hosting/X10D.Hosting.csproj | 2 +- X10D.Tests/X10D.Tests.csproj | 2 +- X10D/X10D.csproj | 2 +- tools/Benchmarks/Benchmarks.csproj | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/X10D.Hosting/X10D.Hosting.csproj b/X10D.Hosting/X10D.Hosting.csproj index cc93b63..74d07d3 100644 --- a/X10D.Hosting/X10D.Hosting.csproj +++ b/X10D.Hosting/X10D.Hosting.csproj @@ -1,7 +1,7 @@ - net8.0;net6.0 + net8.0 diff --git a/X10D.Tests/X10D.Tests.csproj b/X10D.Tests/X10D.Tests.csproj index 9ac986d..74bdbc1 100644 --- a/X10D.Tests/X10D.Tests.csproj +++ b/X10D.Tests/X10D.Tests.csproj @@ -1,7 +1,7 @@ - net8.0;net6.0 + net8.0 false true xml,cobertura diff --git a/X10D/X10D.csproj b/X10D/X10D.csproj index 592e773..3961f95 100644 --- a/X10D/X10D.csproj +++ b/X10D/X10D.csproj @@ -1,7 +1,7 @@ - net8.0;net6.0 + net8.0 diff --git a/tools/Benchmarks/Benchmarks.csproj b/tools/Benchmarks/Benchmarks.csproj index 197c37b..09df3b4 100644 --- a/tools/Benchmarks/Benchmarks.csproj +++ b/tools/Benchmarks/Benchmarks.csproj @@ -1,7 +1,7 @@ - net8.0;net6.0 + net8.0 Release Exe true From 7f1a1dbead091f76fdda83a32659d42a84cf08c1 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Tue, 12 Nov 2024 17:25:40 +0000 Subject: [PATCH 02/27] refactor!: remove NET7_0_OR_GREATER conditionals (#92) --- .../Collections/BinaryIntegerExtensions.cs | 2 - X10D/src/Collections/ByteExtensions.cs | 44 ----- X10D/src/Collections/Int16Extensions.cs | 44 ----- X10D/src/Collections/Int32Extensions.cs | 50 ------ X10D/src/Collections/Int64Extensions.cs | 45 ----- X10D/src/Core/IntrinsicExtensions.cs | 5 - X10D/src/Core/SpanExtensions.cs | 9 +- X10D/src/Math/BigIntegerExtensions.cs | 59 ------- X10D/src/Math/BinaryIntegerExtensions.cs | 2 - X10D/src/Math/ByteExtensions.cs | 101 ------------ X10D/src/Math/Int16Extensions.cs | 130 --------------- X10D/src/Math/Int32Extensions.cs | 130 --------------- X10D/src/Math/Int64Extensions.cs | 135 --------------- X10D/src/Math/MathUtility.cs | 154 ------------------ X10D/src/Math/NumberExtensions.cs | 2 - X10D/src/Math/SByteExtensions.cs | 130 --------------- X10D/src/Math/UInt16Extensions.cs | 101 ------------ X10D/src/Math/UInt32Extensions.cs | 101 ------------ X10D/src/Math/UInt64Extensions.cs | 106 ------------ X10D/src/Text/CharExtensions.cs | 4 - X10D/src/Text/RuneExtensions.cs | 4 - 21 files changed, 1 insertion(+), 1357 deletions(-) delete mode 100644 X10D/src/Collections/Int64Extensions.cs diff --git a/X10D/src/Collections/BinaryIntegerExtensions.cs b/X10D/src/Collections/BinaryIntegerExtensions.cs index 0aec0d0..5edba34 100644 --- a/X10D/src/Collections/BinaryIntegerExtensions.cs +++ b/X10D/src/Collections/BinaryIntegerExtensions.cs @@ -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 diff --git a/X10D/src/Collections/ByteExtensions.cs b/X10D/src/Collections/ByteExtensions.cs index bdcdcce..5498209 100644 --- a/X10D/src/Collections/ByteExtensions.cs +++ b/X10D/src/Collections/ByteExtensions.cs @@ -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 - /// - /// Unpacks this 8-bit unsigned integer into a boolean list, treating it as a bit field. - /// - /// The value to unpack. - /// An array of with length 8. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool[] Unpack(this byte value) - { - var buffer = new bool[Size]; - value.Unpack(buffer); - return buffer; - } - - /// - /// Unpacks this 8-bit unsigned integer into a boolean list, treating it as a bit field. - /// - /// The value to unpack. - /// When this method returns, contains the unpacked booleans from . - /// is not large enough to contain the result. - [ExcludeFromCodeCoverage] - [MethodImpl(CompilerResources.MaxOptimization)] - public static void Unpack(this byte value, Span 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 destination) { diff --git a/X10D/src/Collections/Int16Extensions.cs b/X10D/src/Collections/Int16Extensions.cs index e3e5570..b744413 100644 --- a/X10D/src/Collections/Int16Extensions.cs +++ b/X10D/src/Collections/Int16Extensions.cs @@ -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 - /// - /// Unpacks this 16-bit signed integer into a boolean list, treating it as a bit field. - /// - /// The value to unpack. - /// An array of with length 16. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool[] Unpack(this short value) - { - var ret = new bool[Size]; - value.Unpack(ret); - return ret; - } - - /// - /// Unpacks this 16-bit signed integer into a boolean list, treating it as a bit field. - /// - /// The value to unpack. - /// When this method returns, contains the unpacked booleans from . - /// is not large enough to contain the result. - [ExcludeFromCodeCoverage] - [MethodImpl(CompilerResources.MaxOptimization)] - public static void Unpack(this short value, Span 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 destination) { diff --git a/X10D/src/Collections/Int32Extensions.cs b/X10D/src/Collections/Int32Extensions.cs index b74a311..1386541 100644 --- a/X10D/src/Collections/Int32Extensions.cs +++ b/X10D/src/Collections/Int32Extensions.cs @@ -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 - /// - /// Unpacks this 32-bit signed integer into a boolean list, treating it as a bit field. - /// - /// The value to unpack. - /// An array of with length 32. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool[] Unpack(this int value) - { - var ret = new bool[Size]; - value.Unpack(ret); - return ret; - } - - /// - /// Unpacks this 32-bit signed integer into a boolean list, treating it as a bit field. - /// - /// The value to unpack. - /// When this method returns, contains the unpacked booleans from . - /// is not large enough to contain the result. - [ExcludeFromCodeCoverage] - [MethodImpl(CompilerResources.MaxOptimization)] - public static void Unpack(this int value, Span 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 destination) { diff --git a/X10D/src/Collections/Int64Extensions.cs b/X10D/src/Collections/Int64Extensions.cs deleted file mode 100644 index c72dfbd..0000000 --- a/X10D/src/Collections/Int64Extensions.cs +++ /dev/null @@ -1,45 +0,0 @@ -#if !NET7_0_OR_GREATER -using System.Diagnostics.Contracts; - -namespace X10D.Collections; - -/// -/// Collection-related extension methods for . -/// -public static class Int64Extensions -{ - private const int Size = sizeof(long) * 8; - - /// - /// Unpacks this 64-bit signed integer into a boolean list, treating it as a bit field. - /// - /// The value to unpack. - /// An array of with length 64. - [Pure] - public static bool[] Unpack(this long value) - { - var ret = new bool[Size]; - value.Unpack(ret); - return ret; - } - - /// - /// Unpacks this 64-bit signed integer into a boolean list, treating it as a bit field. - /// - /// The value to unpack. - /// When this method returns, contains the unpacked booleans from . - /// is not large enough to contain the result. - public static void Unpack(this long value, Span 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 diff --git a/X10D/src/Core/IntrinsicExtensions.cs b/X10D/src/Core/IntrinsicExtensions.cs index 7a98d64..1e2fc9d 100644 --- a/X10D/src/Core/IntrinsicExtensions.cs +++ b/X10D/src/Core/IntrinsicExtensions.cs @@ -37,12 +37,7 @@ public static class IntrinsicExtensions for (var i = 0; i < Vector64.Count; i++) { ref byte writeElement = ref Unsafe.Add(ref Unsafe.As, 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, byte>(ref vector), i); - writeElement = element == 0 ? (byte)0 : (byte)1; -#endif } return output; diff --git a/X10D/src/Core/SpanExtensions.cs b/X10D/src/Core/SpanExtensions.cs index ab79a16..beb4c92 100644 --- a/X10D/src/Core/SpanExtensions.cs +++ b/X10D/src/Core/SpanExtensions.cs @@ -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; /// @@ -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())); -#else - throw new ArgumentException(string.Format(ExceptionMessages.EnumSizeIsUnexpected, Unsafe.SizeOf())); -#endif // dotcover enable } } diff --git a/X10D/src/Math/BigIntegerExtensions.cs b/X10D/src/Math/BigIntegerExtensions.cs index 79c936c..da72697 100644 --- a/X10D/src/Math/BigIntegerExtensions.cs +++ b/X10D/src/Math/BigIntegerExtensions.cs @@ -10,41 +10,6 @@ namespace X10D.Math; /// public static class BigIntegerExtensions { -#if !NET7_0_OR_GREATER - /// - /// Returns the number of digits in the current integer. - /// - /// The value whose digit count to compute. - /// The number of digits in . - public static int CountDigits(this BigInteger value) - { - if (value == 0) - { - return 1; - } - - return (int)(1 + BigInteger.Log10(BigInteger.Abs(value))); - } - - /// - /// Computes the digital root of this 8-bit integer. - /// - /// The value whose digital root to compute. - /// The digital root of . - /// The digital root is defined as the recursive sum of digits until that result is a single digit. - /// - /// The digital root is defined as the recursive sum of digits until that result is a single digit. - /// For example, the digital root of 239 is 5: 2 + 3 + 9 = 14, then 1 + 4 = 5. - /// - [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 - /// /// Returns the factorial of the current 64-bit signed integer. /// @@ -172,30 +137,6 @@ public static class BigIntegerExtensions return value * other / value.GreatestCommonFactor(other); } -#if !NET7_0_OR_GREATER - /// - /// Performs a modulo operation which supports a negative dividend. - /// - /// The dividend. - /// The divisor. - /// The result of dividend mod divisor. - /// - /// The % 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 x % y where x is - /// negative will return a negative value, akin to -(x % y), even if precedence is forced. This method provides a - /// modulo operation which supports negative dividends. - /// - /// ShreevatsaR, https://stackoverflow.com/a/1082938/1467293 - /// CC-BY-SA 2.5 - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static BigInteger Mod(this BigInteger dividend, BigInteger divisor) - { - BigInteger r = dividend % divisor; - return r < 0 ? r + divisor : r; - } -#endif - /// /// Returns the multiplicative persistence of a specified value. /// diff --git a/X10D/src/Math/BinaryIntegerExtensions.cs b/X10D/src/Math/BinaryIntegerExtensions.cs index ce10a7e..2d09419 100644 --- a/X10D/src/Math/BinaryIntegerExtensions.cs +++ b/X10D/src/Math/BinaryIntegerExtensions.cs @@ -1,4 +1,3 @@ -#if NET7_0_OR_GREATER using System.Diagnostics.Contracts; using System.Numerics; using System.Runtime.CompilerServices; @@ -98,4 +97,3 @@ public static class BinaryIntegerExtensions return value; } } -#endif diff --git a/X10D/src/Math/ByteExtensions.cs b/X10D/src/Math/ByteExtensions.cs index 0bd8486..5f6d77a 100644 --- a/X10D/src/Math/ByteExtensions.cs +++ b/X10D/src/Math/ByteExtensions.cs @@ -9,107 +9,6 @@ namespace X10D.Math; /// public static class ByteExtensions { -#if !NET7_0_OR_GREATER - /// - /// Returns the number of digits in the current 8-bit unsigned integer. - /// - /// The value whose digit count to compute. - /// The number of digits in . - public static int CountDigits(this byte value) - { - if (value == 0) - { - return 1; - } - - return ((ulong)value).CountDigits(); - } - - /// - /// Computes the digital root of this 8-bit integer. - /// - /// The value whose digital root to compute. - /// The digital root of . - /// The digital root is defined as the recursive sum of digits until that result is a single digit. - /// - /// The digital root is defined as the recursive sum of digits until that result is a single digit. - /// For example, the digital root of 239 is 5: 2 + 3 + 9 = 14, then 1 + 4 = 5. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static byte DigitalRoot(this byte value) - { - int root = value % 9; - return (byte)(root == 0 ? 9 : root); - } - - /// - /// Returns the factorial of the current 8-bit unsigned integer. - /// - /// The value whose factorial to compute. - /// The factorial of . - [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; - } - - /// - /// Calculates the greatest common factor between the current 8-bit unsigned integer, and another 8-bit unsigned integer. - /// - /// The first value. - /// The second value. - /// The greatest common factor between and . - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static byte GreatestCommonFactor(this byte value, byte other) - { - return (byte)((long)value).GreatestCommonFactor(other); - } - - /// - /// Returns a value indicating whether the current value is evenly divisible by 2. - /// - /// The value whose parity to check. - /// - /// if is evenly divisible by 2, or - /// otherwise. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool IsEven(this byte value) - { - return (value & 1) == 0; - } - - /// - /// Returns a value indicating whether the current value is not evenly divisible by 2. - /// - /// The value whose parity to check. - /// - /// if is not evenly divisible by 2, or - /// otherwise. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool IsOdd(this byte value) - { - return !value.IsEven(); - } -#endif - /// /// Returns a value indicating whether the current value is a prime number. /// diff --git a/X10D/src/Math/Int16Extensions.cs b/X10D/src/Math/Int16Extensions.cs index 318a948..a331a46 100644 --- a/X10D/src/Math/Int16Extensions.cs +++ b/X10D/src/Math/Int16Extensions.cs @@ -9,112 +9,6 @@ namespace X10D.Math; /// public static class Int16Extensions { -#if !NET7_0_OR_GREATER - /// - /// Returns the number of digits in the current 16-bit signed integer. - /// - /// The value whose digit count to compute. - /// The number of digits in . - public static int CountDigits(this short value) - { - if (value == 0) - { - return 1; - } - - return ((long)value).CountDigits(); - } - - /// - /// Computes the digital root of this 16-bit integer. - /// - /// The value whose digital root to compute. - /// The digital root of . - /// - /// The digital root is defined as the recursive sum of digits until that result is a single digit. - /// For example, the digital root of 239 is 5: 2 + 3 + 9 = 14, then 1 + 4 = 5. - /// - [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; - } - - /// - /// Returns the factorial of the current 16-bit signed integer. - /// - /// The value whose factorial to compute. - /// The factorial of . - /// is less than 0. - [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; - } - - /// - /// Calculates the greatest common factor between the current 16-bit signed integer, and another 16-bit signed integer. - /// - /// The first value. - /// The second value. - /// The greatest common factor between and . - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static short GreatestCommonFactor(this short value, short other) - { - return (short)((long)value).GreatestCommonFactor(other); - } - - /// - /// Returns a value indicating whether the current value is evenly divisible by 2. - /// - /// The value whose parity to check. - /// - /// if is evenly divisible by 2, or - /// otherwise. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool IsEven(this short value) - { - return (value & 1) == 0; - } - - /// - /// Returns a value indicating whether the current value is not evenly divisible by 2. - /// - /// The value whose parity to check. - /// - /// if is not evenly divisible by 2, or - /// otherwise. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool IsOdd(this short value) - { - return !value.IsEven(); - } -#endif - /// /// Returns a value indicating whether the current value is a prime number. /// @@ -142,30 +36,6 @@ public static class Int16Extensions return (short)((long)value).LowestCommonMultiple(other); } -#if !NET7_0_OR_GREATER - /// - /// Performs a modulo operation which supports a negative dividend. - /// - /// The dividend. - /// The divisor. - /// The result of dividend mod divisor. - /// - /// The % 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 x % y where x is - /// negative will return a negative value, akin to -(x % y), even if precedence is forced. This method provides a - /// modulo operation which supports negative dividends. - /// - /// ShreevatsaR, https://stackoverflow.com/a/1082938/1467293 - /// CC-BY-SA 2.5 - [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 - /// /// Returns the multiplicative persistence of a specified value. /// diff --git a/X10D/src/Math/Int32Extensions.cs b/X10D/src/Math/Int32Extensions.cs index e0b05cc..c9eb23f 100644 --- a/X10D/src/Math/Int32Extensions.cs +++ b/X10D/src/Math/Int32Extensions.cs @@ -9,112 +9,6 @@ namespace X10D.Math; /// public static class Int32Extensions { -#if !NET7_0_OR_GREATER - /// - /// Returns the number of digits in the current 32-bit signed integer. - /// - /// The value whose digit count to compute. - /// The number of digits in . - public static int CountDigits(this int value) - { - if (value == 0) - { - return 1; - } - - return ((long)value).CountDigits(); - } - - /// - /// Computes the digital root of this 32-bit integer. - /// - /// The value whose digital root to compute. - /// The digital root of . - /// - /// The digital root is defined as the recursive sum of digits until that result is a single digit. - /// For example, the digital root of 239 is 5: 2 + 3 + 9 = 14, then 1 + 4 = 5. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static int DigitalRoot(this int value) - { - int root = System.Math.Abs(value).Mod(9); - return root < 1 ? 9 - root : root; - } - - /// - /// Returns the factorial of the current 32-bit signed integer. - /// - /// The value whose factorial to compute. - /// The factorial of . - /// is less than 0. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static long Factorial(this int value) - { - if (value < 0) - { - throw new ArithmeticException(nameof(value)); - } - - if (value == 0) - { - return 1; - } - - var result = 1L; - for (var i = 1; i <= value; i++) - { - result *= i; - } - - return result; - } - - /// - /// Calculates the greatest common factor between the current 32-bit signed integer, and another 32-bit signed integer. - /// - /// The first value. - /// The second value. - /// The greatest common factor between and . - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static int GreatestCommonFactor(this int value, int other) - { - return (int)((long)value).GreatestCommonFactor(other); - } - - /// - /// Returns a value indicating whether the current value is evenly divisible by 2. - /// - /// The value whose parity to check. - /// - /// if is evenly divisible by 2, or - /// otherwise. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool IsEven(this int value) - { - return (value & 1) == 0; - } - - /// - /// Returns a value indicating whether the current value is not evenly divisible by 2. - /// - /// The value whose parity to check. - /// - /// if is not evenly divisible by 2, or - /// otherwise. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool IsOdd(this int value) - { - return !value.IsEven(); - } -#endif - /// /// Returns a value indicating whether the current value is a prime number. /// @@ -142,30 +36,6 @@ public static class Int32Extensions return (int)((long)value).LowestCommonMultiple(other); } -#if !NET7_0_OR_GREATER - /// - /// Performs a modulo operation which supports a negative dividend. - /// - /// The dividend. - /// The divisor. - /// The result of dividend mod divisor. - /// - /// The % 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 x % y where x is - /// negative will return a negative value, akin to -(x % y), even if precedence is forced. This method provides a - /// modulo operation which supports negative dividends. - /// - /// ShreevatsaR, https://stackoverflow.com/a/1082938/1467293 - /// CC-BY-SA 2.5 - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static int Mod(this int dividend, int divisor) - { - int r = dividend % divisor; - return r < 0 ? r + divisor : r; - } -#endif - /// /// Returns the multiplicative persistence of a specified value. /// diff --git a/X10D/src/Math/Int64Extensions.cs b/X10D/src/Math/Int64Extensions.cs index b0c1e58..d000cbe 100644 --- a/X10D/src/Math/Int64Extensions.cs +++ b/X10D/src/Math/Int64Extensions.cs @@ -9,117 +9,6 @@ namespace X10D.Math; /// public static class Int64Extensions { -#if !NET7_0_OR_GREATER - /// - /// Returns the number of digits in the current 64-bit signed integer. - /// - /// The value whose digit count to compute. - /// The number of digits in . - public static int CountDigits(this long value) - { - if (value == 0) - { - return 1; - } - - return 1 + (int)System.Math.Floor(System.Math.Log10(System.Math.Abs(value))); - } - - /// - /// Computes the digital root of this 64-bit integer. - /// - /// The value whose digital root to compute. - /// The digital root of . - /// - /// The digital root is defined as the recursive sum of digits until that result is a single digit. - /// For example, the digital root of 239 is 5: 2 + 3 + 9 = 14, then 1 + 4 = 5. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static long DigitalRoot(this long value) - { - long root = System.Math.Abs(value).Mod(9L); - return root < 1L ? 9L - root : root; - } - - /// - /// Returns the factorial of the current 64-bit signed integer. - /// - /// The value whose factorial to compute. - /// The factorial of . - /// is less than 0. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static long Factorial(this long value) - { - if (value < 0) - { - throw new ArithmeticException(nameof(value)); - } - - if (value == 0) - { - return 1; - } - - var result = 1L; - for (var i = 1L; i <= value; i++) - { - result *= i; - } - - return result; - } - - /// - /// Calculates the greatest common factor between the current 64-bit signed integer, and another 64-bit unsigned integer. - /// - /// The first value. - /// The second value. - /// The greatest common factor between and . - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static long GreatestCommonFactor(this long value, long other) - { - while (other != 0) - { - (value, other) = (other, value % other); - } - - return value; - } - - /// - /// Returns a value indicating whether the current value is evenly divisible by 2. - /// - /// The value whose parity to check. - /// - /// if is evenly divisible by 2, or - /// otherwise. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool IsEven(this long value) - { - return (value & 1) == 0; - } - - /// - /// Returns a value indicating whether the current value is not evenly divisible by 2. - /// - /// The value whose parity to check. - /// - /// if is not evenly divisible by 2, or - /// otherwise. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool IsOdd(this long value) - { - return !value.IsEven(); - } -#endif - /// /// Returns a value indicating whether the current value is a prime number. /// @@ -181,30 +70,6 @@ public static class Int64Extensions return value * other / value.GreatestCommonFactor(other); } -#if !NET7_0_OR_GREATER - /// - /// Performs a modulo operation which supports a negative dividend. - /// - /// The dividend. - /// The divisor. - /// The result of dividend mod divisor. - /// - /// The % 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 x % y where x is - /// negative will return a negative value, akin to -(x % y), even if precedence is forced. This method provides a - /// modulo operation which supports negative dividends. - /// - /// ShreevatsaR, https://stackoverflow.com/a/1082938/1467293 - /// CC-BY-SA 2.5 - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static long Mod(this long dividend, long divisor) - { - long r = dividend % divisor; - return r < 0 ? r + divisor : r; - } -#endif - /// /// Returns the multiplicative persistence of a specified value. /// diff --git a/X10D/src/Math/MathUtility.cs b/X10D/src/Math/MathUtility.cs index 0ca9365..bcdbb4d 100644 --- a/X10D/src/Math/MathUtility.cs +++ b/X10D/src/Math/MathUtility.cs @@ -127,158 +127,6 @@ public static class MathUtility return (alpha - start) / (end - start); } -#if !NET7_0_OR_GREATER - /// - /// Applies a simple bias function to value. - /// - /// The value to which the bias function will be applied. - /// The bias value. Valid values range from 0-1. - /// The biased result. - /// - /// If is less than 0.5, will be shifted downward; otherwise, upward. - /// - public static float Bias(float value, float bias) - { - return value / ((1.0f / bias - 2.0f) * (1.0f - value) + 1.0f); - } - - /// - /// Applies a simple bias function to value. - /// - /// The value to which the bias function will be applied. - /// The bias value. Valid values range from 0-1. - /// The biased result. - /// - /// If is less than 0.5, will be shifted downward; otherwise, upward. - /// - public static double Bias(double value, double bias) - { - return value / ((1.0 / bias - 2.0) * (1.0 - value) + 1.0); - } - - /// - /// Linearly interpolates from one value to a target using a specified alpha. - /// - /// The interpolation source. - /// The interpolation target. - /// The interpolation alpha. - /// - /// The interpolation result as determined by (1 - alpha) * value + alpha * target. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static float Lerp(float value, float target, float alpha) - { - // rookie mistake: a + t * (b - a) - // "precise" method: (1 - t) * a + t * b - return ((1.0f - alpha) * value) + (alpha * target); - } - - /// - /// Linearly interpolates from one value to a target using a specified alpha. - /// - /// The interpolation source. - /// The interpolation target. - /// The interpolation alpha. - /// - /// The interpolation result as determined by (1 - alpha) * value + alpha * target. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static double Lerp(double value, double target, double alpha) - { - // rookie mistake: a + t * (b - a) - // "precise" method: (1 - t) * a + t * b - return ((1.0 - alpha) * value) + (alpha * target); - } - - /// - /// Performs smooth Hermite interpolation from one value to a target using a specified alpha. - /// - /// The interpolation source. - /// The interpolation target. - /// The interpolation alpha. - /// The interpolation result. - public static float SmoothStep(float value, float target, float alpha) - { - alpha = System.Math.Clamp(alpha, 0.0f, 1.0f); - alpha = -2.0f * alpha * alpha * alpha + 3.0f * alpha * alpha; - return target * alpha + value * (1.0f - alpha); - } - - /// - /// Performs smooth Hermite interpolation from one value to a target using a specified alpha. - /// - /// The interpolation source. - /// The interpolation target. - /// The interpolation alpha. - /// The interpolation result. - public static double SmoothStep(double value, double target, double alpha) - { - alpha = System.Math.Clamp(alpha, 0.0, 1.0); - alpha = -2.0 * alpha * alpha * alpha + 3.0 * alpha * alpha; - return target * alpha + value * (1.0 - alpha); - } - - /// - /// Converts a value from being a percentage of one range, to being the same percentage in a new range. - /// - /// The value to convert. - /// The old minimum value. - /// The old maximum value. - /// The new minimum value. - /// The new maximum value. - /// The scaled value. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static float ScaleRange(float value, float oldMin, float oldMax, float newMin, float newMax) - { - float oldRange = oldMax - oldMin; - float newRange = newMax - newMin; - float alpha = (value - oldMin) / oldRange; - return (alpha * newRange) + newMin; - } - - /// - /// Converts a value from being a percentage of one range, to being the same percentage in a new range. - /// - /// The value to convert. - /// The old minimum value. - /// The old maximum value. - /// The new minimum value. - /// The new maximum value. - /// The scaled value. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static double ScaleRange(double value, double oldMin, double oldMax, double newMin, double newMax) - { - double oldRange = oldMax - oldMin; - double newRange = newMax - newMin; - double alpha = (value - oldMin) / oldRange; - return (alpha * newRange) + newMin; - } - - /// - /// Returns the incremental sawtooth wave of a given value. - /// - /// The value to calculate. - /// The sawtooth wave of the given value. - public static float Sawtooth(float value) - { - return (value - MathF.Floor(value)); - } - - /// - /// Returns the incremental sawtooth wave of a given value. - /// - /// The value to calculate. - /// The sawtooth wave of the given value. - public static double Sawtooth(double value) - { - return (value - System.Math.Floor(value)); - } -#endif - /// /// Converts a linear value to a gamma-encoded value using a gamma value of 2.2. /// @@ -389,7 +237,6 @@ public static class MathUtility return 1.0f / (1.0f + System.Math.Exp(-value)); } -#if NET7_0_OR_GREATER /// /// Applies a simple bias function to value. /// @@ -474,5 +321,4 @@ public static class MathUtility alpha = -two * alpha * alpha * alpha + three * alpha * alpha; return target * alpha + value * (one - alpha); } -#endif } diff --git a/X10D/src/Math/NumberExtensions.cs b/X10D/src/Math/NumberExtensions.cs index 3a058c5..a03d583 100644 --- a/X10D/src/Math/NumberExtensions.cs +++ b/X10D/src/Math/NumberExtensions.cs @@ -1,4 +1,3 @@ -#if NET7_0_OR_GREATER using System.Diagnostics.Contracts; using System.Numerics; using System.Runtime.CompilerServices; @@ -101,4 +100,3 @@ public static class NumberExtensions return TNumber.Sign(value); } } -#endif diff --git a/X10D/src/Math/SByteExtensions.cs b/X10D/src/Math/SByteExtensions.cs index de64ee3..40b45e6 100644 --- a/X10D/src/Math/SByteExtensions.cs +++ b/X10D/src/Math/SByteExtensions.cs @@ -10,112 +10,6 @@ namespace X10D.Math; [CLSCompliant(false)] public static class SByteExtensions { -#if !NET7_0_OR_GREATER - /// - /// Returns the number of digits in the current 8-bit signed integer. - /// - /// The value whose digit count to compute. - /// The number of digits in . - public static int CountDigits(this sbyte value) - { - if (value == 0) - { - return 1; - } - - return ((long)value).CountDigits(); - } - - /// - /// Computes the digital root of this 32-bit integer. - /// - /// The value whose digital root to compute. - /// The digital root of . - /// - /// The digital root is defined as the recursive sum of digits until that result is a single digit. - /// For example, the digital root of 239 is 5: 2 + 3 + 9 = 14, then 1 + 4 = 5. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static sbyte DigitalRoot(this sbyte value) - { - int root = System.Math.Abs(value).Mod(9); - return (sbyte)(root < 1 ? 9 - root : root); - } - - /// - /// Returns the factorial of the current 8-bit signed integer. - /// - /// The value whose factorial to compute. - /// The factorial of . - /// is less than 0. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static long Factorial(this sbyte value) - { - if (value < 0) - { - throw new ArithmeticException(nameof(value)); - } - - if (value == 0) - { - return 1; - } - - var result = 1L; - for (ushort i = 1; i <= value; i++) - { - result *= i; - } - - return result; - } - - /// - /// Calculates the greatest common factor between the current 8-bit signed integer, and another 8-bit signed integer. - /// - /// The first value. - /// The second value. - /// The greatest common factor between and . - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static sbyte GreatestCommonFactor(this sbyte value, sbyte other) - { - return (sbyte)((long)value).GreatestCommonFactor(other); - } - - /// - /// Returns a value indicating whether the current value is evenly divisible by 2. - /// - /// The value whose parity to check. - /// - /// if is evenly divisible by 2, or - /// otherwise. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool IsEven(this sbyte value) - { - return (value & 1) == 0; - } - - /// - /// Returns a value indicating whether the current value is not evenly divisible by 2. - /// - /// The value whose parity to check. - /// - /// if is not evenly divisible by 2, or - /// otherwise. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool IsOdd(this sbyte value) - { - return !value.IsEven(); - } -#endif - /// /// Returns a value indicating whether the current value is a prime number. /// @@ -143,30 +37,6 @@ public static class SByteExtensions return (sbyte)((long)value).LowestCommonMultiple(other); } -#if !NET7_0_OR_GREATER - /// - /// Performs a modulo operation which supports a negative dividend. - /// - /// The dividend. - /// The divisor. - /// The result of dividend mod divisor. - /// - /// The % 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 x % y where x is - /// negative will return a negative value, akin to -(x % y), even if precedence is forced. This method provides a - /// modulo operation which supports negative dividends. - /// - /// ShreevatsaR, https://stackoverflow.com/a/1082938/1467293 - /// CC-BY-SA 2.5 - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static sbyte Mod(this sbyte dividend, sbyte divisor) - { - int r = dividend % divisor; - return (sbyte)(r < 0 ? r + divisor : r); - } -#endif - /// /// Returns the multiplicative persistence of a specified value. /// diff --git a/X10D/src/Math/UInt16Extensions.cs b/X10D/src/Math/UInt16Extensions.cs index 617ed9d..ada7d97 100644 --- a/X10D/src/Math/UInt16Extensions.cs +++ b/X10D/src/Math/UInt16Extensions.cs @@ -10,107 +10,6 @@ namespace X10D.Math; [CLSCompliant(false)] public static class UInt16Extensions { -#if !NET7_0_OR_GREATER - /// - /// Returns the number of digits in the current 16-bit signed integer. - /// - /// The value whose digit count to compute. - /// The number of digits in . - public static int CountDigits(this ushort value) - { - if (value == 0) - { - return 1; - } - - return ((ulong)value).CountDigits(); - } - - /// - /// Computes the digital root of the current 16-bit unsigned integer. - /// - /// The value whose digital root to compute. - /// The digital root of . - /// - /// The digital root is defined as the recursive sum of digits until that result is a single digit. - /// For example, the digital root of 239 is 5: 2 + 3 + 9 = 14, then 1 + 4 = 5. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static ushort DigitalRoot(this ushort value) - { - var root = (ushort)(value % 9); - return (ushort)(root == 0 ? 9 : root); - } - - /// - /// Returns the factorial of the current 16-bit unsigned integer. - /// - /// The value whose factorial to compute. - /// The factorial of . - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static ulong Factorial(this ushort value) - { - if (value == 0) - { - return 1; - } - - var result = 1UL; - for (ushort i = 1; i <= value; i++) - { - result *= i; - } - - return result; - } - - /// - /// Calculates the greatest common factor between the current 16-bit unsigned integer, and another 16-bit unsigned - /// integer. - /// - /// The first value. - /// The second value. - /// The greatest common factor between and . - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static ushort GreatestCommonFactor(this ushort value, ushort other) - { - return (ushort)((long)value).GreatestCommonFactor(other); - } - - /// - /// Returns a value indicating whether the current value is evenly divisible by 2. - /// - /// The value whose parity to check. - /// - /// if is evenly divisible by 2, or - /// otherwise. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool IsEven(this ushort value) - { - return (value & 1) == 0; - } - - /// - /// Returns a value indicating whether the current value is not evenly divisible by 2. - /// - /// The value whose parity to check. - /// - /// if is not evenly divisible by 2, or - /// otherwise. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool IsOdd(this ushort value) - { - return !value.IsEven(); - } -#endif - /// /// Returns a value indicating whether the current value is a prime number. /// diff --git a/X10D/src/Math/UInt32Extensions.cs b/X10D/src/Math/UInt32Extensions.cs index da391e9..c20a19d 100644 --- a/X10D/src/Math/UInt32Extensions.cs +++ b/X10D/src/Math/UInt32Extensions.cs @@ -10,107 +10,6 @@ namespace X10D.Math; [CLSCompliant(false)] public static class UInt32Extensions { -#if !NET7_0_OR_GREATER - /// - /// Returns the number of digits in the current 32-bit unsigned integer. - /// - /// The value whose digit count to compute. - /// The number of digits in . - public static int CountDigits(this uint value) - { - if (value == 0) - { - return 1; - } - - return ((ulong)value).CountDigits(); - } - - /// - /// Computes the digital root of the current 32-bit unsigned integer. - /// - /// The value whose digital root to compute. - /// The digital root of . - /// - /// The digital root is defined as the recursive sum of digits until that result is a single digit. - /// For example, the digital root of 239 is 5: 2 + 3 + 9 = 14, then 1 + 4 = 5. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static uint DigitalRoot(this uint value) - { - uint root = value % 9; - return root == 0 ? 9 : root; - } - - /// - /// Returns the factorial of the current 32-bit unsigned integer. - /// - /// The value whose factorial to compute. - /// The factorial of . - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static ulong Factorial(this uint value) - { - if (value == 0) - { - return 1; - } - - var result = 1UL; - for (var i = 1U; i <= value; i++) - { - result *= i; - } - - return result; - } - - /// - /// Calculates the greatest common factor between the current 32-bit unsigned integer, and another 32-bit unsigned - /// integer. - /// - /// The first value. - /// The second value. - /// The greatest common factor between and . - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static uint GreatestCommonFactor(this uint value, uint other) - { - return (uint)((long)value).GreatestCommonFactor(other); - } - - /// - /// Returns a value indicating whether the current value is evenly divisible by 2. - /// - /// The value whose parity to check. - /// - /// if is evenly divisible by 2, or - /// otherwise. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool IsEven(this uint value) - { - return (value & 1) == 0; - } - - /// - /// Returns a value indicating whether the current value is not evenly divisible by 2. - /// - /// The value whose parity to check. - /// - /// if is not evenly divisible by 2, or - /// otherwise. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool IsOdd(this uint value) - { - return !value.IsEven(); - } -#endif - /// /// Returns a value indicating whether the current value is a prime number. /// diff --git a/X10D/src/Math/UInt64Extensions.cs b/X10D/src/Math/UInt64Extensions.cs index aaec7b4..3f7637c 100644 --- a/X10D/src/Math/UInt64Extensions.cs +++ b/X10D/src/Math/UInt64Extensions.cs @@ -10,112 +10,6 @@ namespace X10D.Math; [CLSCompliant(false)] public static class UInt64Extensions { -#if !NET7_0_OR_GREATER - /// - /// Returns the number of digits in the current 64-bit unsigned integer. - /// - /// The value whose digit count to compute. - /// The number of digits in . - public static int CountDigits(this ulong value) - { - if (value == 0) - { - return 1; - } - - return 1 + (int)System.Math.Floor(System.Math.Log10(System.Math.Abs((double)value))); - } - - /// - /// Computes the digital root of the current 64-bit unsigned integer. - /// - /// The value whose digital root to compute. - /// The digital root of . - /// - /// The digital root is defined as the recursive sum of digits until that result is a single digit. - /// For example, the digital root of 239 is 5: 2 + 3 + 9 = 14, then 1 + 4 = 5. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static ulong DigitalRoot(this ulong value) - { - ulong root = value % 9; - return root == 0 ? 9 : root; - } - - /// - /// Returns the factorial of the current 64-bit unsigned integer. - /// - /// The value whose factorial to compute. - /// The factorial of . - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static ulong Factorial(this ulong value) - { - if (value == 0) - { - return 1; - } - - var result = 1UL; - for (var i = 1UL; i <= value; i++) - { - result *= i; - } - - return result; - } - - /// - /// Calculates the greatest common factor between the current 64-bit unsigned integer, and another 64-bit unsigned - /// integer. - /// - /// The first value. - /// The second value. - /// The greatest common factor between and . - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static ulong GreatestCommonFactor(this ulong value, ulong other) - { - while (other != 0) - { - (value, other) = (other, value % other); - } - - return value; - } - - /// - /// Returns a value indicating whether the current value is evenly divisible by 2. - /// - /// The value whose parity to check. - /// - /// if is evenly divisible by 2, or - /// otherwise. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool IsEven(this ulong value) - { - return (value & 1) == 0; - } - - /// - /// Returns a value indicating whether the current value is not evenly divisible by 2. - /// - /// The value whose parity to check. - /// - /// if is not evenly divisible by 2, or - /// otherwise. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool IsOdd(this ulong value) - { - return !value.IsEven(); - } -#endif - /// /// Returns a value indicating whether the current value is a prime number. /// diff --git a/X10D/src/Text/CharExtensions.cs b/X10D/src/Text/CharExtensions.cs index 8b015de..5ac29ee 100644 --- a/X10D/src/Text/CharExtensions.cs +++ b/X10D/src/Text/CharExtensions.cs @@ -18,13 +18,9 @@ public static class CharExtensions [MethodImpl(CompilerResources.MaxOptimization)] public static bool IsEmoji(this char value) { -#if NET7_0_OR_GREATER Span chars = stackalloc char[1]; chars[0] = value; return EmojiRegex.Value.IsMatch(chars); -#else - return EmojiRegex.Value.IsMatch(value.ToString()); -#endif } /// diff --git a/X10D/src/Text/RuneExtensions.cs b/X10D/src/Text/RuneExtensions.cs index c1f3ef9..24991bb 100644 --- a/X10D/src/Text/RuneExtensions.cs +++ b/X10D/src/Text/RuneExtensions.cs @@ -101,11 +101,7 @@ public static class RuneExtensions default: string exceptionFormat = ExceptionMessages.UnexpectedRuneUtf8SequenceLength; string message = string.Format(CultureInfo.CurrentCulture, exceptionFormat, length); -#if NET7_0_OR_GREATER throw new UnreachableException(message); -#else - throw new InvalidOperationException(message); -#endif // dotcover enable } } From 3f02b0006e93e8a8c7bbbd88996a6e45fb2e36bd Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Tue, 12 Nov 2024 18:10:45 +0000 Subject: [PATCH 03/27] fix(ci): drop 6.0.x from dontet-version (#92) --- .github/workflows/dotnet.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 4b60600..212d24d 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -23,7 +23,6 @@ jobs: uses: actions/setup-dotnet@v3 with: dotnet-version: | - 6.0.x 8.0.x - name: Add NuGet source @@ -35,9 +34,6 @@ 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 From 521ad7e63c85d7de43f60d16efe7f04b46b17e03 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Wed, 13 Nov 2024 17:52:56 +0000 Subject: [PATCH 04/27] [ci skip] style(ci): unindent steps --- .github/workflows/docfx.yml | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/.github/workflows/docfx.yml b/.github/workflows/docfx.yml index e922032..36ece19 100644 --- a/.github/workflows/docfx.yml +++ b/.github/workflows/docfx.yml @@ -10,22 +10,22 @@ jobs: runs-on: ubuntu-latest name: Publish Documentation steps: - - name: Checkout - uses: actions/checkout@v3 + - name: Checkout + uses: actions/checkout@v3 - - 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 }} From f041815e17a0ae1c6a8b6730ab832ed3711f29e8 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Wed, 13 Nov 2024 17:58:26 +0000 Subject: [PATCH 05/27] [ci skip] style(ci): unindent steps --- .github/workflows/docfx.yml | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/.github/workflows/docfx.yml b/.github/workflows/docfx.yml index e922032..36ece19 100644 --- a/.github/workflows/docfx.yml +++ b/.github/workflows/docfx.yml @@ -10,22 +10,22 @@ jobs: runs-on: ubuntu-latest name: Publish Documentation steps: - - name: Checkout - uses: actions/checkout@v3 + - name: Checkout + uses: actions/checkout@v3 - - 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 }} From fcedbd014f56c570502c4e7ced655ea4fac08493 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Wed, 13 Nov 2024 17:58:52 +0000 Subject: [PATCH 06/27] ci: bump actions/checkout to v4 --- .github/workflows/docfx.yml | 2 +- .github/workflows/dotnet.yml | 2 +- .github/workflows/nightly.yml | 2 +- .github/workflows/prerelease.yml | 2 +- .github/workflows/release.yml | 2 +- .github/workflows/source_validator.yml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/docfx.yml b/.github/workflows/docfx.yml index 36ece19..b160e11 100644 --- a/.github/workflows/docfx.yml +++ b/.github/workflows/docfx.yml @@ -11,7 +11,7 @@ jobs: name: Publish Documentation steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Copy favicon run: | diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 4b60600..4b8f4f3 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -17,7 +17,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup .NET uses: actions/setup-dotnet@v3 diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 05fd768..4ca3255 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -13,7 +13,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup .NET uses: actions/setup-dotnet@v3 diff --git a/.github/workflows/prerelease.yml b/.github/workflows/prerelease.yml index d62576b..94cb504 100644 --- a/.github/workflows/prerelease.yml +++ b/.github/workflows/prerelease.yml @@ -12,7 +12,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup .NET uses: actions/setup-dotnet@v3 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 374f271..a452303 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,7 +12,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup .NET uses: actions/setup-dotnet@v3 diff --git a/.github/workflows/source_validator.yml b/.github/workflows/source_validator.yml index 0d7fb93..a1024c5 100644 --- a/.github/workflows/source_validator.yml +++ b/.github/workflows/source_validator.yml @@ -14,7 +14,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup .NET uses: actions/setup-dotnet@v3 From a46ec974438ada6214d9e2dce763074d6b7057ee Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Wed, 13 Nov 2024 18:10:57 +0000 Subject: [PATCH 07/27] chore: add net9.0 target --- .github/workflows/dotnet.yml | 1 + .github/workflows/nightly.yml | 2 +- .github/workflows/prerelease.yml | 2 +- .github/workflows/release.yml | 2 +- .github/workflows/source_validator.yml | 2 +- X10D.Hosting/X10D.Hosting.csproj | 2 +- X10D.Tests/X10D.Tests.csproj | 2 +- X10D/X10D.csproj | 2 +- global.json | 2 +- 9 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 8558da2..a533cf8 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -24,6 +24,7 @@ jobs: with: dotnet-version: | 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" diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 4ca3255..2739e83 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -18,7 +18,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v3 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" diff --git a/.github/workflows/prerelease.yml b/.github/workflows/prerelease.yml index 94cb504..01deb82 100644 --- a/.github/workflows/prerelease.yml +++ b/.github/workflows/prerelease.yml @@ -17,7 +17,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v3 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" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a452303..8c99c49 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,7 +17,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v3 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" diff --git a/.github/workflows/source_validator.yml b/.github/workflows/source_validator.yml index a1024c5..d782e63 100644 --- a/.github/workflows/source_validator.yml +++ b/.github/workflows/source_validator.yml @@ -19,7 +19,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v3 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" diff --git a/X10D.Hosting/X10D.Hosting.csproj b/X10D.Hosting/X10D.Hosting.csproj index 74d07d3..09c069d 100644 --- a/X10D.Hosting/X10D.Hosting.csproj +++ b/X10D.Hosting/X10D.Hosting.csproj @@ -1,7 +1,7 @@ - net8.0 + net8.0;net9.0 diff --git a/X10D.Tests/X10D.Tests.csproj b/X10D.Tests/X10D.Tests.csproj index 74bdbc1..0184a2b 100644 --- a/X10D.Tests/X10D.Tests.csproj +++ b/X10D.Tests/X10D.Tests.csproj @@ -1,7 +1,7 @@ - net8.0 + net8.0;net9.0 false true xml,cobertura diff --git a/X10D/X10D.csproj b/X10D/X10D.csproj index 3961f95..cb6b70a 100644 --- a/X10D/X10D.csproj +++ b/X10D/X10D.csproj @@ -1,7 +1,7 @@ - net8.0 + net8.0;net9.0 diff --git a/global.json b/global.json index b5b37b6..a27a2b8 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "8.0.0", + "version": "9.0.0", "rollForward": "latestMajor", "allowPrerelease": false } From b3dfaa727e596206e574bcdb20c2c1acb7b7259e Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Wed, 13 Nov 2024 18:12:44 +0000 Subject: [PATCH 08/27] ci: bump actions/setup-dotnet to v4 --- .github/workflows/dotnet.yml | 2 +- .github/workflows/nightly.yml | 2 +- .github/workflows/prerelease.yml | 2 +- .github/workflows/release.yml | 2 +- .github/workflows/source_validator.yml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index a533cf8..1756f8c 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -20,7 +20,7 @@ jobs: uses: actions/checkout@v4 - name: Setup .NET - uses: actions/setup-dotnet@v3 + uses: actions/setup-dotnet@v4 with: dotnet-version: | 8.0.x diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 2739e83..d8c39e5 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -16,7 +16,7 @@ jobs: uses: actions/checkout@v4 - name: Setup .NET - uses: actions/setup-dotnet@v3 + uses: actions/setup-dotnet@v4 with: dotnet-version: 9.0.x diff --git a/.github/workflows/prerelease.yml b/.github/workflows/prerelease.yml index 01deb82..8bd5742 100644 --- a/.github/workflows/prerelease.yml +++ b/.github/workflows/prerelease.yml @@ -15,7 +15,7 @@ jobs: uses: actions/checkout@v4 - name: Setup .NET - uses: actions/setup-dotnet@v3 + uses: actions/setup-dotnet@v4 with: dotnet-version: 9.0.x diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8c99c49..b72d4a6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -15,7 +15,7 @@ jobs: uses: actions/checkout@v4 - name: Setup .NET - uses: actions/setup-dotnet@v3 + uses: actions/setup-dotnet@v4 with: dotnet-version: 9.0.x diff --git a/.github/workflows/source_validator.yml b/.github/workflows/source_validator.yml index d782e63..6a9e072 100644 --- a/.github/workflows/source_validator.yml +++ b/.github/workflows/source_validator.yml @@ -17,7 +17,7 @@ jobs: uses: actions/checkout@v4 - name: Setup .NET - uses: actions/setup-dotnet@v3 + uses: actions/setup-dotnet@v4 with: dotnet-version: 9.0.x From 9d870b2c241bd521e38c89f8a40bd971f308c52b Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Wed, 13 Nov 2024 18:15:24 +0000 Subject: [PATCH 09/27] chore(test): update dependencies * coverlet.collector 6.0.2 * Microsoft.Extensions.Hosting 9.0.0 * Microsoft.NET.Test.Sdk 17.11.1 * NSubstitute 5.3.0 * NUnit 4.2.2 * NUnit3TestAdapter 4.6.0 * NUnit.Analyzers 4.3.0 * System.Reactive 6.0.1 --- X10D.Tests/X10D.Tests.csproj | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/X10D.Tests/X10D.Tests.csproj b/X10D.Tests/X10D.Tests.csproj index 0184a2b..8092409 100644 --- a/X10D.Tests/X10D.Tests.csproj +++ b/X10D.Tests/X10D.Tests.csproj @@ -14,14 +14,14 @@ - - - - - - - - + + + + + + + + From 0b978f5cdfb717c175887a52ba2102018ff0b411 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Wed, 13 Nov 2024 18:22:36 +0000 Subject: [PATCH 10/27] refactor!: remove Span.Split --- CHANGELOG.md | 12 ++++++++++-- X10D.Tests/src/Collections/SpanTest.cs | 4 ++++ X10D/src/Collections/SpanExtensions.cs | 2 ++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 29a70fa..521a00e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,14 @@ 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] + +### Removed + +- X10D: Removed `Span.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-8.0). + +## [4.0.0] - 2024-06-12 ### Added @@ -642,7 +649,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 diff --git a/X10D.Tests/src/Collections/SpanTest.cs b/X10D.Tests/src/Collections/SpanTest.cs index fa7ac45..114336e 100644 --- a/X10D.Tests/src/Collections/SpanTest.cs +++ b/X10D.Tests/src/Collections/SpanTest.cs @@ -1,5 +1,7 @@ using NUnit.Framework; +#if !NET9_0_OR_GREATER using X10D.Collections; +#endif namespace X10D.Tests.Collections; @@ -70,6 +72,7 @@ internal class SpanTest 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 } diff --git a/X10D/src/Collections/SpanExtensions.cs b/X10D/src/Collections/SpanExtensions.cs index 7c3ee0a..d063dd9 100644 --- a/X10D/src/Collections/SpanExtensions.cs +++ b/X10D/src/Collections/SpanExtensions.cs @@ -75,6 +75,7 @@ public static class SpanExtensions } #endif +#if !NET9_0_OR_GREATER /// /// Splits a span of elements into sub-spans based on a delimiting element. /// @@ -134,4 +135,5 @@ public static class SpanExtensions { return new SpanSplitEnumerator(source, delimiter); } +#endif } From a433244799efaf9e08f430a3d86da60c3d6052c4 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Wed, 13 Nov 2024 18:41:45 +0000 Subject: [PATCH 11/27] fix(test): use new NUnit constraint API --- X10D.Tests/src/Collections/EnumerableTests.cs | 16 ++-- X10D.Tests/src/Collections/ListTests.cs | 64 ++++++------- X10D.Tests/src/Collections/SpanTest.cs | 16 ++-- X10D.Tests/src/Core/CoreTests.cs | 2 +- X10D.Tests/src/Core/SpanTest.cs | 1 - X10D.Tests/src/Drawing/PolygonFTests.cs | 6 +- X10D.Tests/src/Drawing/PolyhedronTests.cs | 10 +- .../src/Hosting/ServiceCollectionTests.cs | 16 ++-- X10D.Tests/src/IO/BooleanTests.cs | 4 +- X10D.Tests/src/IO/ByteTests.cs | 11 ++- X10D.Tests/src/IO/DecimalTests.cs | 24 +++-- X10D.Tests/src/IO/DoubleTests.cs | 22 +++-- X10D.Tests/src/IO/FileInfoTests.cs | 14 ++- X10D.Tests/src/IO/Int16Tests.cs | 22 +++-- X10D.Tests/src/IO/Int32Tests.cs | 22 +++-- X10D.Tests/src/IO/Int64Tests.cs | 22 +++-- X10D.Tests/src/IO/SByteTests.cs | 11 ++- X10D.Tests/src/IO/SingleTests.cs | 22 +++-- X10D.Tests/src/IO/StreamTests.WriteDecimal.cs | 38 ++++---- X10D.Tests/src/IO/StreamTests.WriteDouble.cs | 26 ++++-- X10D.Tests/src/IO/StreamTests.WriteInt16.cs | 26 ++++-- X10D.Tests/src/IO/StreamTests.WriteInt32.cs | 26 ++++-- X10D.Tests/src/IO/StreamTests.WriteInt64.cs | 26 ++++-- X10D.Tests/src/IO/StreamTests.WriteSingle.cs | 26 ++++-- X10D.Tests/src/IO/StreamTests.WriteUInt16.cs | 26 ++++-- X10D.Tests/src/IO/StreamTests.WriteUInt32.cs | 26 ++++-- X10D.Tests/src/IO/StreamTests.WriteUInt64.cs | 26 ++++-- X10D.Tests/src/IO/StreamTests.cs | 4 +- X10D.Tests/src/IO/UInt16Tests.cs | 24 +++-- X10D.Tests/src/IO/UInt32Tests.cs | 24 +++-- X10D.Tests/src/IO/UInt64Tests.cs | 24 +++-- X10D.Tests/src/Math/IsPrimeTests.cs | 2 +- X10D.Tests/src/Text/CoreTests.cs | 8 +- X10D.Tests/src/Text/EnumerableTests.cs | 32 ++++--- .../src/Text/StringBuilderReaderTests.cs | 91 ++++++++++++------- X10D.Tests/src/Text/StringTests.cs | 9 +- 36 files changed, 457 insertions(+), 312 deletions(-) diff --git a/X10D.Tests/src/Collections/EnumerableTests.cs b/X10D.Tests/src/Collections/EnumerableTests.cs index a08c05f..37e19f8 100644 --- a/X10D.Tests/src/Collections/EnumerableTests.cs +++ b/X10D.Tests/src/Collections/EnumerableTests.cs @@ -117,11 +117,11 @@ internal partial class EnumerableTests IEnumerable source = oneToTen.Select(i => new DummyClass {Value = i}).ToArray(); IEnumerable 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 source = oneToTen.Select(i => new DummyClass {Value = i}).ToArray(); IEnumerable 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 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++; } diff --git a/X10D.Tests/src/Collections/ListTests.cs b/X10D.Tests/src/Collections/ListTests.cs index a2f7f28..469d097 100644 --- a/X10D.Tests/src/Collections/ListTests.cs +++ b/X10D.Tests/src/Collections/ListTests.cs @@ -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(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,7 +36,7 @@ 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] @@ -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); @@ -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(() => array.IndexOf(0, 2, 4)); } @@ -184,7 +184,7 @@ internal class ListTests public void RemoveRange_ShouldThrowArgumentOutOfRangeException_GivenEndIndexGreaterThanOrEqualToCount() { Assert.Throws(() => new List().RemoveRange(..0)); - Assert.Throws(() => new List {1}.RemoveRange(..2)); + Assert.Throws(() => new List { 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(Enumerable.Range(1, 52)); // 52! chance of being shuffled to the same order var shuffled = new List(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(); - CollectionAssert.AreEqual(Array.Empty(), array.Slice(0).ToArray()); - CollectionAssert.AreEqual(Array.Empty(), array.Slice(0, 0).ToArray()); + Assert.That(array.Slice(0).ToArray(), Is.EqualTo(Array.Empty()).AsCollection); + Assert.That(array.Slice(0, 0).ToArray(), Is.EqualTo(Array.Empty()).AsCollection); } [Test] @@ -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(() => array.Slice(2, 4)); } @@ -297,18 +297,18 @@ internal class ListTests [Test] public void Swap_ShouldSwapElements_GivenMatchingElementCount() { - var first = new List {1, 2, 3}; - var second = new List {4, 5, 6}; + var first = new List { 1, 2, 3 }; + var second = new List { 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 {6, 7}; + var second = new List { 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)); } } diff --git a/X10D.Tests/src/Collections/SpanTest.cs b/X10D.Tests/src/Collections/SpanTest.cs index 114336e..47175f0 100644 --- a/X10D.Tests/src/Collections/SpanTest.cs +++ b/X10D.Tests/src/Collections/SpanTest.cs @@ -31,7 +31,7 @@ internal class SpanTest [Test] public void Count_ShouldReturn8_GivenSpanWith8MatchingElements() { - Span span = stackalloc int[16] {1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2}; + Span span = stackalloc int[16] { 1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2 }; int count = span.Count(2); @@ -41,7 +41,7 @@ internal class SpanTest [Test] public void Count_ShouldReturn8_GivenReadOnlySpanWith8MatchingElements() { - ReadOnlySpan span = stackalloc int[16] {1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2}; + ReadOnlySpan span = stackalloc int[16] { 1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2 }; int count = span.Count(2); @@ -51,25 +51,25 @@ internal class SpanTest [Test] public void Replace_ShouldReplaceAllElements_GivenSpanOfInt32() { - Span span = stackalloc int[16] {1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2}; + Span span = stackalloc int[16] { 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 chars = stackalloc char[12] {'H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!'}; + Span chars = stackalloc char[12] { '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 span = stackalloc int[16] {1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2}; + Span span = stackalloc int[16] { 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 diff --git a/X10D.Tests/src/Core/CoreTests.cs b/X10D.Tests/src/Core/CoreTests.cs index a5df6ac..6e46d93 100644 --- a/X10D.Tests/src/Core/CoreTests.cs +++ b/X10D.Tests/src/Core/CoreTests.cs @@ -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] diff --git a/X10D.Tests/src/Core/SpanTest.cs b/X10D.Tests/src/Core/SpanTest.cs index 743a55e..9b3673b 100644 --- a/X10D.Tests/src/Core/SpanTest.cs +++ b/X10D.Tests/src/Core/SpanTest.cs @@ -1,4 +1,3 @@ -using System.Runtime.Intrinsics.Arm; using System.Runtime.Intrinsics.X86; using NUnit.Framework; using X10D.Core; diff --git a/X10D.Tests/src/Drawing/PolygonFTests.cs b/X10D.Tests/src/Drawing/PolygonFTests.cs index 9052c98..a5c54fe 100644 --- a/X10D.Tests/src/Drawing/PolygonFTests.cs +++ b/X10D.Tests/src/Drawing/PolygonFTests.cs @@ -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 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); }); } diff --git a/X10D.Tests/src/Drawing/PolyhedronTests.cs b/X10D.Tests/src/Drawing/PolyhedronTests.cs index 30545e7..4a81ec7 100644 --- a/X10D.Tests/src/Drawing/PolyhedronTests.cs +++ b/X10D.Tests/src/Drawing/PolyhedronTests.cs @@ -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 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); }); } diff --git a/X10D.Tests/src/Hosting/ServiceCollectionTests.cs b/X10D.Tests/src/Hosting/ServiceCollectionTests.cs index d9a8351..7bc78d1 100644 --- a/X10D.Tests/src/Hosting/ServiceCollectionTests.cs +++ b/X10D.Tests/src/Hosting/ServiceCollectionTests.cs @@ -23,8 +23,8 @@ internal class ServiceCollectionTests { Assert.That(service, Is.Not.Null); Assert.That(hostedService, Is.Not.Null); - Assert.IsAssignableFrom(service); - Assert.IsAssignableFrom(hostedService); + Assert.That(service, Is.AssignableFrom()); + Assert.That(hostedService, Is.AssignableFrom()); 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(service); - Assert.IsAssignableFrom(hostedService); + Assert.That(service, Is.AssignableFrom()); + Assert.That(hostedService, Is.AssignableFrom()); 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(service); - Assert.IsAssignableFrom(hostedService); + Assert.That(service, Is.AssignableFrom()); + Assert.That(hostedService, Is.AssignableFrom()); 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(service); - Assert.IsAssignableFrom(hostedService); + Assert.That(service, Is.AssignableFrom()); + Assert.That(hostedService, Is.AssignableFrom()); Assert.That(hostedService, Is.SameAs(service)); }); } diff --git a/X10D.Tests/src/IO/BooleanTests.cs b/X10D.Tests/src/IO/BooleanTests.cs index 87e2075..99bd606 100644 --- a/X10D.Tests/src/IO/BooleanTests.cs +++ b/X10D.Tests/src/IO/BooleanTests.cs @@ -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,7 +19,7 @@ internal class BooleanTests const bool value = true; Span 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] diff --git a/X10D.Tests/src/IO/ByteTests.cs b/X10D.Tests/src/IO/ByteTests.cs index 433cc09..1c9d1c9 100644 --- a/X10D.Tests/src/IO/ByteTests.cs +++ b/X10D.Tests/src/IO/ByteTests.cs @@ -10,16 +10,19 @@ 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 buffer = stackalloc byte[1]; - Assert.That(value.TryWriteBytes(buffer)); - CollectionAssert.AreEqual(new[] {value}, buffer.ToArray()); + Assert.Multiple(() => + { + Span buffer = stackalloc byte[1]; + Assert.That(value.TryWriteBytes(buffer)); + Assert.That(buffer.ToArray(), Is.EqualTo(new[] { value }).AsCollection); + }); } [Test] diff --git a/X10D.Tests/src/IO/DecimalTests.cs b/X10D.Tests/src/IO/DecimalTests.cs index 46e7077..8a64198 100644 --- a/X10D.Tests/src/IO/DecimalTests.cs +++ b/X10D.Tests/src/IO/DecimalTests.cs @@ -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 bytes = stackalloc byte[16]; - Assert.That(value.TryWriteBigEndianBytes(bytes)); - - CollectionAssert.AreEqual(expected, bytes.ToArray()); + Assert.Multiple(() => + { + Span 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 bytes = stackalloc byte[16]; - Assert.That(value.TryWriteLittleEndianBytes(bytes)); - - CollectionAssert.AreEqual(expected, bytes.ToArray()); + Assert.Multiple(() => + { + Span bytes = stackalloc byte[16]; + Assert.That(value.TryWriteLittleEndianBytes(bytes)); + Assert.That(bytes.ToArray(), Is.EqualTo(expected).AsCollection); + }); } [Test] diff --git a/X10D.Tests/src/IO/DoubleTests.cs b/X10D.Tests/src/IO/DoubleTests.cs index 66f15fe..99ae227 100644 --- a/X10D.Tests/src/IO/DoubleTests.cs +++ b/X10D.Tests/src/IO/DoubleTests.cs @@ -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 actual = stackalloc byte[8]; - Assert.That(value.TryWriteBigEndianBytes(actual)); - CollectionAssert.AreEqual(expected, actual.ToArray()); + Assert.Multiple(() => + { + Span actual = stackalloc byte[8]; + Assert.That(value.TryWriteBigEndianBytes(actual)); + Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection); + }); } [Test] @@ -43,9 +46,12 @@ internal class DoubleTests const double value = 42.5; var expected = new byte[] { 0, 0, 0, 0, 0, 0x40, 0x45, 0x40 }; - Span actual = stackalloc byte[8]; - Assert.That(value.TryWriteLittleEndianBytes(actual)); - CollectionAssert.AreEqual(expected, actual.ToArray()); + Assert.Multiple(() => + { + Span actual = stackalloc byte[8]; + Assert.That(value.TryWriteLittleEndianBytes(actual)); + Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection); + }); } [Test] diff --git a/X10D.Tests/src/IO/FileInfoTests.cs b/X10D.Tests/src/IO/FileInfoTests.cs index 319e864..aff685e 100644 --- a/X10D.Tests/src/IO/FileInfoTests.cs +++ b/X10D.Tests/src/IO/FileInfoTests.cs @@ -29,7 +29,7 @@ internal class FileInfoTests try { byte[] hash = new FileInfo(fileName).GetHash(); - CollectionAssert.AreEqual(expectedHash, hash); + Assert.That(hash, Is.EqualTo(expectedHash).AsCollection); } finally { @@ -58,10 +58,14 @@ internal class FileInfoTests try { - Span hash = stackalloc byte[20]; - new FileInfo(fileName).TryWriteHash(hash, out int bytesWritten); - Assert.That(bytesWritten, Is.EqualTo(expectedHash.Length)); - CollectionAssert.AreEqual(expectedHash, hash.ToArray()); + Assert.Multiple(() => + { + Span hash = stackalloc byte[20]; + new FileInfo(fileName).TryWriteHash(hash, out int bytesWritten); + + Assert.That(bytesWritten, Is.EqualTo(expectedHash.Length)); + Assert.That(hash.ToArray(), Is.EqualTo(expectedHash).AsCollection); + }); } finally { diff --git a/X10D.Tests/src/IO/Int16Tests.cs b/X10D.Tests/src/IO/Int16Tests.cs index 6b03d4a..ad6a146 100644 --- a/X10D.Tests/src/IO/Int16Tests.cs +++ b/X10D.Tests/src/IO/Int16Tests.cs @@ -13,7 +13,7 @@ internal class Int16Tests byte[] expected = { 0x0F, 0 }; byte[] actual = value.GetLittleEndianBytes(); - CollectionAssert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected).AsCollection); } [Test] @@ -23,7 +23,7 @@ internal class Int16Tests byte[] expected = { 0, 0x0F }; byte[] actual = value.GetBigEndianBytes(); - CollectionAssert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected).AsCollection); } [Test] @@ -32,9 +32,12 @@ internal class Int16Tests const short value = 0x0F; byte[] expected = { 0x0F, 0 }; - Span actual = stackalloc byte[2]; - Assert.That(value.TryWriteLittleEndianBytes(actual)); - CollectionAssert.AreEqual(expected, actual.ToArray()); + Assert.Multiple(() => + { + Span actual = stackalloc byte[2]; + Assert.That(value.TryWriteLittleEndianBytes(actual)); + Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection); + }); } [Test] @@ -43,9 +46,12 @@ internal class Int16Tests const short value = 0x0F; byte[] expected = { 0, 0x0F }; - Span actual = stackalloc byte[2]; - Assert.That(value.TryWriteBigEndianBytes(actual)); - CollectionAssert.AreEqual(expected, actual.ToArray()); + Assert.Multiple(() => + { + Span actual = stackalloc byte[2]; + Assert.That(value.TryWriteBigEndianBytes(actual)); + Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection); + }); } [Test] diff --git a/X10D.Tests/src/IO/Int32Tests.cs b/X10D.Tests/src/IO/Int32Tests.cs index 01c7990..634426f 100644 --- a/X10D.Tests/src/IO/Int32Tests.cs +++ b/X10D.Tests/src/IO/Int32Tests.cs @@ -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 actual = stackalloc byte[4]; - Assert.That(value.TryWriteBigEndianBytes(actual)); - CollectionAssert.AreEqual(expected, actual.ToArray()); + Assert.Multiple(() => + { + Span actual = stackalloc byte[4]; + Assert.That(value.TryWriteBigEndianBytes(actual)); + Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection); + }); } [Test] @@ -43,9 +46,12 @@ internal class Int32Tests const int value = 0x0F; var expected = new byte[] { 0x0F, 0, 0, 0 }; - Span actual = stackalloc byte[4]; - Assert.That(value.TryWriteLittleEndianBytes(actual)); - CollectionAssert.AreEqual(expected, actual.ToArray()); + Assert.Multiple(() => + { + Span actual = stackalloc byte[4]; + Assert.That(value.TryWriteLittleEndianBytes(actual)); + Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection); + }); } [Test] diff --git a/X10D.Tests/src/IO/Int64Tests.cs b/X10D.Tests/src/IO/Int64Tests.cs index c331369..d4751be 100644 --- a/X10D.Tests/src/IO/Int64Tests.cs +++ b/X10D.Tests/src/IO/Int64Tests.cs @@ -13,7 +13,7 @@ internal class Int64Tests 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] @@ -23,7 +23,7 @@ internal class Int64Tests 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] @@ -32,9 +32,12 @@ internal class Int64Tests const long value = 0x0F; byte[] expected = { 0x0F, 0, 0, 0, 0, 0, 0, 0 }; - Span actual = stackalloc byte[8]; - Assert.That(value.TryWriteLittleEndianBytes(actual)); - CollectionAssert.AreEqual(expected, actual.ToArray()); + Assert.Multiple(() => + { + Span actual = stackalloc byte[8]; + Assert.That(value.TryWriteLittleEndianBytes(actual)); + Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection); + }); } [Test] @@ -43,9 +46,12 @@ internal class Int64Tests const long value = 0x0F; byte[] expected = { 0, 0, 0, 0, 0, 0, 0, 0x0F }; - Span actual = stackalloc byte[8]; - Assert.That(value.TryWriteBigEndianBytes(actual)); - CollectionAssert.AreEqual(expected, actual.ToArray()); + Assert.Multiple(() => + { + Span actual = stackalloc byte[8]; + Assert.That(value.TryWriteBigEndianBytes(actual)); + Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection); + }); } [Test] diff --git a/X10D.Tests/src/IO/SByteTests.cs b/X10D.Tests/src/IO/SByteTests.cs index c9486e2..e7d3d6e 100644 --- a/X10D.Tests/src/IO/SByteTests.cs +++ b/X10D.Tests/src/IO/SByteTests.cs @@ -10,16 +10,19 @@ 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 buffer = stackalloc byte[1]; - Assert.That(value.TryWriteBytes(buffer)); - CollectionAssert.AreEqual(new[] {(byte)value}, buffer.ToArray()); + Assert.Multiple(() => + { + Span buffer = stackalloc byte[1]; + Assert.That(value.TryWriteBytes(buffer)); + Assert.That(buffer.ToArray(), Is.EqualTo(new[] { (byte)value }).AsCollection); + }); } [Test] diff --git a/X10D.Tests/src/IO/SingleTests.cs b/X10D.Tests/src/IO/SingleTests.cs index 984f8a4..1dd325a 100644 --- a/X10D.Tests/src/IO/SingleTests.cs +++ b/X10D.Tests/src/IO/SingleTests.cs @@ -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 actual = stackalloc byte[4]; - Assert.That(value.TryWriteBigEndianBytes(actual)); - CollectionAssert.AreEqual(expected, actual.ToArray()); + Assert.Multiple(() => + { + Span actual = stackalloc byte[4]; + Assert.That(value.TryWriteBigEndianBytes(actual)); + Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection); + }); } [Test] @@ -43,9 +46,12 @@ internal class SingleTests const float value = 42.5f; var expected = new byte[] { 0, 0, 0x2A, 0x42 }; - Span actual = stackalloc byte[4]; - Assert.That(value.TryWriteLittleEndianBytes(actual)); - CollectionAssert.AreEqual(expected, actual.ToArray()); + Assert.Multiple(() => + { + Span actual = stackalloc byte[4]; + Assert.That(value.TryWriteLittleEndianBytes(actual)); + Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection); + }); } [Test] diff --git a/X10D.Tests/src/IO/StreamTests.WriteDecimal.cs b/X10D.Tests/src/IO/StreamTests.WriteDecimal.cs index 15e7538..91aed0d 100644 --- a/X10D.Tests/src/IO/StreamTests.WriteDecimal.cs +++ b/X10D.Tests/src/IO/StreamTests.WriteDecimal.cs @@ -45,16 +45,19 @@ internal partial class StreamTests Assert.That(stream.Position, Is.EqualTo(16)); stream.Position = 0; - Span actual = stackalloc byte[16]; - ReadOnlySpan 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 actual = stackalloc byte[16]; + ReadOnlySpan expected = stackalloc byte[] + { + 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 actual = stackalloc byte[16]; - ReadOnlySpan 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 actual = stackalloc byte[16]; + ReadOnlySpan expected = stackalloc byte[] + { + 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); + }); } } diff --git a/X10D.Tests/src/IO/StreamTests.WriteDouble.cs b/X10D.Tests/src/IO/StreamTests.WriteDouble.cs index 8828325..ba82011 100644 --- a/X10D.Tests/src/IO/StreamTests.WriteDouble.cs +++ b/X10D.Tests/src/IO/StreamTests.WriteDouble.cs @@ -44,12 +44,15 @@ internal partial class StreamTests Assert.That(stream.Position, Is.EqualTo(8)); stream.Position = 0; - Span actual = stackalloc byte[8]; - ReadOnlySpan expected = stackalloc byte[] { 0x40, 0x7A, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00 }; - int read = stream.Read(actual); + Assert.Multiple(() => + { + Span actual = stackalloc byte[8]; + ReadOnlySpan expected = stackalloc byte[] { 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 actual = stackalloc byte[8]; - ReadOnlySpan expected = stackalloc byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x7A, 0x40 }; - int read = stream.Read(actual); + Assert.Multiple(() => + { + Span actual = stackalloc byte[8]; + ReadOnlySpan expected = stackalloc byte[] { 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); + }); } } diff --git a/X10D.Tests/src/IO/StreamTests.WriteInt16.cs b/X10D.Tests/src/IO/StreamTests.WriteInt16.cs index bc38dd8..a49513b 100644 --- a/X10D.Tests/src/IO/StreamTests.WriteInt16.cs +++ b/X10D.Tests/src/IO/StreamTests.WriteInt16.cs @@ -44,12 +44,15 @@ internal partial class StreamTests Assert.That(stream.Position, Is.EqualTo(2)); stream.Position = 0; - Span actual = stackalloc byte[2]; - ReadOnlySpan expected = stackalloc byte[] { 0x01, 0xA4 }; - int read = stream.Read(actual); + Assert.Multiple(() => + { + Span actual = stackalloc byte[2]; + ReadOnlySpan expected = stackalloc byte[] { 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 actual = stackalloc byte[2]; - ReadOnlySpan expected = stackalloc byte[] { 0xA4, 0x01 }; - int read = stream.Read(actual); + Assert.Multiple(() => + { + Span actual = stackalloc byte[2]; + ReadOnlySpan expected = stackalloc byte[] { 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); + }); } } diff --git a/X10D.Tests/src/IO/StreamTests.WriteInt32.cs b/X10D.Tests/src/IO/StreamTests.WriteInt32.cs index 75688f9..7534e2e 100644 --- a/X10D.Tests/src/IO/StreamTests.WriteInt32.cs +++ b/X10D.Tests/src/IO/StreamTests.WriteInt32.cs @@ -44,12 +44,15 @@ internal partial class StreamTests Assert.That(stream.Position, Is.EqualTo(4)); stream.Position = 0; - Span actual = stackalloc byte[4]; - ReadOnlySpan expected = stackalloc byte[] { 0x00, 0x00, 0x01, 0xA4 }; - int read = stream.Read(actual); + Assert.Multiple(() => + { + Span actual = stackalloc byte[4]; + ReadOnlySpan expected = stackalloc byte[] { 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 actual = stackalloc byte[4]; - ReadOnlySpan expected = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00 }; - int read = stream.Read(actual); + Assert.Multiple(() => + { + Span actual = stackalloc byte[4]; + ReadOnlySpan expected = stackalloc byte[] { 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); + }); } } diff --git a/X10D.Tests/src/IO/StreamTests.WriteInt64.cs b/X10D.Tests/src/IO/StreamTests.WriteInt64.cs index feeb677..3a3fea5 100644 --- a/X10D.Tests/src/IO/StreamTests.WriteInt64.cs +++ b/X10D.Tests/src/IO/StreamTests.WriteInt64.cs @@ -44,12 +44,15 @@ internal partial class StreamTests Assert.That(stream.Position, Is.EqualTo(8)); stream.Position = 0; - Span actual = stackalloc byte[8]; - ReadOnlySpan expected = stackalloc byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xA4 }; - int read = stream.Read(actual); + Assert.Multiple(() => + { + Span actual = stackalloc byte[8]; + ReadOnlySpan expected = stackalloc byte[] { 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 actual = stackalloc byte[8]; - ReadOnlySpan expected = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - int read = stream.Read(actual); + Assert.Multiple(() => + { + Span actual = stackalloc byte[8]; + ReadOnlySpan expected = stackalloc byte[] { 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); + }); } } diff --git a/X10D.Tests/src/IO/StreamTests.WriteSingle.cs b/X10D.Tests/src/IO/StreamTests.WriteSingle.cs index 7df8eb8..b9a6db0 100644 --- a/X10D.Tests/src/IO/StreamTests.WriteSingle.cs +++ b/X10D.Tests/src/IO/StreamTests.WriteSingle.cs @@ -44,12 +44,15 @@ internal partial class StreamTests Assert.That(stream.Position, Is.EqualTo(4)); stream.Position = 0; - Span actual = stackalloc byte[4]; - ReadOnlySpan expected = stackalloc byte[] { 0x43, 0xD2, 0x00, 0x00 }; - int read = stream.Read(actual); + Assert.Multiple(() => + { + Span actual = stackalloc byte[4]; + ReadOnlySpan expected = stackalloc byte[] { 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 actual = stackalloc byte[4]; - ReadOnlySpan expected = stackalloc byte[] { 0x00, 0x00, 0xD2, 0x43 }; - int read = stream.Read(actual); + Assert.Multiple(() => + { + Span actual = stackalloc byte[4]; + ReadOnlySpan expected = stackalloc byte[] { 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); + }); } } diff --git a/X10D.Tests/src/IO/StreamTests.WriteUInt16.cs b/X10D.Tests/src/IO/StreamTests.WriteUInt16.cs index 7fde9f2..4f0be3d 100644 --- a/X10D.Tests/src/IO/StreamTests.WriteUInt16.cs +++ b/X10D.Tests/src/IO/StreamTests.WriteUInt16.cs @@ -44,12 +44,15 @@ internal partial class StreamTests Assert.That(stream.Position, Is.EqualTo(2)); stream.Position = 0; - Span actual = stackalloc byte[2]; - ReadOnlySpan expected = stackalloc byte[] { 0x01, 0xA4 }; - int read = stream.Read(actual); + Assert.Multiple(() => + { + Span actual = stackalloc byte[2]; + ReadOnlySpan expected = stackalloc byte[] { 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 actual = stackalloc byte[2]; - ReadOnlySpan expected = stackalloc byte[] { 0xA4, 0x01 }; - int read = stream.Read(actual); + Assert.Multiple(() => + { + Span actual = stackalloc byte[2]; + ReadOnlySpan expected = stackalloc byte[] { 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); + }); } } diff --git a/X10D.Tests/src/IO/StreamTests.WriteUInt32.cs b/X10D.Tests/src/IO/StreamTests.WriteUInt32.cs index e5eafb7..2c58155 100644 --- a/X10D.Tests/src/IO/StreamTests.WriteUInt32.cs +++ b/X10D.Tests/src/IO/StreamTests.WriteUInt32.cs @@ -44,12 +44,15 @@ internal partial class StreamTests Assert.That(stream.Position, Is.EqualTo(4)); stream.Position = 0; - Span actual = stackalloc byte[4]; - ReadOnlySpan expected = stackalloc byte[] { 0x00, 0x00, 0x01, 0xA4 }; - int read = stream.Read(actual); + Assert.Multiple(() => + { + Span actual = stackalloc byte[4]; + ReadOnlySpan expected = stackalloc byte[] { 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 actual = stackalloc byte[4]; - ReadOnlySpan expected = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00 }; - int read = stream.Read(actual); + Assert.Multiple(() => + { + Span actual = stackalloc byte[4]; + ReadOnlySpan expected = stackalloc byte[] { 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); + }); } } diff --git a/X10D.Tests/src/IO/StreamTests.WriteUInt64.cs b/X10D.Tests/src/IO/StreamTests.WriteUInt64.cs index 5d8edcf..349f489 100644 --- a/X10D.Tests/src/IO/StreamTests.WriteUInt64.cs +++ b/X10D.Tests/src/IO/StreamTests.WriteUInt64.cs @@ -44,12 +44,15 @@ internal partial class StreamTests Assert.That(stream.Position, Is.EqualTo(8)); stream.Position = 0; - Span actual = stackalloc byte[8]; - ReadOnlySpan expected = stackalloc byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xA4 }; - int read = stream.Read(actual); + Assert.Multiple(() => + { + Span actual = stackalloc byte[8]; + ReadOnlySpan expected = stackalloc byte[] { 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 actual = stackalloc byte[8]; - ReadOnlySpan expected = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - int read = stream.Read(actual); + Assert.Multiple(() => + { + Span actual = stackalloc byte[8]; + ReadOnlySpan expected = stackalloc byte[] { 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); + }); } } diff --git a/X10D.Tests/src/IO/StreamTests.cs b/X10D.Tests/src/IO/StreamTests.cs index b522265..2857c16 100644 --- a/X10D.Tests/src/IO/StreamTests.cs +++ b/X10D.Tests/src/IO/StreamTests.cs @@ -26,7 +26,7 @@ internal partial class StreamTests byte[] hash = stream.GetHash(); Trace.WriteLine($"Hash: {BitConverter.ToString(hash)}"); Trace.WriteLine($"Expected: {BitConverter.ToString(expectedHash)}"); - CollectionAssert.AreEqual(expectedHash, hash); + Assert.That(hash, Is.EqualTo(expectedHash).AsCollection); } [Test] @@ -54,7 +54,7 @@ internal partial class StreamTests Span hash = stackalloc byte[20]; stream.TryWriteHash(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] diff --git a/X10D.Tests/src/IO/UInt16Tests.cs b/X10D.Tests/src/IO/UInt16Tests.cs index be9360e..e646553 100644 --- a/X10D.Tests/src/IO/UInt16Tests.cs +++ b/X10D.Tests/src/IO/UInt16Tests.cs @@ -13,7 +13,7 @@ internal class UInt16Tests byte[] expected = { 0x0F, 0 }; byte[] actual = value.GetLittleEndianBytes(); - CollectionAssert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected).AsCollection); } [Test] @@ -23,7 +23,7 @@ internal class UInt16Tests byte[] expected = { 0, 0x0F }; byte[] actual = value.GetBigEndianBytes(); - CollectionAssert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected).AsCollection); } [Test] @@ -32,10 +32,12 @@ internal class UInt16Tests const ushort value = 0x0F; byte[] expected = { 0x0F, 0 }; - Span actual = stackalloc byte[2]; - Assert.That(value.TryWriteLittleEndianBytes(actual)); - - CollectionAssert.AreEqual(expected, actual.ToArray()); + Assert.Multiple(() => + { + Span actual = stackalloc byte[2]; + Assert.That(value.TryWriteLittleEndianBytes(actual)); + Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection); + }); } [Test] @@ -44,10 +46,12 @@ internal class UInt16Tests const ushort value = 0x0F; byte[] expected = { 0, 0x0F }; - Span actual = stackalloc byte[2]; - Assert.That(value.TryWriteBigEndianBytes(actual)); - - CollectionAssert.AreEqual(expected, actual.ToArray()); + Assert.Multiple(() => + { + Span actual = stackalloc byte[2]; + Assert.That(value.TryWriteBigEndianBytes(actual)); + Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection); + }); } [Test] diff --git a/X10D.Tests/src/IO/UInt32Tests.cs b/X10D.Tests/src/IO/UInt32Tests.cs index 7847759..588f2fb 100644 --- a/X10D.Tests/src/IO/UInt32Tests.cs +++ b/X10D.Tests/src/IO/UInt32Tests.cs @@ -13,7 +13,7 @@ internal class UInt32Tests byte[] expected = { 0x0F, 0, 0, 0 }; byte[] actual = value.GetLittleEndianBytes(); - CollectionAssert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected).AsCollection); } [Test] @@ -23,7 +23,7 @@ internal class UInt32Tests byte[] expected = { 0, 0, 0, 0x0F }; byte[] actual = value.GetBigEndianBytes(); - CollectionAssert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected).AsCollection); } [Test] @@ -32,10 +32,12 @@ internal class UInt32Tests const uint value = 0x0F; byte[] expected = { 0x0F, 0, 0, 0 }; - Span actual = stackalloc byte[4]; - Assert.That(value.TryWriteLittleEndianBytes(actual)); - - CollectionAssert.AreEqual(expected, actual.ToArray()); + Assert.Multiple(() => + { + Span actual = stackalloc byte[4]; + Assert.That(value.TryWriteLittleEndianBytes(actual)); + Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection); + }); } [Test] @@ -44,10 +46,12 @@ internal class UInt32Tests const uint value = 0x0F; byte[] expected = { 0, 0, 0, 0x0F }; - Span actual = stackalloc byte[4]; - Assert.That(value.TryWriteBigEndianBytes(actual)); - - CollectionAssert.AreEqual(expected, actual.ToArray()); + Assert.Multiple(() => + { + Span actual = stackalloc byte[4]; + Assert.That(value.TryWriteBigEndianBytes(actual)); + Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection); + }); } [Test] diff --git a/X10D.Tests/src/IO/UInt64Tests.cs b/X10D.Tests/src/IO/UInt64Tests.cs index e783e2a..07e38f4 100644 --- a/X10D.Tests/src/IO/UInt64Tests.cs +++ b/X10D.Tests/src/IO/UInt64Tests.cs @@ -13,7 +13,7 @@ internal class UInt64Tests 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] @@ -23,7 +23,7 @@ internal class UInt64Tests 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] @@ -32,10 +32,12 @@ internal class UInt64Tests const ulong value = 0x0F; byte[] expected = { 0x0F, 0, 0, 0, 0, 0, 0, 0 }; - Span actual = stackalloc byte[8]; - Assert.That(value.TryWriteLittleEndianBytes(actual)); - - CollectionAssert.AreEqual(expected, actual.ToArray()); + Assert.Multiple(() => + { + Span actual = stackalloc byte[8]; + Assert.That(value.TryWriteLittleEndianBytes(actual)); + Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection); + }); } [Test] @@ -44,10 +46,12 @@ internal class UInt64Tests const ulong value = 0x0F; byte[] expected = { 0, 0, 0, 0, 0, 0, 0, 0x0F }; - Span actual = stackalloc byte[8]; - Assert.That(value.TryWriteBigEndianBytes(actual)); - - CollectionAssert.AreEqual(expected, actual.ToArray()); + Assert.Multiple(() => + { + Span actual = stackalloc byte[8]; + Assert.That(value.TryWriteBigEndianBytes(actual)); + Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection); + }); } [Test] diff --git a/X10D.Tests/src/Math/IsPrimeTests.cs b/X10D.Tests/src/Math/IsPrimeTests.cs index 452a286..314bad0 100644 --- a/X10D.Tests/src/Math/IsPrimeTests.cs +++ b/X10D.Tests/src/Math/IsPrimeTests.cs @@ -142,7 +142,7 @@ internal class IsPrimeTests private static IReadOnlyList 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(); diff --git a/X10D.Tests/src/Text/CoreTests.cs b/X10D.Tests/src/Text/CoreTests.cs index 684fa26..679164a 100644 --- a/X10D.Tests/src/Text/CoreTests.cs +++ b/X10D.Tests/src/Text/CoreTests.cs @@ -20,7 +20,11 @@ internal class CoreTests int[] source = Enumerable.Range(1, 100).ToArray(); string json = source.ToJson(); int[]? target = json.FromJson(); - CollectionAssert.AreEqual(source, target); - CollectionAssert.AreEquivalent(source, target); + + Assert.Multiple(() => + { + Assert.That(target, Is.EqualTo(source).AsCollection); + Assert.That(target, Is.EquivalentTo(source)); + }); } } diff --git a/X10D.Tests/src/Text/EnumerableTests.cs b/X10D.Tests/src/Text/EnumerableTests.cs index ab6bfd0..8fbcec2 100644 --- a/X10D.Tests/src/Text/EnumerableTests.cs +++ b/X10D.Tests/src/Text/EnumerableTests.cs @@ -10,13 +10,13 @@ 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] @@ -28,27 +28,27 @@ internal class EnumerableTests 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(); @@ -60,22 +60,28 @@ internal class EnumerableTests public void Grep_ShouldThrowArgumentNullException_GivenNullPattern() { IEnumerable source = Enumerable.Empty(); - Assert.Throws(() => source.Grep(null!).ToArray()); - Assert.Throws(() => source.Grep(null!, false).ToArray()); + Assert.Multiple(() => + { + Assert.Throws(() => source.Grep(null!).ToArray()); + Assert.Throws(() => source.Grep(null!, false).ToArray()); + }); } [Test] public void Grep_ShouldThrowArgumentNullException_GivenNullSource() { IEnumerable source = null!; - Assert.Throws(() => source.Grep("foo").ToArray()); - Assert.Throws(() => source.Grep("foo", false).ToArray()); + Assert.Multiple(() => + { + Assert.Throws(() => source.Grep("foo").ToArray()); + Assert.Throws(() => 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(); diff --git a/X10D.Tests/src/Text/StringBuilderReaderTests.cs b/X10D.Tests/src/Text/StringBuilderReaderTests.cs index 8575511..fc2f60f 100644 --- a/X10D.Tests/src/Text/StringBuilderReaderTests.cs +++ b/X10D.Tests/src/Text/StringBuilderReaderTests.cs @@ -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 span = stackalloc char[5]; - int read = reader.Read(span); - Assert.That(read, Is.EqualTo(5)); + Assert.Multiple(() => + { + Span 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 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 span = stackalloc char[5]; - int read = reader.ReadBlock(span); - Assert.That(read, Is.EqualTo(5)); + Assert.Multiple(() => + { + Span 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 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(); } diff --git a/X10D.Tests/src/Text/StringTests.cs b/X10D.Tests/src/Text/StringTests.cs index d658b72..5c0afe1 100644 --- a/X10D.Tests/src/Text/StringTests.cs +++ b/X10D.Tests/src/Text/StringTests.cs @@ -423,7 +423,7 @@ internal class StringTests var target = json.FromJson(); Assert.Multiple(() => { - Assert.IsInstanceOf(target); + Assert.That(target, Is.InstanceOf()); 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; } } } From 8e6e16700f557badc87f91e4d94b7db24bad0fda Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Wed, 13 Nov 2024 18:45:37 +0000 Subject: [PATCH 12/27] ci: add net9.0 test step --- .github/workflows/dotnet.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 1756f8c..ab038c6 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -38,6 +38,9 @@ jobs: - 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: From bd546e6f04b2af3c7f43dc604e6217d4d2906902 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Wed, 13 Nov 2024 18:56:13 +0000 Subject: [PATCH 13/27] style: use collection expression syntax where applicable --- .../src/Collections/ArrayTests.AsReadOnly.cs | 6 +- .../src/Collections/ArrayTests.Clear.cs | 2 +- X10D.Tests/src/Collections/ByteTests.cs | 2 +- X10D.Tests/src/Collections/Int16Tests.cs | 2 +- X10D.Tests/src/Collections/Int32Tests.cs | 2 +- X10D.Tests/src/Collections/Int64Tests.cs | 2 +- X10D.Tests/src/Collections/ListTests.cs | 30 ++-- X10D.Tests/src/Collections/SpanTest.cs | 10 +- X10D.Tests/src/Core/SpanTest.cs | 154 +++++++++--------- X10D.Tests/src/Drawing/PolygonFTests.cs | 10 +- X10D.Tests/src/Drawing/PolygonTests.cs | 8 +- X10D.Tests/src/Drawing/PolyhedronTests.cs | 8 +- X10D.Tests/src/IO/BooleanTests.cs | 2 +- X10D.Tests/src/IO/ByteTests.cs | 2 +- X10D.Tests/src/IO/DoubleTests.cs | 4 +- X10D.Tests/src/IO/FileInfoTests.cs | 8 +- X10D.Tests/src/IO/Int16Tests.cs | 12 +- X10D.Tests/src/IO/Int32Tests.cs | 4 +- X10D.Tests/src/IO/Int64Tests.cs | 12 +- X10D.Tests/src/IO/SByteTests.cs | 2 +- X10D.Tests/src/IO/SingleTests.cs | 4 +- X10D.Tests/src/IO/StreamTests.ReadDecimal.cs | 12 +- X10D.Tests/src/IO/StreamTests.ReadDouble.cs | 4 +- X10D.Tests/src/IO/StreamTests.ReadInt16.cs | 4 +- X10D.Tests/src/IO/StreamTests.ReadInt32.cs | 4 +- X10D.Tests/src/IO/StreamTests.ReadInt64.cs | 4 +- X10D.Tests/src/IO/StreamTests.ReadSingle.cs | 4 +- X10D.Tests/src/IO/StreamTests.ReadUInt16.cs | 4 +- X10D.Tests/src/IO/StreamTests.ReadUInt32.cs | 4 +- X10D.Tests/src/IO/StreamTests.ReadUInt64.cs | 4 +- X10D.Tests/src/IO/StreamTests.WriteDecimal.cs | 12 +- X10D.Tests/src/IO/StreamTests.WriteDouble.cs | 4 +- X10D.Tests/src/IO/StreamTests.WriteInt16.cs | 4 +- X10D.Tests/src/IO/StreamTests.WriteInt32.cs | 4 +- X10D.Tests/src/IO/StreamTests.WriteInt64.cs | 4 +- X10D.Tests/src/IO/StreamTests.WriteSingle.cs | 4 +- X10D.Tests/src/IO/StreamTests.WriteUInt16.cs | 4 +- X10D.Tests/src/IO/StreamTests.WriteUInt32.cs | 4 +- X10D.Tests/src/IO/StreamTests.WriteUInt64.cs | 4 +- X10D.Tests/src/IO/StreamTests.cs | 12 +- X10D.Tests/src/IO/UInt16Tests.cs | 12 +- X10D.Tests/src/IO/UInt32Tests.cs | 12 +- X10D.Tests/src/IO/UInt64Tests.cs | 12 +- X10D.Tests/src/Linq/EnumerableTests.cs | 6 +- X10D.Tests/src/Linq/ReadOnlySpanTests.cs | 25 +-- X10D.Tests/src/Linq/SpanTests.cs | 32 ++-- X10D.Tests/src/Text/EnumerableTests.cs | 6 +- X10D/src/Core/Extensions.cs | 2 +- X10D/src/Drawing/Polygon.cs | 6 +- X10D/src/Drawing/PolygonF.cs | 8 +- X10D/src/Drawing/Polyhedron.cs | 4 +- 51 files changed, 260 insertions(+), 251 deletions(-) diff --git a/X10D.Tests/src/Collections/ArrayTests.AsReadOnly.cs b/X10D.Tests/src/Collections/ArrayTests.AsReadOnly.cs index f7339d0..c75e5ac 100644 --- a/X10D.Tests/src/Collections/ArrayTests.AsReadOnly.cs +++ b/X10D.Tests/src/Collections/ArrayTests.AsReadOnly.cs @@ -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 result = array.AsReadOnly(); Assert.That(result, Is.InstanceOf>()); } @@ -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 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[] array = []; IReadOnlyCollection result = array.AsReadOnly(); Assert.That(result, Is.Empty); } diff --git a/X10D.Tests/src/Collections/ArrayTests.Clear.cs b/X10D.Tests/src/Collections/ArrayTests.Clear.cs index 509785e..c4a9411 100644 --- a/X10D.Tests/src/Collections/ArrayTests.Clear.cs +++ b/X10D.Tests/src/Collections/ArrayTests.Clear.cs @@ -21,7 +21,7 @@ internal static partial class ArrayTests [Test] public void Clear_ShouldDoNothing_WhenArrayIsEmpty() { - int[] array = Array.Empty(); + int[] array = []; array.Clear(); } diff --git a/X10D.Tests/src/Collections/ByteTests.cs b/X10D.Tests/src/Collections/ByteTests.cs index 304999a..b8662bf 100644 --- a/X10D.Tests/src/Collections/ByteTests.cs +++ b/X10D.Tests/src/Collections/ByteTests.cs @@ -105,7 +105,7 @@ internal class ByteTests Assert.Throws(() => { const byte value = 0b11010100; - Span bits = stackalloc bool[0]; + Span bits = []; value.Unpack(bits); }); } diff --git a/X10D.Tests/src/Collections/Int16Tests.cs b/X10D.Tests/src/Collections/Int16Tests.cs index c01dbe4..9d3bf2e 100644 --- a/X10D.Tests/src/Collections/Int16Tests.cs +++ b/X10D.Tests/src/Collections/Int16Tests.cs @@ -126,7 +126,7 @@ internal class Int16Tests Assert.Throws(() => { const short value = 0b11010100; - Span bits = stackalloc bool[0]; + Span bits = []; value.Unpack(bits); }); } diff --git a/X10D.Tests/src/Collections/Int32Tests.cs b/X10D.Tests/src/Collections/Int32Tests.cs index 0a8ea19..7668ed2 100644 --- a/X10D.Tests/src/Collections/Int32Tests.cs +++ b/X10D.Tests/src/Collections/Int32Tests.cs @@ -156,7 +156,7 @@ internal class Int32Tests Assert.Throws(() => { const int value = 0b11010100; - Span bits = stackalloc bool[0]; + Span bits = []; value.Unpack(bits); }); } diff --git a/X10D.Tests/src/Collections/Int64Tests.cs b/X10D.Tests/src/Collections/Int64Tests.cs index 9862ec8..2aaa7aa 100644 --- a/X10D.Tests/src/Collections/Int64Tests.cs +++ b/X10D.Tests/src/Collections/Int64Tests.cs @@ -70,7 +70,7 @@ internal class Int64Tests { Assert.Throws(() => { - Span bits = stackalloc bool[0]; + Span bits = []; 0b11010100L.Unpack(bits); }); } diff --git a/X10D.Tests/src/Collections/ListTests.cs b/X10D.Tests/src/Collections/ListTests.cs index 469d097..7e2bfc5 100644 --- a/X10D.Tests/src/Collections/ListTests.cs +++ b/X10D.Tests/src/Collections/ListTests.cs @@ -42,7 +42,7 @@ internal class ListTests [Test] public void Fill_ShouldThrow_GivenExceededCount() { - int[] array = Array.Empty(); + int[] array = []; var list = new List(); Assert.Throws(() => array.Fill(0, 0, 1)); Assert.Throws(() => list.Fill(0, 0, 1)); @@ -51,7 +51,7 @@ internal class ListTests [Test] public void Fill_ShouldThrow_GivenNegativeCount() { - int[] array = Array.Empty(); + int[] array = []; var list = new List(); Assert.Throws(() => array.Fill(0, 0, -1)); Assert.Throws(() => list.Fill(0, 0, -1)); @@ -60,7 +60,7 @@ internal class ListTests [Test] public void Fill_ShouldThrow_GivenNegativeStartIndex() { - int[] array = Array.Empty(); + int[] array = []; var list = new List(); Assert.Throws(() => array.Fill(0, -1, 0)); Assert.Throws(() => 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[] 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[] array = []; Assert.Throws(() => array.IndexOf(0, 0, -1)); } [Test] public void IndexOf_ShouldThrowArgumentOutOfRangeException_GivenNegativeStartIndex() { - int[] array = Array.Empty(); + int[] array = []; Assert.Multiple(() => { Assert.Throws(() => 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(() => array.IndexOf(0, 2, 4)); } @@ -233,21 +233,21 @@ internal class ListTests [Test] public void Slice_ShouldReturnCorrectValue_GivenStartIndex() { - int[] array = { 0, 1, 2, 3, 4, 5 }; + 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 }; + 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[] array = []; Assert.That(array.Slice(0).ToArray(), Is.EqualTo(Array.Empty()).AsCollection); Assert.That(array.Slice(0, 0).ToArray(), Is.EqualTo(Array.Empty()).AsCollection); } @@ -263,14 +263,14 @@ internal class ListTests [Test] public void Slice_ShouldThrowArgumentOutOfRangeException_GivenNegativeCount() { - int[] array = Array.Empty(); + int[] array = []; Assert.Throws(() => array.Slice(0, -1)); } [Test] public void Slice_ShouldThrowArgumentOutOfRangeException_GivenNegativeStartIndex() { - int[] array = Array.Empty(); + int[] array = []; Assert.Throws(() => array.Slice(-1)); Assert.Throws(() => 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(() => array.Slice(2, 4)); } diff --git a/X10D.Tests/src/Collections/SpanTest.cs b/X10D.Tests/src/Collections/SpanTest.cs index 47175f0..1f0b58a 100644 --- a/X10D.Tests/src/Collections/SpanTest.cs +++ b/X10D.Tests/src/Collections/SpanTest.cs @@ -31,7 +31,7 @@ internal class SpanTest [Test] public void Count_ShouldReturn8_GivenSpanWith8MatchingElements() { - Span span = stackalloc int[16] { 1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2 }; + Span span = [1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2]; int count = span.Count(2); @@ -41,7 +41,7 @@ internal class SpanTest [Test] public void Count_ShouldReturn8_GivenReadOnlySpanWith8MatchingElements() { - ReadOnlySpan span = stackalloc int[16] { 1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2 }; + ReadOnlySpan span = [1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2]; int count = span.Count(2); @@ -51,7 +51,7 @@ internal class SpanTest [Test] public void Replace_ShouldReplaceAllElements_GivenSpanOfInt32() { - Span span = stackalloc int[16] { 1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2 }; + Span 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 })); } @@ -59,7 +59,7 @@ internal class SpanTest [Test] public void Replace_ShouldReplaceAllElements_GivenSpanOfChar() { - Span chars = stackalloc char[12] { 'H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!' }; + Span chars = ['H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!']; chars.Replace('l', 'w'); Assert.That("Hewwo worwd!".ToCharArray(), Is.EqualTo(chars.ToArray()).AsCollection); } @@ -67,7 +67,7 @@ internal class SpanTest [Test] public void Replace_ShouldDoNothing_GivenSpanWithNoMatchingElements() { - Span span = stackalloc int[16] { 1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2 }; + Span 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 })); } diff --git a/X10D.Tests/src/Core/SpanTest.cs b/X10D.Tests/src/Core/SpanTest.cs index 9b3673b..30a1b23 100644 --- a/X10D.Tests/src/Core/SpanTest.cs +++ b/X10D.Tests/src/Core/SpanTest.cs @@ -12,7 +12,7 @@ internal class SpanTest { Assert.Multiple(() => { - ReadOnlySpan span = stackalloc EnumByte[1] {EnumByte.B}; + ReadOnlySpan span = [EnumByte.B]; Assert.That(span.Contains(EnumByte.A), Is.False); Assert.That(span.Contains(EnumByte.C), Is.False); }); @@ -23,7 +23,7 @@ internal class SpanTest { Assert.Multiple(() => { - ReadOnlySpan span = stackalloc EnumInt16[1] {EnumInt16.B}; + ReadOnlySpan span = [EnumInt16.B]; Assert.That(span.Contains(EnumInt16.A), Is.False); Assert.That(span.Contains(EnumInt16.C), Is.False); }); @@ -34,7 +34,7 @@ internal class SpanTest { Assert.Multiple(() => { - ReadOnlySpan span = stackalloc EnumInt32[1] {EnumInt32.B}; + ReadOnlySpan span = [EnumInt32.B]; Assert.That(span.Contains(EnumInt32.A), Is.False); Assert.That(span.Contains(EnumInt32.C), Is.False); }); @@ -45,7 +45,7 @@ internal class SpanTest { Assert.Multiple(() => { - ReadOnlySpan span = stackalloc EnumInt64[1] {EnumInt64.B}; + ReadOnlySpan span = [EnumInt64.B]; Assert.That(span.Contains(EnumInt64.A), Is.False); Assert.That(span.Contains(EnumInt64.C), Is.False); @@ -55,7 +55,7 @@ internal class SpanTest [Test] public void Contains_ShouldReturnTrue_GivenReadOnlySpanWithMatchingElements_UsingByteEnum() { - ReadOnlySpan span = stackalloc EnumByte[1] {EnumByte.B}; + ReadOnlySpan span = [EnumByte.B]; Assert.That(span.Contains(EnumByte.B)); } @@ -63,7 +63,7 @@ internal class SpanTest [Test] public void Contains_ShouldReturnTrue_GivenReadOnlySpanWithMatchingElements_UsingInt16Enum() { - ReadOnlySpan span = stackalloc EnumInt16[1] {EnumInt16.B}; + ReadOnlySpan span = [EnumInt16.B]; Assert.That(span.Contains(EnumInt16.B)); } @@ -71,7 +71,7 @@ internal class SpanTest [Test] public void Contains_ShouldReturnTrue_GivenReadOnlySpanWithMatchingElements_UsingInt32Enum() { - ReadOnlySpan span = stackalloc EnumInt32[1] {EnumInt32.B}; + ReadOnlySpan span = [EnumInt32.B]; Assert.That(span.Contains(EnumInt32.B)); } @@ -79,7 +79,7 @@ internal class SpanTest [Test] public void Contains_ShouldReturnTrue_GivenReadOnlySpanWithMatchingElements_UsingInt64Enum() { - ReadOnlySpan span = stackalloc EnumInt64[1] {EnumInt64.B}; + ReadOnlySpan span = [EnumInt64.B]; Assert.That(span.Contains(EnumInt64.B)); } @@ -89,7 +89,7 @@ internal class SpanTest { Assert.Multiple(() => { - Span span = stackalloc EnumByte[1] {EnumByte.B}; + Span span = [EnumByte.B]; Assert.That(span.Contains(EnumByte.A), Is.False); Assert.That(span.Contains(EnumByte.C), Is.False); @@ -99,7 +99,7 @@ internal class SpanTest [Test] public void Contains_ShouldReturnFalse_GivenSpanWithNoMatchingElements_UsingInt16Enum() { - Span span = stackalloc EnumInt16[1] {EnumInt16.B}; + Span span = [EnumInt16.B]; Assert.That(span.Contains(EnumInt16.A), Is.False); Assert.That(span.Contains(EnumInt16.C), Is.False); @@ -108,7 +108,7 @@ internal class SpanTest [Test] public void Contains_ShouldReturnFalse_GivenSpanWithNoMatchingElements_UsingInt32Enum() { - Span span = stackalloc EnumInt32[1] {EnumInt32.B}; + Span span = [EnumInt32.B]; Assert.That(span.Contains(EnumInt32.A), Is.False); Assert.That(span.Contains(EnumInt32.C), Is.False); @@ -117,7 +117,7 @@ internal class SpanTest [Test] public void Contains_ShouldReturnFalse_GivenSpanWithNoMatchingElements_UsingInt64Enum() { - Span span = stackalloc EnumInt64[1] {EnumInt64.B}; + Span span = [EnumInt64.B]; Assert.That(span.Contains(EnumInt64.A), Is.False); Assert.That(span.Contains(EnumInt64.C), Is.False); @@ -126,7 +126,7 @@ internal class SpanTest [Test] public void Contains_ShouldReturnTrue_GivenSpanWithMatchingElements_UsingByteEnum() { - Span span = stackalloc EnumByte[1] {EnumByte.B}; + Span span = [EnumByte.B]; Assert.That(span.Contains(EnumByte.B)); } @@ -134,7 +134,7 @@ internal class SpanTest [Test] public void Contains_ShouldReturnTrue_GivenSpanWithMatchingElements_UsingInt16Enum() { - Span span = stackalloc EnumInt16[1] {EnumInt16.B}; + Span span = [EnumInt16.B]; Assert.That(span.Contains(EnumInt16.B)); } @@ -142,7 +142,7 @@ internal class SpanTest [Test] public void Contains_ShouldReturnTrue_GivenSpanWithMatchingElements_UsingInt32Enum() { - Span span = stackalloc EnumInt32[1] {EnumInt32.B}; + Span span = [EnumInt32.B]; Assert.That(span.Contains(EnumInt32.B)); } @@ -150,7 +150,7 @@ internal class SpanTest [Test] public void Contains_ShouldReturnTrue_GivenSpanWithMatchingElements_UsingInt64Enum() { - Span span = stackalloc EnumInt64[1] {EnumInt64.B}; + Span span = [EnumInt64.B]; Assert.That(span.Contains(EnumInt64.B)); } @@ -199,7 +199,7 @@ internal class SpanTest public void PackByteInternal_Fallback_ShouldReturnCorrectByte_GivenReadOnlySpan_Using() { const byte expected = 0b00110011; - ReadOnlySpan span = stackalloc bool[8] {true, true, false, false, true, true, false, false}; + ReadOnlySpan span = [true, true, false, false, true, true, false, false]; byte actual = span.PackByteInternal_Fallback(); @@ -215,7 +215,7 @@ internal class SpanTest } const byte expected = 0b00110011; - ReadOnlySpan span = stackalloc bool[8] {true, true, false, false, true, true, false, false}; + ReadOnlySpan span = [true, true, false, false, true, true, false, false]; byte actual = span.PackByteInternal_Sse2(); @@ -225,7 +225,7 @@ internal class SpanTest [Test] public void PackInt16_ShouldReturnSameAsPackByte_WhenSpanHasLength8() { - ReadOnlySpan span = stackalloc bool[8] {true, true, false, false, true, true, false, false}; + ReadOnlySpan span = [true, true, false, false, true, true, false, false]; short expected = span.PackByte(); short actual = span.PackInt16(); @@ -237,10 +237,10 @@ internal class SpanTest public void PackInt16Internal_Fallback_ShouldReturnCorrectInt16_GivenReadOnlySpan() { const short expected = 0b00101101_11010100; - ReadOnlySpan span = stackalloc bool[16] - { - false, false, true, false, true, false, true, true, true, false, true, true, false, true, false, false, - }; + ReadOnlySpan span = + [ + false, false, true, false, true, false, true, true, true, false, true, true, false, true, false, false + ]; short actual = span.PackInt16Internal_Fallback(); @@ -256,10 +256,10 @@ internal class SpanTest } const short expected = 0b00101101_11010100; - ReadOnlySpan span = stackalloc bool[16] - { - false, false, true, false, true, false, true, true, true, false, true, true, false, true, false, false, - }; + ReadOnlySpan span = + [ + false, false, true, false, true, false, true, true, true, false, true, true, false, true, false, false + ]; short actual = span.PackInt16Internal_Sse2(); @@ -270,11 +270,11 @@ internal class SpanTest public void PackInt32Internal_Fallback_ShouldReturnCorrectInt32_GivenReadOnlySpan() { const int expected = 0b01010101_10101010_01010101_10101010; - ReadOnlySpan span = stackalloc bool[32] - { + ReadOnlySpan 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(); @@ -290,11 +290,11 @@ internal class SpanTest } const int expected = 0b01010101_10101010_01010101_10101010; - ReadOnlySpan span = stackalloc bool[32] - { + ReadOnlySpan 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(); @@ -310,11 +310,11 @@ internal class SpanTest } const int expected = 0b01010101_10101010_01010101_10101010; - ReadOnlySpan span = stackalloc bool[32] - { + ReadOnlySpan 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(); @@ -324,7 +324,7 @@ internal class SpanTest [Test] public void PackInt32_ShouldReturnSameAsPackByte_WhenSpanHasLength8_UsingReadOnlySpan() { - ReadOnlySpan span = stackalloc bool[8] {true, true, false, false, true, true, false, false}; + ReadOnlySpan span = [true, true, false, false, true, true, false, false]; int expected = span.PackByte(); int actual = span.PackInt32(); @@ -335,7 +335,7 @@ internal class SpanTest [Test] public void PackInt32_ShouldReturnSameAsPackByte_WhenSpanHasLength8_UsingSpan() { - Span span = stackalloc bool[8] {true, true, false, false, true, true, false, false}; + Span span = [true, true, false, false, true, true, false, false]; int expected = span.PackByte(); int actual = span.PackInt32(); @@ -346,10 +346,10 @@ internal class SpanTest [Test] public void PackInt32_ShouldReturnSameAsPackInt16_WhenSpanHasLength16_UsingReadOnlySpan() { - ReadOnlySpan span = stackalloc bool[16] - { - false, false, true, false, true, false, true, true, true, false, true, true, false, true, false, false, - }; + ReadOnlySpan 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(); @@ -360,10 +360,10 @@ internal class SpanTest [Test] public void PackInt32_ShouldReturnSameAsPackInt16_WhenSpanHasLength16_UsingSpan() { - Span span = stackalloc bool[16] - { - false, false, true, false, true, false, true, true, true, false, true, true, false, true, false, false, - }; + Span 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(); @@ -375,13 +375,13 @@ internal class SpanTest public void PackInt64_ShouldReturnCorrectInt64_GivenReadOnlySpan() { const long expected = 0b01010101_11010110_01101001_11010110_00010010_10010111_00101100_10100101; - ReadOnlySpan span = stackalloc bool[64] - { + ReadOnlySpan 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(); @@ -392,13 +392,13 @@ internal class SpanTest public void PackInt64_ShouldReturnCorrectInt64_GivenSpan() { const long expected = 0b01010101_11010110_01101001_11010110_00010010_10010111_00101100_10100101; - Span span = stackalloc bool[64] - { + Span 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(); @@ -408,7 +408,7 @@ internal class SpanTest [Test] public void PackInt64_ShouldReturnSameAsPackByte_WhenSpanHasLength8_UsingReadOnlySpan() { - ReadOnlySpan span = stackalloc bool[8] {true, true, false, false, true, true, false, false}; + ReadOnlySpan span = [true, true, false, false, true, true, false, false]; long expected = span.PackByte(); long actual = span.PackInt64(); @@ -419,7 +419,7 @@ internal class SpanTest [Test] public void PackInt64_ShouldReturnSameAsPackByte_WhenSpanHasLength8_UsingSpan() { - Span span = stackalloc bool[8] {true, true, false, false, true, true, false, false}; + Span span = [true, true, false, false, true, true, false, false]; long expected = span.PackByte(); long actual = span.PackInt64(); @@ -430,10 +430,10 @@ internal class SpanTest [Test] public void PackInt64_ShouldReturnSameAsPackInt16_WhenSpanHasLength16_UsingReadOnlySpan() { - ReadOnlySpan span = stackalloc bool[16] - { - false, false, true, false, true, false, true, true, true, false, true, true, false, true, false, false, - }; + ReadOnlySpan 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(); @@ -444,10 +444,10 @@ internal class SpanTest [Test] public void PackInt64_ShouldReturnSameAsPackInt16_WhenSpanHasLength16_UsingSpan() { - Span span = stackalloc bool[16] - { - false, false, true, false, true, false, true, true, true, false, true, true, false, true, false, false, - }; + Span 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(); @@ -458,11 +458,11 @@ internal class SpanTest [Test] public void PackInt64_ShouldReturnSameAsPackInt32_WhenSpanHasLength16_UsingReadOnlySpan() { - ReadOnlySpan span = stackalloc bool[32] - { + ReadOnlySpan 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(); @@ -473,11 +473,11 @@ internal class SpanTest [Test] public void PackInt64_ShouldReturnSameAsPackInt32_WhenSpanHasLength16_UsingSpan() { - Span span = stackalloc bool[32] - { + Span 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(); @@ -489,7 +489,7 @@ internal class SpanTest public void PackInt64_ShouldFallbackAndReturnCorrectValue_GivenNonPowerOfTwoLength_UsingReadOnlySpan() { const long expected = 0b00000000_00000000_00000000_00000000_00000000_00000000_00000001_01010011; - ReadOnlySpan span = stackalloc bool[10] {true, true, false, false, true, false, true, false, true, false}; + ReadOnlySpan span = [true, true, false, false, true, false, true, false, true, false]; long actual = span.PackInt64(); @@ -500,7 +500,7 @@ internal class SpanTest public void PackInt64_ShouldFallbackAndReturnCorrectValue_GivenNonPowerOfTwoLength_UsingSpan() { const long expected = 0b00000000_00000000_00000000_00000000_00000000_00000000_00000001_01010011; - Span span = stackalloc bool[10] {true, true, false, false, true, false, true, false, true, false}; + Span span = [true, true, false, false, true, false, true, false, true, false]; long actual = span.PackInt64(); diff --git a/X10D.Tests/src/Drawing/PolygonFTests.cs b/X10D.Tests/src/Drawing/PolygonFTests.cs index a5c54fe..287434e 100644 --- a/X10D.Tests/src/Drawing/PolygonFTests.cs +++ b/X10D.Tests/src/Drawing/PolygonFTests.cs @@ -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)); diff --git a/X10D.Tests/src/Drawing/PolygonTests.cs b/X10D.Tests/src/Drawing/PolygonTests.cs index 50fe6d8..539ec1c 100644 --- a/X10D.Tests/src/Drawing/PolygonTests.cs +++ b/X10D.Tests/src/Drawing/PolygonTests.cs @@ -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)); diff --git a/X10D.Tests/src/Drawing/PolyhedronTests.cs b/X10D.Tests/src/Drawing/PolyhedronTests.cs index 4a81ec7..d244362 100644 --- a/X10D.Tests/src/Drawing/PolyhedronTests.cs +++ b/X10D.Tests/src/Drawing/PolyhedronTests.cs @@ -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(() => diff --git a/X10D.Tests/src/IO/BooleanTests.cs b/X10D.Tests/src/IO/BooleanTests.cs index 99bd606..55557d7 100644 --- a/X10D.Tests/src/IO/BooleanTests.cs +++ b/X10D.Tests/src/IO/BooleanTests.cs @@ -26,7 +26,7 @@ internal class BooleanTests public void TryWriteBytes_ReturnsFalse_GivenSmallSpan() { const bool value = true; - Span buffer = stackalloc byte[0]; + Span buffer = []; Assert.That(value.TryWriteBytes(buffer), Is.False); } } diff --git a/X10D.Tests/src/IO/ByteTests.cs b/X10D.Tests/src/IO/ByteTests.cs index 1c9d1c9..61ed158 100644 --- a/X10D.Tests/src/IO/ByteTests.cs +++ b/X10D.Tests/src/IO/ByteTests.cs @@ -29,7 +29,7 @@ internal class ByteTests public void TryWriteBytes_ReturnsFalse_GivenSmallSpan() { const byte value = 0x0F; - Span buffer = stackalloc byte[0]; + Span buffer = []; Assert.That(value.TryWriteBytes(buffer), Is.False); } } diff --git a/X10D.Tests/src/IO/DoubleTests.cs b/X10D.Tests/src/IO/DoubleTests.cs index 99ae227..4168bfa 100644 --- a/X10D.Tests/src/IO/DoubleTests.cs +++ b/X10D.Tests/src/IO/DoubleTests.cs @@ -58,7 +58,7 @@ internal class DoubleTests public void TryWriteBigEndian_ReturnsFalse_GivenSmallSpan() { const double value = 42.5; - Span buffer = stackalloc byte[0]; + Span buffer = []; Assert.That(value.TryWriteBigEndianBytes(buffer), Is.False); } @@ -66,7 +66,7 @@ internal class DoubleTests public void TryWriteLittleEndian_RReturnsFalse_GivenSmallSpan() { const double value = 42.5; - Span buffer = stackalloc byte[0]; + Span buffer = []; Assert.That(value.TryWriteLittleEndianBytes(buffer), Is.False); } } diff --git a/X10D.Tests/src/IO/FileInfoTests.cs b/X10D.Tests/src/IO/FileInfoTests.cs index aff685e..1d8df95 100644 --- a/X10D.Tests/src/IO/FileInfoTests.cs +++ b/X10D.Tests/src/IO/FileInfoTests.cs @@ -21,10 +21,10 @@ 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 { @@ -51,10 +51,10 @@ 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 { diff --git a/X10D.Tests/src/IO/Int16Tests.cs b/X10D.Tests/src/IO/Int16Tests.cs index ad6a146..6d8d94f 100644 --- a/X10D.Tests/src/IO/Int16Tests.cs +++ b/X10D.Tests/src/IO/Int16Tests.cs @@ -11,7 +11,7 @@ internal class Int16Tests { const short value = 0x0F; - byte[] expected = { 0x0F, 0 }; + byte[] expected = [0x0F, 0]; byte[] actual = value.GetLittleEndianBytes(); Assert.That(actual, Is.EqualTo(expected).AsCollection); } @@ -21,7 +21,7 @@ internal class Int16Tests { const short value = 0x0F; - byte[] expected = { 0, 0x0F }; + byte[] expected = [0, 0x0F]; byte[] actual = value.GetBigEndianBytes(); Assert.That(actual, Is.EqualTo(expected).AsCollection); } @@ -31,7 +31,7 @@ internal class Int16Tests { const short value = 0x0F; - byte[] expected = { 0x0F, 0 }; + byte[] expected = [0x0F, 0]; Assert.Multiple(() => { Span actual = stackalloc byte[2]; @@ -45,7 +45,7 @@ internal class Int16Tests { const short value = 0x0F; - byte[] expected = { 0, 0x0F }; + byte[] expected = [0, 0x0F]; Assert.Multiple(() => { Span actual = stackalloc byte[2]; @@ -58,7 +58,7 @@ internal class Int16Tests public void TryWriteLittleEndian_RReturnsFalse_GivenSmallSpan() { const short value = 0x0F; - Span buffer = stackalloc byte[0]; + Span buffer = []; Assert.That(value.TryWriteLittleEndianBytes(buffer), Is.False); } @@ -66,7 +66,7 @@ internal class Int16Tests public void TryWriteBigEndian_ReturnsFalse_GivenSmallSpan() { const short value = 0x0F; - Span buffer = stackalloc byte[0]; + Span buffer = []; Assert.That(value.TryWriteBigEndianBytes(buffer), Is.False); } } diff --git a/X10D.Tests/src/IO/Int32Tests.cs b/X10D.Tests/src/IO/Int32Tests.cs index 634426f..021b37a 100644 --- a/X10D.Tests/src/IO/Int32Tests.cs +++ b/X10D.Tests/src/IO/Int32Tests.cs @@ -58,7 +58,7 @@ internal class Int32Tests public void TryWriteBigEndian_ReturnsFalse_GivenSmallSpan() { const int value = 0x0F; - Span buffer = stackalloc byte[0]; + Span buffer = []; Assert.That(value.TryWriteBigEndianBytes(buffer), Is.False); } @@ -66,7 +66,7 @@ internal class Int32Tests public void TryWriteLittleEndian_RReturnsFalse_GivenSmallSpan() { const int value = 0x0F; - Span buffer = stackalloc byte[0]; + Span buffer = []; Assert.That(value.TryWriteLittleEndianBytes(buffer), Is.False); } } diff --git a/X10D.Tests/src/IO/Int64Tests.cs b/X10D.Tests/src/IO/Int64Tests.cs index d4751be..2cdd8ba 100644 --- a/X10D.Tests/src/IO/Int64Tests.cs +++ b/X10D.Tests/src/IO/Int64Tests.cs @@ -11,7 +11,7 @@ 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(); Assert.That(actual, Is.EqualTo(expected).AsCollection); } @@ -21,7 +21,7 @@ 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(); Assert.That(actual, Is.EqualTo(expected).AsCollection); } @@ -31,7 +31,7 @@ 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]; Assert.Multiple(() => { Span actual = stackalloc byte[8]; @@ -45,7 +45,7 @@ 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]; Assert.Multiple(() => { Span actual = stackalloc byte[8]; @@ -58,7 +58,7 @@ internal class Int64Tests public void TryWriteLittleEndian_RReturnsFalse_GivenSmallSpan() { const long value = 0x0F; - Span buffer = stackalloc byte[0]; + Span buffer = []; Assert.That(value.TryWriteLittleEndianBytes(buffer), Is.False); } @@ -66,7 +66,7 @@ internal class Int64Tests public void TryWriteBigEndian_ReturnsFalse_GivenSmallSpan() { const long value = 0x0F; - Span buffer = stackalloc byte[0]; + Span buffer = []; Assert.That(value.TryWriteBigEndianBytes(buffer), Is.False); } } diff --git a/X10D.Tests/src/IO/SByteTests.cs b/X10D.Tests/src/IO/SByteTests.cs index e7d3d6e..fe15ad4 100644 --- a/X10D.Tests/src/IO/SByteTests.cs +++ b/X10D.Tests/src/IO/SByteTests.cs @@ -29,7 +29,7 @@ internal class SByteTests public void TryWriteBytes_ReturnsFalse_GivenSmallSpan() { const sbyte value = 0x0F; - Span buffer = stackalloc byte[0]; + Span buffer = []; Assert.That(value.TryWriteBytes(buffer), Is.False); } } diff --git a/X10D.Tests/src/IO/SingleTests.cs b/X10D.Tests/src/IO/SingleTests.cs index 1dd325a..cea5f8b 100644 --- a/X10D.Tests/src/IO/SingleTests.cs +++ b/X10D.Tests/src/IO/SingleTests.cs @@ -58,7 +58,7 @@ internal class SingleTests public void TryWriteBigEndian_ReturnsFalse_GivenSmallSpan() { const float value = 42.5f; - Span buffer = stackalloc byte[0]; + Span buffer = []; Assert.That(value.TryWriteBigEndianBytes(buffer), Is.False); } @@ -66,7 +66,7 @@ internal class SingleTests public void TryWriteLittleEndian_RReturnsFalse_GivenSmallSpan() { const float value = 42.5f; - Span buffer = stackalloc byte[0]; + Span buffer = []; Assert.That(value.TryWriteLittleEndianBytes(buffer), Is.False); } } diff --git a/X10D.Tests/src/IO/StreamTests.ReadDecimal.cs b/X10D.Tests/src/IO/StreamTests.ReadDecimal.cs index c7fcdb5..55468ac 100644 --- a/X10D.Tests/src/IO/StreamTests.ReadDecimal.cs +++ b/X10D.Tests/src/IO/StreamTests.ReadDecimal.cs @@ -40,10 +40,10 @@ internal partial class StreamTests public void ReadDecimalBigEndian_ShouldReadBigEndian() { using var stream = new MemoryStream(); - ReadOnlySpan bytes = stackalloc byte[] - { + ReadOnlySpan 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 bytes = stackalloc byte[] - { + ReadOnlySpan bytes = + [ 0x68, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00 - }; + ]; stream.Write(bytes); stream.Position = 0; diff --git a/X10D.Tests/src/IO/StreamTests.ReadDouble.cs b/X10D.Tests/src/IO/StreamTests.ReadDouble.cs index 02f7991..7615fda 100644 --- a/X10D.Tests/src/IO/StreamTests.ReadDouble.cs +++ b/X10D.Tests/src/IO/StreamTests.ReadDouble.cs @@ -40,7 +40,7 @@ internal partial class StreamTests public void ReadDoubleBigEndian_ShouldReadBigEndian() { using var stream = new MemoryStream(); - ReadOnlySpan bytes = stackalloc byte[] { 0x40, 0x7A, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00 }; + ReadOnlySpan 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 bytes = stackalloc byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x7A, 0x40 }; + ReadOnlySpan bytes = [0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x7A, 0x40]; stream.Write(bytes); stream.Position = 0; diff --git a/X10D.Tests/src/IO/StreamTests.ReadInt16.cs b/X10D.Tests/src/IO/StreamTests.ReadInt16.cs index a71d4bd..61e3224 100644 --- a/X10D.Tests/src/IO/StreamTests.ReadInt16.cs +++ b/X10D.Tests/src/IO/StreamTests.ReadInt16.cs @@ -40,7 +40,7 @@ internal partial class StreamTests public void ReadInt16BigEndian_ShouldReadBigEndian() { using var stream = new MemoryStream(); - ReadOnlySpan bytes = stackalloc byte[] { 0x01, 0xA4 }; + ReadOnlySpan 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 bytes = stackalloc byte[] { 0xA4, 0x01 }; + ReadOnlySpan bytes = [0xA4, 0x01]; stream.Write(bytes); stream.Position = 0; diff --git a/X10D.Tests/src/IO/StreamTests.ReadInt32.cs b/X10D.Tests/src/IO/StreamTests.ReadInt32.cs index e51ef95..29b0660 100644 --- a/X10D.Tests/src/IO/StreamTests.ReadInt32.cs +++ b/X10D.Tests/src/IO/StreamTests.ReadInt32.cs @@ -40,7 +40,7 @@ internal partial class StreamTests public void ReadInt32BigEndian_ShouldReadBigEndian() { using var stream = new MemoryStream(); - ReadOnlySpan bytes = stackalloc byte[] { 0x00, 0x00, 0x01, 0xA4 }; + ReadOnlySpan 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 bytes = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00 }; + ReadOnlySpan bytes = [0xA4, 0x01, 0x00, 0x00]; stream.Write(bytes); stream.Position = 0; diff --git a/X10D.Tests/src/IO/StreamTests.ReadInt64.cs b/X10D.Tests/src/IO/StreamTests.ReadInt64.cs index faebfda..b8d2688 100644 --- a/X10D.Tests/src/IO/StreamTests.ReadInt64.cs +++ b/X10D.Tests/src/IO/StreamTests.ReadInt64.cs @@ -37,7 +37,7 @@ internal partial class StreamTests public void ReadInt64BigEndian_ShouldReadBigEndian() { using var stream = new MemoryStream(); - ReadOnlySpan bytes = stackalloc byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xA4 }; + ReadOnlySpan 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 bytes = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + ReadOnlySpan bytes = [0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; stream.Write(bytes); stream.Position = 0; diff --git a/X10D.Tests/src/IO/StreamTests.ReadSingle.cs b/X10D.Tests/src/IO/StreamTests.ReadSingle.cs index ff2336b..76707e1 100644 --- a/X10D.Tests/src/IO/StreamTests.ReadSingle.cs +++ b/X10D.Tests/src/IO/StreamTests.ReadSingle.cs @@ -40,7 +40,7 @@ internal partial class StreamTests public void ReadSingleBigEndian_ShouldReadBigEndian() { using var stream = new MemoryStream(); - ReadOnlySpan bytes = stackalloc byte[] { 0x43, 0xD2, 0x00, 0x00 }; + ReadOnlySpan 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 bytes = stackalloc byte[] { 0x00, 0x00, 0xD2, 0x43 }; + ReadOnlySpan bytes = [0x00, 0x00, 0xD2, 0x43]; stream.Write(bytes); stream.Position = 0; diff --git a/X10D.Tests/src/IO/StreamTests.ReadUInt16.cs b/X10D.Tests/src/IO/StreamTests.ReadUInt16.cs index 0cd249d..bc7b2ae 100644 --- a/X10D.Tests/src/IO/StreamTests.ReadUInt16.cs +++ b/X10D.Tests/src/IO/StreamTests.ReadUInt16.cs @@ -40,7 +40,7 @@ internal partial class StreamTests public void ReadUInt16BigEndian_ShouldReadBigEndian() { using var stream = new MemoryStream(); - ReadOnlySpan bytes = stackalloc byte[] { 0x01, 0xA4 }; + ReadOnlySpan 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 bytes = stackalloc byte[] { 0xA4, 0x01 }; + ReadOnlySpan bytes = [0xA4, 0x01]; stream.Write(bytes); stream.Position = 0; diff --git a/X10D.Tests/src/IO/StreamTests.ReadUInt32.cs b/X10D.Tests/src/IO/StreamTests.ReadUInt32.cs index 3164afe..fb83278 100644 --- a/X10D.Tests/src/IO/StreamTests.ReadUInt32.cs +++ b/X10D.Tests/src/IO/StreamTests.ReadUInt32.cs @@ -40,7 +40,7 @@ internal partial class StreamTests public void ReadUInt32BigEndian_ShouldReadBigEndian() { using var stream = new MemoryStream(); - ReadOnlySpan bytes = stackalloc byte[] { 0x00, 0x00, 0x01, 0xA4 }; + ReadOnlySpan 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 bytes = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00 }; + ReadOnlySpan bytes = [0xA4, 0x01, 0x00, 0x00]; stream.Write(bytes); stream.Position = 0; diff --git a/X10D.Tests/src/IO/StreamTests.ReadUInt64.cs b/X10D.Tests/src/IO/StreamTests.ReadUInt64.cs index ca33b01..eed8a58 100644 --- a/X10D.Tests/src/IO/StreamTests.ReadUInt64.cs +++ b/X10D.Tests/src/IO/StreamTests.ReadUInt64.cs @@ -40,7 +40,7 @@ internal partial class StreamTests public void ReadUInt64BigEndian_ShouldReadBigEndian() { using var stream = new MemoryStream(); - ReadOnlySpan bytes = stackalloc byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xA4 }; + ReadOnlySpan 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 bytes = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + ReadOnlySpan bytes = [0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; stream.Write(bytes); stream.Position = 0; diff --git a/X10D.Tests/src/IO/StreamTests.WriteDecimal.cs b/X10D.Tests/src/IO/StreamTests.WriteDecimal.cs index 91aed0d..018b977 100644 --- a/X10D.Tests/src/IO/StreamTests.WriteDecimal.cs +++ b/X10D.Tests/src/IO/StreamTests.WriteDecimal.cs @@ -48,10 +48,10 @@ internal partial class StreamTests Assert.Multiple(() => { Span actual = stackalloc byte[16]; - ReadOnlySpan expected = stackalloc byte[] - { + ReadOnlySpan 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())); @@ -71,10 +71,10 @@ internal partial class StreamTests Assert.Multiple(() => { Span actual = stackalloc byte[16]; - ReadOnlySpan expected = stackalloc byte[] - { + ReadOnlySpan 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}"))); diff --git a/X10D.Tests/src/IO/StreamTests.WriteDouble.cs b/X10D.Tests/src/IO/StreamTests.WriteDouble.cs index ba82011..948bd43 100644 --- a/X10D.Tests/src/IO/StreamTests.WriteDouble.cs +++ b/X10D.Tests/src/IO/StreamTests.WriteDouble.cs @@ -47,7 +47,7 @@ internal partial class StreamTests Assert.Multiple(() => { Span actual = stackalloc byte[8]; - ReadOnlySpan expected = stackalloc byte[] { 0x40, 0x7A, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00 }; + ReadOnlySpan expected = [0x40, 0x7A, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00]; int read = stream.Read(actual); Assert.That(read, Is.EqualTo(8)); @@ -66,7 +66,7 @@ internal partial class StreamTests Assert.Multiple(() => { Span actual = stackalloc byte[8]; - ReadOnlySpan expected = stackalloc byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x7A, 0x40 }; + ReadOnlySpan expected = [0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x7A, 0x40]; int read = stream.Read(actual); Assert.That(read, Is.EqualTo(8)); diff --git a/X10D.Tests/src/IO/StreamTests.WriteInt16.cs b/X10D.Tests/src/IO/StreamTests.WriteInt16.cs index a49513b..69df715 100644 --- a/X10D.Tests/src/IO/StreamTests.WriteInt16.cs +++ b/X10D.Tests/src/IO/StreamTests.WriteInt16.cs @@ -47,7 +47,7 @@ internal partial class StreamTests Assert.Multiple(() => { Span actual = stackalloc byte[2]; - ReadOnlySpan expected = stackalloc byte[] { 0x01, 0xA4 }; + ReadOnlySpan expected = [0x01, 0xA4]; int read = stream.Read(actual); Assert.That(read, Is.EqualTo(2)); @@ -66,7 +66,7 @@ internal partial class StreamTests Assert.Multiple(() => { Span actual = stackalloc byte[2]; - ReadOnlySpan expected = stackalloc byte[] { 0xA4, 0x01 }; + ReadOnlySpan expected = [0xA4, 0x01]; int read = stream.Read(actual); Assert.That(read, Is.EqualTo(2)); diff --git a/X10D.Tests/src/IO/StreamTests.WriteInt32.cs b/X10D.Tests/src/IO/StreamTests.WriteInt32.cs index 7534e2e..38adbe2 100644 --- a/X10D.Tests/src/IO/StreamTests.WriteInt32.cs +++ b/X10D.Tests/src/IO/StreamTests.WriteInt32.cs @@ -47,7 +47,7 @@ internal partial class StreamTests Assert.Multiple(() => { Span actual = stackalloc byte[4]; - ReadOnlySpan expected = stackalloc byte[] { 0x00, 0x00, 0x01, 0xA4 }; + ReadOnlySpan expected = [0x00, 0x00, 0x01, 0xA4]; int read = stream.Read(actual); Assert.That(read, Is.EqualTo(4)); @@ -66,7 +66,7 @@ internal partial class StreamTests Assert.Multiple(() => { Span actual = stackalloc byte[4]; - ReadOnlySpan expected = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00 }; + ReadOnlySpan expected = [0xA4, 0x01, 0x00, 0x00]; int read = stream.Read(actual); Assert.That(read, Is.EqualTo(4)); diff --git a/X10D.Tests/src/IO/StreamTests.WriteInt64.cs b/X10D.Tests/src/IO/StreamTests.WriteInt64.cs index 3a3fea5..d6292ed 100644 --- a/X10D.Tests/src/IO/StreamTests.WriteInt64.cs +++ b/X10D.Tests/src/IO/StreamTests.WriteInt64.cs @@ -47,7 +47,7 @@ internal partial class StreamTests Assert.Multiple(() => { Span actual = stackalloc byte[8]; - ReadOnlySpan expected = stackalloc byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xA4 }; + ReadOnlySpan expected = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xA4]; int read = stream.Read(actual); Assert.That(read, Is.EqualTo(8)); @@ -66,7 +66,7 @@ internal partial class StreamTests Assert.Multiple(() => { Span actual = stackalloc byte[8]; - ReadOnlySpan expected = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + ReadOnlySpan expected = [0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; int read = stream.Read(actual); Assert.That(read, Is.EqualTo(8)); diff --git a/X10D.Tests/src/IO/StreamTests.WriteSingle.cs b/X10D.Tests/src/IO/StreamTests.WriteSingle.cs index b9a6db0..734225d 100644 --- a/X10D.Tests/src/IO/StreamTests.WriteSingle.cs +++ b/X10D.Tests/src/IO/StreamTests.WriteSingle.cs @@ -47,7 +47,7 @@ internal partial class StreamTests Assert.Multiple(() => { Span actual = stackalloc byte[4]; - ReadOnlySpan expected = stackalloc byte[] { 0x43, 0xD2, 0x00, 0x00 }; + ReadOnlySpan expected = [0x43, 0xD2, 0x00, 0x00]; int read = stream.Read(actual); Assert.That(read, Is.EqualTo(4)); @@ -66,7 +66,7 @@ internal partial class StreamTests Assert.Multiple(() => { Span actual = stackalloc byte[4]; - ReadOnlySpan expected = stackalloc byte[] { 0x00, 0x00, 0xD2, 0x43 }; + ReadOnlySpan expected = [0x00, 0x00, 0xD2, 0x43]; int read = stream.Read(actual); Assert.That(read, Is.EqualTo(4)); diff --git a/X10D.Tests/src/IO/StreamTests.WriteUInt16.cs b/X10D.Tests/src/IO/StreamTests.WriteUInt16.cs index 4f0be3d..926b29c 100644 --- a/X10D.Tests/src/IO/StreamTests.WriteUInt16.cs +++ b/X10D.Tests/src/IO/StreamTests.WriteUInt16.cs @@ -47,7 +47,7 @@ internal partial class StreamTests Assert.Multiple(() => { Span actual = stackalloc byte[2]; - ReadOnlySpan expected = stackalloc byte[] { 0x01, 0xA4 }; + ReadOnlySpan expected = [0x01, 0xA4]; int read = stream.Read(actual); Assert.That(read, Is.EqualTo(2)); @@ -66,7 +66,7 @@ internal partial class StreamTests Assert.Multiple(() => { Span actual = stackalloc byte[2]; - ReadOnlySpan expected = stackalloc byte[] { 0xA4, 0x01 }; + ReadOnlySpan expected = [0xA4, 0x01]; int read = stream.Read(actual); Assert.That(read, Is.EqualTo(2)); diff --git a/X10D.Tests/src/IO/StreamTests.WriteUInt32.cs b/X10D.Tests/src/IO/StreamTests.WriteUInt32.cs index 2c58155..5888969 100644 --- a/X10D.Tests/src/IO/StreamTests.WriteUInt32.cs +++ b/X10D.Tests/src/IO/StreamTests.WriteUInt32.cs @@ -47,7 +47,7 @@ internal partial class StreamTests Assert.Multiple(() => { Span actual = stackalloc byte[4]; - ReadOnlySpan expected = stackalloc byte[] { 0x00, 0x00, 0x01, 0xA4 }; + ReadOnlySpan expected = [0x00, 0x00, 0x01, 0xA4]; int read = stream.Read(actual); Assert.That(read, Is.EqualTo(4)); @@ -66,7 +66,7 @@ internal partial class StreamTests Assert.Multiple(() => { Span actual = stackalloc byte[4]; - ReadOnlySpan expected = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00 }; + ReadOnlySpan expected = [0xA4, 0x01, 0x00, 0x00]; int read = stream.Read(actual); Assert.That(read, Is.EqualTo(4)); diff --git a/X10D.Tests/src/IO/StreamTests.WriteUInt64.cs b/X10D.Tests/src/IO/StreamTests.WriteUInt64.cs index 349f489..38e1fbc 100644 --- a/X10D.Tests/src/IO/StreamTests.WriteUInt64.cs +++ b/X10D.Tests/src/IO/StreamTests.WriteUInt64.cs @@ -47,7 +47,7 @@ internal partial class StreamTests Assert.Multiple(() => { Span actual = stackalloc byte[8]; - ReadOnlySpan expected = stackalloc byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xA4 }; + ReadOnlySpan expected = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xA4]; int read = stream.Read(actual); Assert.That(read, Is.EqualTo(8)); @@ -66,7 +66,7 @@ internal partial class StreamTests Assert.Multiple(() => { Span actual = stackalloc byte[8]; - ReadOnlySpan expected = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + ReadOnlySpan expected = [0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; int read = stream.Read(actual); Assert.That(read, Is.EqualTo(8)); diff --git a/X10D.Tests/src/IO/StreamTests.cs b/X10D.Tests/src/IO/StreamTests.cs index 2857c16..64775aa 100644 --- a/X10D.Tests/src/IO/StreamTests.cs +++ b/X10D.Tests/src/IO/StreamTests.cs @@ -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")); @@ -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")); @@ -160,7 +160,7 @@ internal partial class StreamTests protected override byte[] HashFinal() { - return Array.Empty(); + return []; } public override void Initialize() @@ -176,7 +176,7 @@ internal partial class StreamTests protected override byte[] HashFinal() { - return Array.Empty(); + return []; } public override void Initialize() diff --git a/X10D.Tests/src/IO/UInt16Tests.cs b/X10D.Tests/src/IO/UInt16Tests.cs index e646553..ccbbd1e 100644 --- a/X10D.Tests/src/IO/UInt16Tests.cs +++ b/X10D.Tests/src/IO/UInt16Tests.cs @@ -10,7 +10,7 @@ internal class UInt16Tests public void GetLittleEndianBytes_ReturnsCorrectValue_WithEndianness() { const ushort value = 0x0F; - byte[] expected = { 0x0F, 0 }; + byte[] expected = [0x0F, 0]; byte[] actual = value.GetLittleEndianBytes(); Assert.That(actual, Is.EqualTo(expected).AsCollection); @@ -20,7 +20,7 @@ internal class UInt16Tests public void GetBigEndianBytes_ReturnsCorrectValue_WithEndianness() { const ushort value = 0x0F; - byte[] expected = { 0, 0x0F }; + byte[] expected = [0, 0x0F]; byte[] actual = value.GetBigEndianBytes(); Assert.That(actual, Is.EqualTo(expected).AsCollection); @@ -30,7 +30,7 @@ internal class UInt16Tests public void TryWriteLittleEndian_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan() { const ushort value = 0x0F; - byte[] expected = { 0x0F, 0 }; + byte[] expected = [0x0F, 0]; Assert.Multiple(() => { @@ -44,7 +44,7 @@ internal class UInt16Tests public void TryWriteBigEndian_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan() { const ushort value = 0x0F; - byte[] expected = { 0, 0x0F }; + byte[] expected = [0, 0x0F]; Assert.Multiple(() => { @@ -58,7 +58,7 @@ internal class UInt16Tests public void TryWriteLittleEndian_RReturnsFalse_GivenSmallSpan() { const ushort value = 0x0F; - Span buffer = stackalloc byte[0]; + Span buffer = []; Assert.That(value.TryWriteLittleEndianBytes(buffer), Is.False); } @@ -66,7 +66,7 @@ internal class UInt16Tests public void TryWriteBigEndian_ReturnsFalse_GivenSmallSpan() { const ushort value = 0x0F; - Span buffer = stackalloc byte[0]; + Span buffer = []; Assert.That(value.TryWriteBigEndianBytes(buffer), Is.False); } } diff --git a/X10D.Tests/src/IO/UInt32Tests.cs b/X10D.Tests/src/IO/UInt32Tests.cs index 588f2fb..582bf5f 100644 --- a/X10D.Tests/src/IO/UInt32Tests.cs +++ b/X10D.Tests/src/IO/UInt32Tests.cs @@ -10,7 +10,7 @@ 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(); Assert.That(actual, Is.EqualTo(expected).AsCollection); @@ -20,7 +20,7 @@ internal class UInt32Tests 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(); Assert.That(actual, Is.EqualTo(expected).AsCollection); @@ -30,7 +30,7 @@ internal class UInt32Tests public void TryWriteLittleEndian_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan() { const uint value = 0x0F; - byte[] expected = { 0x0F, 0, 0, 0 }; + byte[] expected = [0x0F, 0, 0, 0]; Assert.Multiple(() => { @@ -44,7 +44,7 @@ internal class UInt32Tests public void TryWriteBigEndian_ReturnsTrue_FillsSpanCorrectly_GivenLargeEnoughSpan() { const uint value = 0x0F; - byte[] expected = { 0, 0, 0, 0x0F }; + byte[] expected = [0, 0, 0, 0x0F]; Assert.Multiple(() => { @@ -58,7 +58,7 @@ internal class UInt32Tests public void TryWriteLittleEndian_RReturnsFalse_GivenSmallSpan() { const uint value = 0x0F; - Span buffer = stackalloc byte[0]; + Span buffer = []; Assert.That(value.TryWriteLittleEndianBytes(buffer), Is.False); } @@ -66,7 +66,7 @@ internal class UInt32Tests public void TryWriteBigEndian_ReturnsFalse_GivenSmallSpan() { const uint value = 0x0F; - Span buffer = stackalloc byte[0]; + Span buffer = []; Assert.That(value.TryWriteBigEndianBytes(buffer), Is.False); } } diff --git a/X10D.Tests/src/IO/UInt64Tests.cs b/X10D.Tests/src/IO/UInt64Tests.cs index 07e38f4..54f3e1e 100644 --- a/X10D.Tests/src/IO/UInt64Tests.cs +++ b/X10D.Tests/src/IO/UInt64Tests.cs @@ -10,7 +10,7 @@ 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(); Assert.That(actual, Is.EqualTo(expected).AsCollection); @@ -20,7 +20,7 @@ internal class UInt64Tests 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(); Assert.That(actual, Is.EqualTo(expected).AsCollection); @@ -30,7 +30,7 @@ internal class UInt64Tests 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]; Assert.Multiple(() => { @@ -44,7 +44,7 @@ internal class UInt64Tests 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]; Assert.Multiple(() => { @@ -58,7 +58,7 @@ internal class UInt64Tests public void TryWriteLittleEndian_RReturnsFalse_GivenSmallSpan() { const ulong value = 0x0F; - Span buffer = stackalloc byte[0]; + Span buffer = []; Assert.That(value.TryWriteLittleEndianBytes(buffer), Is.False); } @@ -66,7 +66,7 @@ internal class UInt64Tests public void TryWriteBigEndian_ReturnsFalse_GivenSmallSpan() { const ulong value = 0x0F; - Span buffer = stackalloc byte[0]; + Span buffer = []; Assert.That(value.TryWriteBigEndianBytes(buffer), Is.False); } } diff --git a/X10D.Tests/src/Linq/EnumerableTests.cs b/X10D.Tests/src/Linq/EnumerableTests.cs index 84e0378..6d55bb0 100644 --- a/X10D.Tests/src/Linq/EnumerableTests.cs +++ b/X10D.Tests/src/Linq/EnumerableTests.cs @@ -112,7 +112,7 @@ internal class EnumerableTests [Test] public void MinMax_ShouldThrowArgumentNullException_GivenNullSelector() { - IEnumerable source = Enumerable.Empty(); + IEnumerable source = []; Assert.Throws(() => source.MinMax((Func)(null!))); Assert.Throws(() => source.MinMax((Func)(null!), null)); } @@ -201,13 +201,13 @@ internal class EnumerableTests { Assert.Throws(() => { - IEnumerable source = Enumerable.Empty(); + IEnumerable source = []; _ = source.MinMaxBy(p => p.Age); }); Assert.Throws(() => { - Person[] source = Array.Empty(); + Person[] source = []; _ = source.MinMaxBy(p => p.Age); }); } diff --git a/X10D.Tests/src/Linq/ReadOnlySpanTests.cs b/X10D.Tests/src/Linq/ReadOnlySpanTests.cs index 2b6ab5f..56b0ffa 100644 --- a/X10D.Tests/src/Linq/ReadOnlySpanTests.cs +++ b/X10D.Tests/src/Linq/ReadOnlySpanTests.cs @@ -9,29 +9,32 @@ internal class ReadOnlySpanTests [Test] public void AllShouldReturnTrueForEmptySpan() { - var span = new ReadOnlySpan(); + ReadOnlySpan span = []; Assert.That(span.All(x => x > 0)); } [Test] public void AllShouldBeCorrect() { - var span = new ReadOnlySpan(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 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(); + ReadOnlySpan span = []; Assert.That(span.Any(x => x > 0), Is.False); } [Test] public void AnyShouldBeCorrect() { - var span = new ReadOnlySpan(new[] { 2, 4, 6, 8, 10 }); + ReadOnlySpan 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(() => { - var span = new ReadOnlySpan(); + ReadOnlySpan span = []; _ = span.All(null!); }); } @@ -51,7 +54,7 @@ internal class ReadOnlySpanTests { Assert.Throws(() => { - var span = new ReadOnlySpan(); + ReadOnlySpan span = []; _ = span.Any(null!); }); } @@ -59,14 +62,14 @@ internal class ReadOnlySpanTests [Test] public void Count_ShouldReturn0_GivenEmptySpan() { - var span = new ReadOnlySpan(); + ReadOnlySpan span = []; Assert.That(span.Count(i => i % 2 == 0), Is.Zero); } [Test] public void Count_ShouldReturn5_ForEvenNumbers_GivenNumbers1To10() { - var span = new ReadOnlySpan(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); + ReadOnlySpan 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(() => { - var span = new ReadOnlySpan(); + ReadOnlySpan span = []; _ = span.Count((Predicate)null!); }); } diff --git a/X10D.Tests/src/Linq/SpanTests.cs b/X10D.Tests/src/Linq/SpanTests.cs index 186d0e8..71dc782 100644 --- a/X10D.Tests/src/Linq/SpanTests.cs +++ b/X10D.Tests/src/Linq/SpanTests.cs @@ -9,31 +9,37 @@ internal class SpanTests [Test] public void AllShouldReturnTrueForEmptySpan() { - var span = new Span(); + Span span = []; Assert.That(span.All(x => x > 0)); } [Test] public void AllShouldBeCorrect() { - var span = new Span(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 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(); + Span span = []; Assert.That(span.Any(x => x > 0), Is.False); } [Test] public void AnyShouldBeCorrect() { - var span = new Span(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 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(() => { - var span = new Span(); + Span span = []; _ = span.All(null!); }); } @@ -51,7 +57,7 @@ internal class SpanTests { Assert.Throws(() => { - var span = new Span(); + Span span = []; _ = span.Any(null!); }); } @@ -59,14 +65,14 @@ internal class SpanTests [Test] public void Count_ShouldReturn0_GivenEmptySpan() { - var span = new Span(); + Span span = []; Assert.That(span.Count(i => i % 2 == 0), Is.Zero); } [Test] public void Count_ShouldReturn5_ForEvenNumbers_GivenNumbers1To10() { - var span = new Span(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); + Span 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(() => { - var span = new Span(); + Span span = []; _ = span.Count((Predicate)null!); }); } diff --git a/X10D.Tests/src/Text/EnumerableTests.cs b/X10D.Tests/src/Text/EnumerableTests.cs index 8fbcec2..6cf6fad 100644 --- a/X10D.Tests/src/Text/EnumerableTests.cs +++ b/X10D.Tests/src/Text/EnumerableTests.cs @@ -22,8 +22,8 @@ internal class EnumerableTests [Test] public void Grep_ShouldYieldNoResults_GivenEmptySource() { - string[] source = Array.Empty(); - string[] expectedResult = Array.Empty(); + string[] source = []; + string[] expectedResult = []; const string pattern = /*lang=regex*/@"[0-9]+"; string[] actualResult = source.Grep(pattern).ToArray(); @@ -59,7 +59,7 @@ internal class EnumerableTests [Test] public void Grep_ShouldThrowArgumentNullException_GivenNullPattern() { - IEnumerable source = Enumerable.Empty(); + IEnumerable source = []; Assert.Multiple(() => { Assert.Throws(() => source.Grep(null!).ToArray()); diff --git a/X10D/src/Core/Extensions.cs b/X10D/src/Core/Extensions.cs index df3969f..78c9118 100644 --- a/X10D/src/Core/Extensions.cs +++ b/X10D/src/Core/Extensions.cs @@ -18,7 +18,7 @@ public static class Extensions [Pure] public static T[] AsArrayValue(this T value) { - return new[] {value}; + return [value]; } /// diff --git a/X10D/src/Drawing/Polygon.cs b/X10D/src/Drawing/Polygon.cs index e3b6519..e27318b 100644 --- a/X10D/src/Drawing/Polygon.cs +++ b/X10D/src/Drawing/Polygon.cs @@ -8,7 +8,7 @@ namespace X10D.Drawing; /// public class Polygon : IEquatable { - private readonly List _vertices = new(); + private readonly List _vertices = []; /// /// Initializes a new instance of the class. @@ -27,7 +27,7 @@ public class Polygon : IEquatable throw new ArgumentNullException(nameof(polygon)); } - _vertices = new List(); + _vertices = []; for (var index = 0; index < polygon._vertices.Count; index++) { Point vertex = polygon._vertices[index]; @@ -46,7 +46,7 @@ public class Polygon : IEquatable throw new ArgumentNullException(nameof(vertices)); } - _vertices = new List(vertices); + _vertices = [..vertices]; } /// diff --git a/X10D/src/Drawing/PolygonF.cs b/X10D/src/Drawing/PolygonF.cs index 7499db9..5e84988 100644 --- a/X10D/src/Drawing/PolygonF.cs +++ b/X10D/src/Drawing/PolygonF.cs @@ -10,7 +10,7 @@ namespace X10D.Drawing; /// public class PolygonF { - private readonly List _vertices = new(); + private readonly List _vertices = []; /// /// Initializes a new instance of the class. @@ -29,7 +29,7 @@ public class PolygonF { throw new ArgumentNullException(nameof(polygon)); } - _vertices = new List(); + _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(); + _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(vertices); + _vertices = [..vertices]; } /// diff --git a/X10D/src/Drawing/Polyhedron.cs b/X10D/src/Drawing/Polyhedron.cs index f968cd9..8a71bbd 100644 --- a/X10D/src/Drawing/Polyhedron.cs +++ b/X10D/src/Drawing/Polyhedron.cs @@ -9,7 +9,7 @@ namespace X10D.Drawing; /// public class Polyhedron : IEquatable { - private readonly List _vertices = new(); + private readonly List _vertices = []; /// /// Initializes a new instance of the class. @@ -39,7 +39,7 @@ public class Polyhedron : IEquatable throw new ArgumentNullException(nameof(vertices)); } - _vertices = new List(vertices); + _vertices = [..vertices]; } /// From 8c2b5f38e61e2fadd8ccf573d42044f1b3abd6bf Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Wed, 13 Nov 2024 19:00:49 +0000 Subject: [PATCH 14/27] style: target c# 13 langversion --- CONTRIBUTING.md | 4 ++-- Directory.Build.props | 2 +- tools/Directory.Build.props | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a6b5007..21cb59d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 diff --git a/Directory.Build.props b/Directory.Build.props index 283ddde..2e583e9 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,6 @@ - 12.0 + 13.0 true true true diff --git a/tools/Directory.Build.props b/tools/Directory.Build.props index 52b14ee..51aa142 100644 --- a/tools/Directory.Build.props +++ b/tools/Directory.Build.props @@ -1,6 +1,6 @@ - 11.0 + 13.0 enable true true From 0d6153d39d8b9188d4bf445504823861c4a77462 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Wed, 13 Nov 2024 19:04:19 +0000 Subject: [PATCH 15/27] feat: add slnx file (#93) This file does not remove the need to keep the .sln file as CI/CD still relies on the classic format for build --- X10D.slnx | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 X10D.slnx diff --git a/X10D.slnx b/X10D.slnx new file mode 100644 index 0000000..21a062d --- /dev/null +++ b/X10D.slnx @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From b1c644dc4789676256c034041c7d9487228d3889 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Thu, 14 Nov 2024 16:01:11 +0000 Subject: [PATCH 16/27] refactor!: replace Product and RangeTo on int types with generic math --- CHANGELOG.md | 7 ++ X10D.Tests/src/Linq/ByteTests.cs | 47 +-------- X10D.Tests/src/Linq/Int16Tests.cs | 34 +----- X10D.Tests/src/Linq/Int32Tests.cs | 16 +-- X10D.Tests/src/Linq/Int64Tests.cs | 2 +- X10D/src/Linq/ByteExtensions.cs | 161 ----------------------------- X10D/src/Linq/DecimalExtensions.cs | 42 -------- X10D/src/Linq/DoubleExtensions.cs | 42 -------- X10D/src/Linq/Int16Extensions.cs | 117 --------------------- X10D/src/Linq/Int32Extensions.cs | 121 ---------------------- X10D/src/Linq/Int64Extensions.cs | 101 ------------------ X10D/src/Linq/NumberExtensions.cs | 72 +++++++++++++ X10D/src/Linq/SingleExtensions.cs | 42 -------- 13 files changed, 83 insertions(+), 721 deletions(-) delete mode 100644 X10D/src/Linq/ByteExtensions.cs delete mode 100644 X10D/src/Linq/DecimalExtensions.cs delete mode 100644 X10D/src/Linq/DoubleExtensions.cs delete mode 100644 X10D/src/Linq/Int16Extensions.cs delete mode 100644 X10D/src/Linq/Int32Extensions.cs delete mode 100644 X10D/src/Linq/Int64Extensions.cs create mode 100644 X10D/src/Linq/NumberExtensions.cs delete mode 100644 X10D/src/Linq/SingleExtensions.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 521a00e..08abffd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## 4.0.1 - [Unreleased] +### Changed + +- X10D: Removed `byte.Product`, `short.Product`, `ushort.Product`, `int.Product`, `uint.Product`, `long.Product`, + and `ulong.Product`, in favour of `INumber.Product`. +- X10D: Removed `byte.RangeTo`, `short.RangeTo`, `ushort.RangeTo`, `int.RangeTo`, `uint.RangeTo`, `long.RangeTo`, +and `ulong.RangeTo`, in favour of `INumber.RangeTo`. + ### Removed - X10D: Removed `Span.Split` for .NET 9.0 target due to conflicts with diff --git a/X10D.Tests/src/Linq/ByteTests.cs b/X10D.Tests/src/Linq/ByteTests.cs index a3b79e2..bbd69c0 100644 --- a/X10D.Tests/src/Linq/ByteTests.cs +++ b/X10D.Tests/src/Linq/ByteTests.cs @@ -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)); - } } diff --git a/X10D.Tests/src/Linq/Int16Tests.cs b/X10D.Tests/src/Linq/Int16Tests.cs index 1401d9e..1c8c3c9 100644 --- a/X10D.Tests/src/Linq/Int16Tests.cs +++ b/X10D.Tests/src/Linq/Int16Tests.cs @@ -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)); - } } diff --git a/X10D.Tests/src/Linq/Int32Tests.cs b/X10D.Tests/src/Linq/Int32Tests.cs index 783cbba..9d5f0b3 100644 --- a/X10D.Tests/src/Linq/Int32Tests.cs +++ b/X10D.Tests/src/Linq/Int32Tests.cs @@ -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)); - } } diff --git a/X10D.Tests/src/Linq/Int64Tests.cs b/X10D.Tests/src/Linq/Int64Tests.cs index c55f74d..9cd525b 100644 --- a/X10D.Tests/src/Linq/Int64Tests.cs +++ b/X10D.Tests/src/Linq/Int64Tests.cs @@ -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; diff --git a/X10D/src/Linq/ByteExtensions.cs b/X10D/src/Linq/ByteExtensions.cs deleted file mode 100644 index 992507c..0000000 --- a/X10D/src/Linq/ByteExtensions.cs +++ /dev/null @@ -1,161 +0,0 @@ -using System.Diagnostics.Contracts; - -namespace X10D.Linq; - -/// -/// LINQ-inspired extension methods for of . -/// -public static class ByteExtensions -{ - /// - /// Computes the product of a sequence of values. - /// - /// A sequence of values that are used to calculate the product. - /// The product the values in the sequence. - /// is . - public static byte Product(this IEnumerable source) - { - if (source is null) - { - throw new ArgumentNullException(nameof(source)); - } - - return source.Aggregate((byte)1, (current, value) => (byte)(current * value)); - } - - /// - /// Computes the product of a sequence of values. - /// - /// A sequence of values that are used to calculate the product. - /// The product the values in the sequence. - /// is . - [CLSCompliant(false)] - public static sbyte Product(this IEnumerable source) - { - if (source is null) - { - throw new ArgumentNullException(nameof(source)); - } - - return source.Aggregate((sbyte)1, (current, value) => (sbyte)(current * value)); - } - - /// - /// Computes the product of a sequence of values that are obtained by invoking a transform function - /// on each element of the input sequence. - /// - /// A sequence of values that are used to calculate a product. - /// A transform function to apply to each element. - /// The type of the elements of . - /// The product of the projected values. - /// is . - public static byte Product(this IEnumerable source, Func selector) - { - if (source is null) - { - throw new ArgumentNullException(nameof(source)); - } - - return source.Select(selector).Product(); - } - - /// - /// Computes the product of a sequence of values that are obtained by invoking a transform function - /// on each element of the input sequence. - /// - /// A sequence of values that are used to calculate a product. - /// A transform function to apply to each element. - /// The type of the elements of . - /// The product of the projected values. - /// is . - [CLSCompliant(false)] - public static sbyte Product(this IEnumerable source, Func selector) - { - if (source is null) - { - throw new ArgumentNullException(nameof(source)); - } - - return source.Select(selector).Product(); - } - - /// - /// Returns an enumerable sequence of 8-bit integers ranging from the current value to a specified value. - /// - /// The starting value of the sequence. - /// The ending value of the sequence. - /// - /// An enumerable collection of 8-bit integers, ranging from to . - /// - [Pure] - public static IEnumerable 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; - } - } - - /// - /// Returns an enumerable sequence of 16-bit integers ranging from the current value to a specified value. - /// - /// The starting value of the sequence. - /// The ending value of the sequence. - /// - /// An enumerable collection of 16-bit integers, ranging from to . - /// - [Pure] - public static IEnumerable 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; - } - } - - /// - /// Returns an enumerable sequence of 32-bit integers ranging from the current value to a specified value. - /// - /// The starting value of the sequence. - /// The ending value of the sequence. - /// - /// An enumerable collection of 32-bit integers, ranging from to . - /// - [Pure] - public static IEnumerable 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; - } - } - - /// - /// Returns an enumerable sequence of 64-bit integers ranging from the current value to a specified value. - /// - /// The starting value of the sequence. - /// The ending value of the sequence. - /// - /// An enumerable collection of 64-bit integers, ranging from to . - /// - [Pure] - public static IEnumerable 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; - } - } -} diff --git a/X10D/src/Linq/DecimalExtensions.cs b/X10D/src/Linq/DecimalExtensions.cs deleted file mode 100644 index 16ca5e9..0000000 --- a/X10D/src/Linq/DecimalExtensions.cs +++ /dev/null @@ -1,42 +0,0 @@ -namespace X10D.Linq; - -/// -/// LINQ-inspired extension methods for of . -/// -public static class DecimalExtensions -{ - /// - /// Computes the product of a sequence of values. - /// - /// A sequence of values that are used to calculate the product. - /// The product the values in the sequence. - /// is . - public static decimal Product(this IEnumerable source) - { - if (source is null) - { - throw new ArgumentNullException(nameof(source)); - } - - return source.Aggregate(1m, (current, value) => (current * value)); - } - - /// - /// Computes the product of a sequence of values that are obtained by invoking a transform function - /// on each element of the input sequence. - /// - /// A sequence of values that are used to calculate a product. - /// A transform function to apply to each element. - /// The type of the elements of . - /// The product of the projected values. - /// is . - public static decimal Product(this IEnumerable source, Func selector) - { - if (source is null) - { - throw new ArgumentNullException(nameof(source)); - } - - return source.Select(selector).Product(); - } -} diff --git a/X10D/src/Linq/DoubleExtensions.cs b/X10D/src/Linq/DoubleExtensions.cs deleted file mode 100644 index 464a0d6..0000000 --- a/X10D/src/Linq/DoubleExtensions.cs +++ /dev/null @@ -1,42 +0,0 @@ -namespace X10D.Linq; - -/// -/// LINQ-inspired extension methods for of . -/// -public static class DoubleExtensions -{ - /// - /// Computes the product of a sequence of values. - /// - /// A sequence of values that are used to calculate the product. - /// The product the values in the sequence. - /// is . - public static double Product(this IEnumerable source) - { - if (source is null) - { - throw new ArgumentNullException(nameof(source)); - } - - return source.Aggregate(1.0, (current, value) => (current * value)); - } - - /// - /// Computes the product of a sequence of values that are obtained by invoking a transform function - /// on each element of the input sequence. - /// - /// A sequence of values that are used to calculate a product. - /// A transform function to apply to each element. - /// The type of the elements of . - /// The product of the projected values. - /// is . - public static double Product(this IEnumerable source, Func selector) - { - if (source is null) - { - throw new ArgumentNullException(nameof(source)); - } - - return source.Select(selector).Product(); - } -} diff --git a/X10D/src/Linq/Int16Extensions.cs b/X10D/src/Linq/Int16Extensions.cs deleted file mode 100644 index 46e082e..0000000 --- a/X10D/src/Linq/Int16Extensions.cs +++ /dev/null @@ -1,117 +0,0 @@ -using System.Diagnostics.Contracts; - -namespace X10D.Linq; - -/// -/// LINQ-inspired extension methods for of . -/// -public static class Int16Extensions -{ - /// - /// Computes the product of a sequence of values. - /// - /// A sequence of values that are used to calculate the product. - /// The product the values in the sequence. - public static short Product(this IEnumerable source) - { - return source.Aggregate((short)1, (current, value) => (short)(current * value)); - } - - /// - /// Computes the product of a sequence of values. - /// - /// A sequence of values that are used to calculate the product. - /// The product the values in the sequence. - [CLSCompliant(false)] - public static ushort Product(this IEnumerable source) - { - return source.Aggregate((ushort)1, (current, value) => (ushort)(current * value)); - } - - /// - /// Computes the product of a sequence of values that are obtained by invoking a transform function - /// on each element of the input sequence. - /// - /// A sequence of values that are used to calculate a product. - /// A transform function to apply to each element. - /// The type of the elements of . - /// The product of the projected values. - public static short Product(this IEnumerable source, Func selector) - { - return source.Select(selector).Product(); - } - - /// - /// Computes the product of a sequence of values that are obtained by invoking a transform function - /// on each element of the input sequence. - /// - /// A sequence of values that are used to calculate a product. - /// A transform function to apply to each element. - /// The type of the elements of . - /// The product of the projected values. - [CLSCompliant(false)] - public static ushort Product(this IEnumerable source, Func selector) - { - return source.Select(selector).Product(); - } - - /// - /// Returns an enumerable sequence of 16-bit integers ranging from the current value to a specified value. - /// - /// The starting value of the sequence. - /// The ending value of the sequence. - /// - /// An enumerable collection of 16-bit integers, ranging from to . - /// - [Pure] - public static IEnumerable 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; - } - } - - /// - /// Returns an enumerable sequence of 32-bit integers ranging from the current value to a specified value. - /// - /// The starting value of the sequence. - /// The ending value of the sequence. - /// - /// An enumerable collection of 32-bit integers, ranging from to . - /// - [Pure] - public static IEnumerable 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; - } - } - - /// - /// Returns an enumerable sequence of 64-bit integers ranging from the current value to a specified value. - /// - /// The starting value of the sequence. - /// The ending value of the sequence. - /// - /// An enumerable collection of 64-bit integers, ranging from to . - /// - [Pure] - public static IEnumerable 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; - } - } -} diff --git a/X10D/src/Linq/Int32Extensions.cs b/X10D/src/Linq/Int32Extensions.cs deleted file mode 100644 index 3aca60b..0000000 --- a/X10D/src/Linq/Int32Extensions.cs +++ /dev/null @@ -1,121 +0,0 @@ -using System.Diagnostics.Contracts; - -namespace X10D.Linq; - -/// -/// LINQ-inspired extension methods for of . -/// -public static class Int32Extensions -{ - /// - /// Computes the product of a sequence of values. - /// - /// A sequence of values that are used to calculate the product. - /// The product the values in the sequence. - /// is . - public static int Product(this IEnumerable source) - { - if (source is null) - { - throw new ArgumentNullException(nameof(source)); - } - - return source.Aggregate(1, (current, value) => current * value); - } - - /// - /// Computes the product of a sequence of values. - /// - /// A sequence of values that are used to calculate the product. - /// The product the values in the sequence. - /// is . - [CLSCompliant(false)] - public static uint Product(this IEnumerable source) - { - if (source is null) - { - throw new ArgumentNullException(nameof(source)); - } - - return source.Aggregate(1u, (current, value) => current * value); - } - - /// - /// Computes the product of a sequence of values that are obtained by invoking a transform function on - /// each element of the input sequence. - /// - /// A sequence of values that are used to calculate a product. - /// A transform function to apply to each element. - /// The type of the elements of . - /// The product of the projected values. - /// is . - public static int Product(this IEnumerable source, Func selector) - { - if (source is null) - { - throw new ArgumentNullException(nameof(source)); - } - - return source.Select(selector).Product(); - } - - /// - /// Computes the product of a sequence of values that are obtained by invoking a transform function on - /// each element of the input sequence. - /// - /// A sequence of values that are used to calculate a product. - /// A transform function to apply to each element. - /// The type of the elements of . - /// The product of the projected values. - /// is . - [CLSCompliant(false)] - public static uint Product(this IEnumerable source, Func selector) - { - if (source is null) - { - throw new ArgumentNullException(nameof(source)); - } - - return source.Select(selector).Product(); - } - - /// - /// Returns an enumerable sequence of 32-bit integers ranging from the current value to a specified value. - /// - /// The starting value of the sequence. - /// The ending value of the sequence. - /// - /// An enumerable collection of 32-bit integers, ranging from to . - /// - [Pure] - public static IEnumerable 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; - } - } - - /// - /// Returns an enumerable sequence of 64-bit integers ranging from the current value to a specified value. - /// - /// The starting value of the sequence. - /// The ending value of the sequence. - /// - /// An enumerable collection of 64-bit integers, ranging from to . - /// - [Pure] - public static IEnumerable 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; - } - } -} diff --git a/X10D/src/Linq/Int64Extensions.cs b/X10D/src/Linq/Int64Extensions.cs deleted file mode 100644 index 53dcf8f..0000000 --- a/X10D/src/Linq/Int64Extensions.cs +++ /dev/null @@ -1,101 +0,0 @@ -using System.Diagnostics.Contracts; - -namespace X10D.Linq; - -/// -/// LINQ-inspired extension methods for of . -/// -public static class Int64Extensions -{ - /// - /// Computes the product of a sequence of values. - /// - /// A sequence of values that are used to calculate the product. - /// The product the values in the sequence. - /// is . - public static long Product(this IEnumerable source) - { - if (source is null) - { - throw new ArgumentNullException(nameof(source)); - } - - return source.Aggregate(1L, (current, value) => current * value); - } - - /// - /// Computes the product of a sequence of values. - /// - /// A sequence of values that are used to calculate the product. - /// The product the values in the sequence. - /// is . - [CLSCompliant(false)] - public static ulong Product(this IEnumerable source) - { - if (source is null) - { - throw new ArgumentNullException(nameof(source)); - } - - return source.Aggregate(1UL, (current, value) => current * value); - } - - /// - /// Computes the product of a sequence of values that are obtained by invoking a transform function on - /// each element of the input sequence. - /// - /// A sequence of values that are used to calculate a product. - /// A transform function to apply to each element. - /// The type of the elements of . - /// The product of the projected values. - /// is . - public static long Product(this IEnumerable source, Func selector) - { - if (source is null) - { - throw new ArgumentNullException(nameof(source)); - } - - return source.Select(selector).Product(); - } - - /// - /// Computes the product of a sequence of values that are obtained by invoking a transform function - /// on each element of the input sequence. - /// - /// A sequence of values that are used to calculate a product. - /// A transform function to apply to each element. - /// The type of the elements of . - /// The product of the projected values. - /// is . - [CLSCompliant(false)] - public static ulong Product(this IEnumerable source, Func selector) - { - if (source is null) - { - throw new ArgumentNullException(nameof(source)); - } - - return source.Select(selector).Product(); - } - - /// - /// Returns an enumerable sequence of 64-bit integers ranging from the current value to a specified value. - /// - /// The starting value of the sequence. - /// The ending value of the sequence. - /// - /// An enumerable collection of 64-bit integers, ranging from to . - /// - [Pure] - public static IEnumerable 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; - } - } -} diff --git a/X10D/src/Linq/NumberExtensions.cs b/X10D/src/Linq/NumberExtensions.cs new file mode 100644 index 0000000..a3d0668 --- /dev/null +++ b/X10D/src/Linq/NumberExtensions.cs @@ -0,0 +1,72 @@ +using System.Diagnostics.Contracts; +using System.Numerics; + +namespace X10D.Linq; + +/// +/// LINQ-inspired extension methods for of . +/// +public static class NumberExtensions +{ + /// + /// Computes the product of a sequence of values. + /// + /// A sequence of values that are used to calculate the product. + /// The type of the number for which to compute the product. + /// The product the values in the sequence. + /// is . + public static TNumber Product(this IEnumerable source) + where TNumber : INumber + { + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } + + return source.Aggregate(TNumber.MultiplicativeIdentity, (current, value) => current * value); + } + + /// + /// Computes the product of a sequence of values that are obtained by invoking a transform + /// function on each element of the input sequence. + /// + /// A sequence of values that are used to calculate a product. + /// A transform function to apply to each element. + /// The type of the elements of . + /// The type of the number for which to compute the product. + /// The product of the projected values. + /// is . + public static TNumber Product(this IEnumerable source, Func selector) + where TNumber : INumber + { + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } + + return source.Select(selector).Product(); + } + + /// + /// Returns an enumerable sequence of numbers ranging from the current value to a specified value. + /// + /// The starting value of the sequence. + /// The ending value of the sequence. + /// The type of the number for which to compute the product. + /// + /// An enumerable collection of , ranging from to + /// . + /// + [Pure] + public static IEnumerable RangeTo(this TNumber value, TNumber end) + where TNumber : INumber + { + TNumber start = TNumber.Min(value, end); + end = TNumber.Max(value, end); + + for (TNumber current = start; current < end; current++) + { + yield return current; + } + } +} diff --git a/X10D/src/Linq/SingleExtensions.cs b/X10D/src/Linq/SingleExtensions.cs deleted file mode 100644 index 2e873af..0000000 --- a/X10D/src/Linq/SingleExtensions.cs +++ /dev/null @@ -1,42 +0,0 @@ -namespace X10D.Linq; - -/// -/// LINQ-inspired extension methods for of . -/// -public static class SingleExtensions -{ - /// - /// Computes the product of a sequence of values. - /// - /// A sequence of values that are used to calculate the product. - /// The product the values in the sequence. - /// is . - public static float Product(this IEnumerable source) - { - if (source is null) - { - throw new ArgumentNullException(nameof(source)); - } - - return source.Aggregate(1f, (current, value) => (current * value)); - } - - /// - /// Computes the product of a sequence of values that are obtained by invoking a transform function - /// on each element of the input sequence. - /// - /// A sequence of values that are used to calculate a product. - /// A transform function to apply to each element. - /// The type of the elements of . - /// The product of the projected values. - /// is . - public static float Product(this IEnumerable source, Func selector) - { - if (source is null) - { - throw new ArgumentNullException(nameof(source)); - } - - return source.Select(selector).Product(); - } -} From 024f6dbd7a0ca3746469bc639ded89234239be47 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Thu, 14 Nov 2024 16:01:46 +0000 Subject: [PATCH 17/27] chore: bump to 4.1.0 --- Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index 2e583e9..1ca3524 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -8,7 +8,7 @@ true pdbonly true - 4.0.0 + 4.1.0 Oliver Booth enable en From c7e78f5d195e0209871515c5332af2e1382f8cec Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Thu, 14 Nov 2024 16:06:52 +0000 Subject: [PATCH 18/27] refactor: fix logic for IBinaryInteger.Factorial The algorithm now starts at IBinaryInteger.MultiplicativeIdentity rather than IBinaryInteger.One --- CHANGELOG.md | 2 ++ X10D/src/Math/BinaryIntegerExtensions.cs | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08abffd..0d2a7ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- X1OD: `IBinaryInteger.Factorial` now starts at `IBinaryInteger.MultiplicativeIdentity` not +`IBinaryInteger.One`. - X10D: Removed `byte.Product`, `short.Product`, `ushort.Product`, `int.Product`, `uint.Product`, `long.Product`, and `ulong.Product`, in favour of `INumber.Product`. - X10D: Removed `byte.RangeTo`, `short.RangeTo`, `ushort.RangeTo`, `int.RangeTo`, `uint.RangeTo`, `long.RangeTo`, diff --git a/X10D/src/Math/BinaryIntegerExtensions.cs b/X10D/src/Math/BinaryIntegerExtensions.cs index 2d09419..cce2bd1 100644 --- a/X10D/src/Math/BinaryIntegerExtensions.cs +++ b/X10D/src/Math/BinaryIntegerExtensions.cs @@ -69,13 +69,13 @@ public static class BinaryIntegerExtensions return 1; } - var result = 1L; + TInteger result = TInteger.MultiplicativeIdentity; for (TInteger i = TInteger.One; i <= value; i++) { - result *= long.CreateChecked(i); + result *= i; } - return result; + return long.CreateChecked(result); } /// From 0be10d819f48207ae4b4a46f2860dd595c3e1da1 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Thu, 14 Nov 2024 16:14:50 +0000 Subject: [PATCH 19/27] refactor!: replace GCF and LCM with generic math --- CHANGELOG.md | 8 ++-- X10D/src/Math/BigIntegerExtensions.cs | 46 ----------------------- X10D/src/Math/BinaryIntegerExtensions.cs | 19 ---------- X10D/src/Math/ByteExtensions.cs | 13 ------- X10D/src/Math/Int16Extensions.cs | 13 ------- X10D/src/Math/Int32Extensions.cs | 13 ------- X10D/src/Math/Int64Extensions.cs | 28 -------------- X10D/src/Math/NumberExtensions.cs | 48 ++++++++++++++++++++++++ X10D/src/Math/SByteExtensions.cs | 13 ------- X10D/src/Math/UInt16Extensions.cs | 14 ------- X10D/src/Math/UInt32Extensions.cs | 14 ------- X10D/src/Math/UInt64Extensions.cs | 29 -------------- 12 files changed, 52 insertions(+), 206 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d2a7ff..1564404 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,10 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - X1OD: `IBinaryInteger.Factorial` now starts at `IBinaryInteger.MultiplicativeIdentity` not `IBinaryInteger.One`. -- X10D: Removed `byte.Product`, `short.Product`, `ushort.Product`, `int.Product`, `uint.Product`, `long.Product`, - and `ulong.Product`, in favour of `INumber.Product`. -- X10D: Removed `byte.RangeTo`, `short.RangeTo`, `ushort.RangeTo`, `int.RangeTo`, `uint.RangeTo`, `long.RangeTo`, -and `ulong.RangeTo`, in favour of `INumber.RangeTo`. +- X10D: Removed `IEnumerable.GreatestCommonFactor` for all integer types in favour of generic math. +- X10D: Removed `IEnumerable.LowestCommonMultiple` for all integer types in favour of generic math. +- X10D: Removed `IEnumerable.Product` for all integer types in favour of generic math. +- X10D: Removed `IEnumerable.RangeTo` for all integer types in favour of generic math. ### Removed diff --git a/X10D/src/Math/BigIntegerExtensions.cs b/X10D/src/Math/BigIntegerExtensions.cs index da72697..156fe05 100644 --- a/X10D/src/Math/BigIntegerExtensions.cs +++ b/X10D/src/Math/BigIntegerExtensions.cs @@ -39,24 +39,6 @@ public static class BigIntegerExtensions return result; } - /// - /// Calculates the greatest common factor between this, and another, . - /// - /// The first value. - /// The second value. - /// The greatest common factor between and . - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static BigInteger GreatestCommonFactor(this BigInteger value, BigInteger other) - { - while (other != 0) - { - (value, other) = (other, value % other); - } - - return value; - } - /// /// Returns a value indicating whether the current value is not evenly divisible by 2. /// @@ -109,34 +91,6 @@ public static class BigIntegerExtensions return true; } - /// - /// Calculates the lowest common multiple between the current 64-bit signed integer, and another 64-bit signed integer. - /// - /// The first value. - /// The second value. - /// The lowest common multiple between and . - [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); - } - /// /// Returns the multiplicative persistence of a specified value. /// diff --git a/X10D/src/Math/BinaryIntegerExtensions.cs b/X10D/src/Math/BinaryIntegerExtensions.cs index cce2bd1..b24fe87 100644 --- a/X10D/src/Math/BinaryIntegerExtensions.cs +++ b/X10D/src/Math/BinaryIntegerExtensions.cs @@ -77,23 +77,4 @@ public static class BinaryIntegerExtensions return long.CreateChecked(result); } - - /// - /// Calculates the greatest common factor between the current binary integer, and another binary integer. - /// - /// The first value. - /// The second value. - /// The greatest common factor between and . - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static TInteger GreatestCommonFactor(this TInteger value, TInteger other) - where TInteger : IBinaryInteger - { - while (other != TInteger.Zero) - { - (value, other) = (other, value % other); - } - - return value; - } } diff --git a/X10D/src/Math/ByteExtensions.cs b/X10D/src/Math/ByteExtensions.cs index 5f6d77a..984d6f7 100644 --- a/X10D/src/Math/ByteExtensions.cs +++ b/X10D/src/Math/ByteExtensions.cs @@ -22,19 +22,6 @@ public static class ByteExtensions return ((long)value).IsPrime(); } - /// - /// Calculates the lowest common multiple between the current 8-bit signed integer, and another 8-bit signed integer. - /// - /// The first value. - /// The second value. - /// The lowest common multiple between and . - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static byte LowestCommonMultiple(this byte value, byte other) - { - return (byte)((long)value).LowestCommonMultiple(other); - } - /// /// Returns the multiplicative persistence of a specified value. /// diff --git a/X10D/src/Math/Int16Extensions.cs b/X10D/src/Math/Int16Extensions.cs index a331a46..d2f0707 100644 --- a/X10D/src/Math/Int16Extensions.cs +++ b/X10D/src/Math/Int16Extensions.cs @@ -23,19 +23,6 @@ public static class Int16Extensions return ((long)value).IsPrime(); } - /// - /// Calculates the lowest common multiple between the current 16-bit signed integer, and another 16-bit signed integer. - /// - /// The first value. - /// The second value. - /// The lowest common multiple between and . - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static short LowestCommonMultiple(this short value, short other) - { - return (short)((long)value).LowestCommonMultiple(other); - } - /// /// Returns the multiplicative persistence of a specified value. /// diff --git a/X10D/src/Math/Int32Extensions.cs b/X10D/src/Math/Int32Extensions.cs index c9eb23f..8f235e1 100644 --- a/X10D/src/Math/Int32Extensions.cs +++ b/X10D/src/Math/Int32Extensions.cs @@ -23,19 +23,6 @@ public static class Int32Extensions return ((long)value).IsPrime(); } - /// - /// Calculates the lowest common multiple between the current 32-bit signed integer, and another 32-bit signed integer. - /// - /// The first value. - /// The second value. - /// The lowest common multiple between and . - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static int LowestCommonMultiple(this int value, int other) - { - return (int)((long)value).LowestCommonMultiple(other); - } - /// /// Returns the multiplicative persistence of a specified value. /// diff --git a/X10D/src/Math/Int64Extensions.cs b/X10D/src/Math/Int64Extensions.cs index d000cbe..dd0d398 100644 --- a/X10D/src/Math/Int64Extensions.cs +++ b/X10D/src/Math/Int64Extensions.cs @@ -42,34 +42,6 @@ public static class Int64Extensions return true; } - /// - /// Calculates the lowest common multiple between the current 64-bit signed integer, and another 64-bit signed integer. - /// - /// The first value. - /// The second value. - /// The lowest common multiple between and . - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static long LowestCommonMultiple(this long value, long other) - { - if (value == 0 || other == 0) - { - return 0; - } - - if (value == 1) - { - return other; - } - - if (other == 1) - { - return value; - } - - return value * other / value.GreatestCommonFactor(other); - } - /// /// Returns the multiplicative persistence of a specified value. /// diff --git a/X10D/src/Math/NumberExtensions.cs b/X10D/src/Math/NumberExtensions.cs index a03d583..99a6468 100644 --- a/X10D/src/Math/NumberExtensions.cs +++ b/X10D/src/Math/NumberExtensions.cs @@ -10,6 +10,25 @@ namespace X10D.Math; /// public static class NumberExtensions { + /// + /// Calculates the greatest common factor between the current number and another number. + /// + /// The first value. + /// The second value. + /// The greatest common factor between and . + [Pure] + [MethodImpl(CompilerResources.MaxOptimization)] + public static TNumber GreatestCommonFactor(this TNumber value, TNumber other) + where TNumber : INumber + { + while (other != TNumber.Zero) + { + (value, other) = (other, value % other); + } + + return value; + } + /// /// Returns a value indicating whether the current value is evenly divisible by 2. /// @@ -42,6 +61,35 @@ public static class NumberExtensions return !value.IsEven(); } + /// + /// Calculates the lowest common multiple between the current 64-bit signed integer, and another 64-bit signed integer. + /// + /// The first value. + /// The second value. + /// The lowest common multiple between and . + [Pure] + [MethodImpl(CompilerResources.MaxOptimization)] + public static TNumber LowestCommonMultiple(this TNumber value, TNumber other) + where TNumber : INumber + { + if (value == TNumber.Zero || other == TNumber.Zero) + { + return TNumber.Zero; + } + + if (value == TNumber.One) + { + return other; + } + + if (other == TNumber.One) + { + return value; + } + + return value * other / value.GreatestCommonFactor(other); + } + /// /// Performs a modulo operation which supports a negative dividend. /// diff --git a/X10D/src/Math/SByteExtensions.cs b/X10D/src/Math/SByteExtensions.cs index 40b45e6..4d22aa4 100644 --- a/X10D/src/Math/SByteExtensions.cs +++ b/X10D/src/Math/SByteExtensions.cs @@ -24,19 +24,6 @@ public static class SByteExtensions return ((long)value).IsPrime(); } - /// - /// Calculates the lowest common multiple between the current 8-bit signed integer, and another 8-bit signed integer. - /// - /// The first value. - /// The second value. - /// The lowest common multiple between and . - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static sbyte LowestCommonMultiple(this sbyte value, sbyte other) - { - return (sbyte)((long)value).LowestCommonMultiple(other); - } - /// /// Returns the multiplicative persistence of a specified value. /// diff --git a/X10D/src/Math/UInt16Extensions.cs b/X10D/src/Math/UInt16Extensions.cs index ada7d97..0d8afe2 100644 --- a/X10D/src/Math/UInt16Extensions.cs +++ b/X10D/src/Math/UInt16Extensions.cs @@ -24,20 +24,6 @@ public static class UInt16Extensions return ((ulong)value).IsPrime(); } - /// - /// Calculates the lowest common multiple between the current 16-bit unsigned integer, and another 16-bit unsigned - /// integer. - /// - /// The first value. - /// The second value. - /// The lowest common multiple between and . - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static ushort LowestCommonMultiple(this ushort value, ushort other) - { - return (ushort)((ulong)value).LowestCommonMultiple(other); - } - /// /// Returns the multiplicative persistence of a specified value. /// diff --git a/X10D/src/Math/UInt32Extensions.cs b/X10D/src/Math/UInt32Extensions.cs index c20a19d..61abefd 100644 --- a/X10D/src/Math/UInt32Extensions.cs +++ b/X10D/src/Math/UInt32Extensions.cs @@ -24,20 +24,6 @@ public static class UInt32Extensions return ((ulong)value).IsPrime(); } - /// - /// Calculates the lowest common multiple between the current 32-bit unsigned integer, and another 32-bit unsigned - /// integer. - /// - /// The first value. - /// The second value. - /// The lowest common multiple between and . - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static uint LowestCommonMultiple(this uint value, uint other) - { - return (uint)((ulong)value).LowestCommonMultiple(other); - } - /// /// Returns the multiplicative persistence of a specified value. /// diff --git a/X10D/src/Math/UInt64Extensions.cs b/X10D/src/Math/UInt64Extensions.cs index 3f7637c..e64374e 100644 --- a/X10D/src/Math/UInt64Extensions.cs +++ b/X10D/src/Math/UInt64Extensions.cs @@ -43,35 +43,6 @@ public static class UInt64Extensions return true; } - /// - /// Calculates the lowest common multiple between the current 64-bit unsigned integer, and another 64-bit unsigned - /// integer. - /// - /// The first value. - /// The second value. - /// The lowest common multiple between and . - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static ulong LowestCommonMultiple(this ulong value, ulong other) - { - if (value == 0 || other == 0) - { - return 0; - } - - if (value == 1) - { - return other; - } - - if (other == 1) - { - return value; - } - - return value * other / value.GreatestCommonFactor(other); - } - /// /// Returns the multiplicative persistence of a specified value. /// From 44d3aec9a69b0310071bfc0bf1ca65c1c2be1621 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Thu, 14 Nov 2024 16:15:37 +0000 Subject: [PATCH 20/27] fix: revert c7e78f5d195e0209871515c5332af2e1382f8cec --- CHANGELOG.md | 2 -- X10D/src/Math/BinaryIntegerExtensions.cs | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1564404..851973c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,8 +9,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- X1OD: `IBinaryInteger.Factorial` now starts at `IBinaryInteger.MultiplicativeIdentity` not -`IBinaryInteger.One`. - X10D: Removed `IEnumerable.GreatestCommonFactor` for all integer types in favour of generic math. - X10D: Removed `IEnumerable.LowestCommonMultiple` for all integer types in favour of generic math. - X10D: Removed `IEnumerable.Product` for all integer types in favour of generic math. diff --git a/X10D/src/Math/BinaryIntegerExtensions.cs b/X10D/src/Math/BinaryIntegerExtensions.cs index b24fe87..08d76fd 100644 --- a/X10D/src/Math/BinaryIntegerExtensions.cs +++ b/X10D/src/Math/BinaryIntegerExtensions.cs @@ -69,12 +69,12 @@ public static class BinaryIntegerExtensions return 1; } - TInteger result = TInteger.MultiplicativeIdentity; + long result = 1L; for (TInteger i = TInteger.One; i <= value; i++) { - result *= i; + result *= long.CreateChecked(i); } - return long.CreateChecked(result); + return result; } } From 72dbaa72ba1395e1214248f568fb3e7ce044be7c Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Thu, 14 Nov 2024 16:29:15 +0000 Subject: [PATCH 21/27] refactor!: remove redundant Sign overloads --- CHANGELOG.md | 1 + X10D/src/Math/DecimalExtensions.cs | 34 ----------------------------- X10D/src/Math/DoubleExtensions.cs | 35 ------------------------------ X10D/src/Math/Int16Extensions.cs | 34 ----------------------------- X10D/src/Math/Int32Extensions.cs | 34 ----------------------------- X10D/src/Math/Int64Extensions.cs | 34 ----------------------------- X10D/src/Math/SingleExtensions.cs | 34 ----------------------------- 7 files changed, 1 insertion(+), 205 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 851973c..ff8f8f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - X10D: Removed `IEnumerable.LowestCommonMultiple` for all integer types in favour of generic math. - X10D: Removed `IEnumerable.Product` for all integer types in favour of generic math. - X10D: Removed `IEnumerable.RangeTo` for all integer types in favour of generic math. +- X10D: Removed `T.Sign` for all numeric types in favour of generic math. ### Removed diff --git a/X10D/src/Math/DecimalExtensions.cs b/X10D/src/Math/DecimalExtensions.cs index 1aa678d..56bddc3 100644 --- a/X10D/src/Math/DecimalExtensions.cs +++ b/X10D/src/Math/DecimalExtensions.cs @@ -90,40 +90,6 @@ public static class DecimalExtensions return System.Math.Clamp(value, 0.0m, 1.0m); } - /// - /// Returns an integer that indicates the sign of this decimal number. - /// - /// A signed number. - /// - /// A number that indicates the sign of , as shown in the following table. - /// - /// - /// - /// Return value - /// Meaning - /// - /// - /// - /// -1 - /// is less than zero. - /// - /// - /// 0 - /// is equal to zero. - /// - /// - /// 1 - /// is greater than zero. - /// - /// - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static int Sign(this decimal value) - { - return System.Math.Sign(value); - } - /// /// Returns the square root of this decimal number. /// diff --git a/X10D/src/Math/DoubleExtensions.cs b/X10D/src/Math/DoubleExtensions.cs index 51a7b7a..06abc82 100644 --- a/X10D/src/Math/DoubleExtensions.cs +++ b/X10D/src/Math/DoubleExtensions.cs @@ -300,41 +300,6 @@ public static class DoubleExtensions return System.Math.Sinh(value); } - /// - /// Returns an integer that indicates the sign of this double-precision floating-point number. - /// - /// A signed number. - /// - /// A number that indicates the sign of , as shown in the following table. - /// - /// - /// - /// Return value - /// Meaning - /// - /// - /// - /// -1 - /// is less than zero. - /// - /// - /// 0 - /// is equal to zero. - /// - /// - /// 1 - /// is greater than zero. - /// - /// - /// - /// is equal to . - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static int Sign(this double value) - { - return System.Math.Sign(value); - } - /// /// Returns the square root of this double-precision floating-point number. /// diff --git a/X10D/src/Math/Int16Extensions.cs b/X10D/src/Math/Int16Extensions.cs index d2f0707..71594a5 100644 --- a/X10D/src/Math/Int16Extensions.cs +++ b/X10D/src/Math/Int16Extensions.cs @@ -38,40 +38,6 @@ public static class Int16Extensions return ((long)value).MultiplicativePersistence(); } - /// - /// Returns an integer that indicates the sign of this 16-bit signed integer. - /// - /// A signed number. - /// - /// A number that indicates the sign of , as shown in the following table. - /// - /// - /// - /// Return value - /// Meaning - /// - /// - /// - /// -1 - /// is less than zero. - /// - /// - /// 0 - /// is equal to zero. - /// - /// - /// 1 - /// is greater than zero. - /// - /// - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static int Sign(this short value) - { - return System.Math.Sign(value); - } - /// /// Wraps the current 16-bit signed integer between a low and a high value. /// diff --git a/X10D/src/Math/Int32Extensions.cs b/X10D/src/Math/Int32Extensions.cs index 8f235e1..b4fefe4 100644 --- a/X10D/src/Math/Int32Extensions.cs +++ b/X10D/src/Math/Int32Extensions.cs @@ -38,40 +38,6 @@ public static class Int32Extensions return ((long)value).MultiplicativePersistence(); } - /// - /// Returns an integer that indicates the sign of this 32-bit signed integer. - /// - /// A signed number. - /// - /// A number that indicates the sign of , as shown in the following table. - /// - /// - /// - /// Return value - /// Meaning - /// - /// - /// - /// -1 - /// is less than zero. - /// - /// - /// 0 - /// is equal to zero. - /// - /// - /// 1 - /// is greater than zero. - /// - /// - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static int Sign(this int value) - { - return System.Math.Sign(value); - } - /// /// Wraps the current 32-bit signed integer between a low and a high value. /// diff --git a/X10D/src/Math/Int64Extensions.cs b/X10D/src/Math/Int64Extensions.cs index dd0d398..e06907e 100644 --- a/X10D/src/Math/Int64Extensions.cs +++ b/X10D/src/Math/Int64Extensions.cs @@ -88,40 +88,6 @@ public static class Int64Extensions return persistence; } - /// - /// Returns an integer that indicates the sign of this 64-bit signed integer. - /// - /// A signed number. - /// - /// A number that indicates the sign of , as shown in the following table. - /// - /// - /// - /// Return value - /// Meaning - /// - /// - /// - /// -1 - /// is less than zero. - /// - /// - /// 0 - /// is equal to zero. - /// - /// - /// 1 - /// is greater than zero. - /// - /// - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static int Sign(this long value) - { - return System.Math.Sign(value); - } - /// /// Wraps the current 64-bit signed integer between a low and a high value. /// diff --git a/X10D/src/Math/SingleExtensions.cs b/X10D/src/Math/SingleExtensions.cs index 9e70592..fa90dbf 100644 --- a/X10D/src/Math/SingleExtensions.cs +++ b/X10D/src/Math/SingleExtensions.cs @@ -268,40 +268,6 @@ public static class SingleExtensions return System.Math.Clamp(value, 0.0f, 1.0f); } - /// - /// Returns an integer that indicates the sign of this single-precision floating-point number. - /// - /// A signed number. - /// - /// A number that indicates the sign of , as shown in the following table. - /// - /// - /// - /// Return value - /// Meaning - /// - /// - /// - /// -1 - /// is less than zero. - /// - /// - /// 0 - /// is equal to zero. - /// - /// - /// 1 - /// is greater than zero. - /// - /// - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static int Sign(this float value) - { - return MathF.Sign(value); - } - /// /// Returns the square root of this single-precision floating-point number. /// From cb7e1308e22fac4c50601267d02e192455fc74c7 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Thu, 14 Nov 2024 16:33:09 +0000 Subject: [PATCH 22/27] refactor: replace T.Wrap for numeric types with generic math --- CHANGELOG.md | 1 + X10D/src/Math/BigIntegerExtensions.cs | 28 ------------------------- X10D/src/Math/ByteExtensions.cs | 27 ------------------------ X10D/src/Math/DecimalExtensions.cs | 28 ------------------------- X10D/src/Math/DoubleExtensions.cs | 28 ------------------------- X10D/src/Math/Int16Extensions.cs | 27 ------------------------ X10D/src/Math/Int32Extensions.cs | 27 ------------------------ X10D/src/Math/Int64Extensions.cs | 28 ------------------------- X10D/src/Math/NumberExtensions.cs | 30 +++++++++++++++++++++++++++ X10D/src/Math/SByteExtensions.cs | 27 ------------------------ X10D/src/Math/SingleExtensions.cs | 27 ------------------------ X10D/src/Math/UInt16Extensions.cs | 27 ------------------------ X10D/src/Math/UInt32Extensions.cs | 27 ------------------------ X10D/src/Math/UInt64Extensions.cs | 28 ------------------------- 14 files changed, 31 insertions(+), 329 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff8f8f6..43469b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - X10D: Removed `IEnumerable.Product` for all integer types in favour of generic math. - X10D: Removed `IEnumerable.RangeTo` for all integer 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 diff --git a/X10D/src/Math/BigIntegerExtensions.cs b/X10D/src/Math/BigIntegerExtensions.cs index 156fe05..55102e6 100644 --- a/X10D/src/Math/BigIntegerExtensions.cs +++ b/X10D/src/Math/BigIntegerExtensions.cs @@ -136,32 +136,4 @@ public static class BigIntegerExtensions return persistence; } - - /// - /// Wraps the current integer between a low and a high value. - /// - /// The value to wrap. - /// The inclusive lower bound. - /// The exclusive upper bound. - /// The wrapped value. - [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; - } - - /// - /// Wraps the current integer between 0 and a high value. - /// - /// The value to wrap. - /// The exclusive upper bound. - /// The wrapped value. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static BigInteger Wrap(this BigInteger value, BigInteger length) - { - return ((value % length) + length) % length; - } } diff --git a/X10D/src/Math/ByteExtensions.cs b/X10D/src/Math/ByteExtensions.cs index 984d6f7..a813c0a 100644 --- a/X10D/src/Math/ByteExtensions.cs +++ b/X10D/src/Math/ByteExtensions.cs @@ -36,31 +36,4 @@ public static class ByteExtensions { return ((long)value).MultiplicativePersistence(); } - - /// - /// Wraps the current 8-bit unsigned integer between a low and a high value. - /// - /// The value to wrap. - /// The inclusive lower bound. - /// The exclusive upper bound. - /// The wrapped value. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static byte Wrap(this byte value, byte low, byte high) - { - return (byte)((ulong)value).Wrap(low, high); - } - - /// - /// Wraps the current 8-bit unsigned integer between 0 and a high value. - /// - /// The value to wrap. - /// The exclusive upper bound. - /// The wrapped value. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static byte Wrap(this byte value, byte length) - { - return (byte)((ulong)value).Wrap(length); - } } diff --git a/X10D/src/Math/DecimalExtensions.cs b/X10D/src/Math/DecimalExtensions.cs index 56bddc3..07db13d 100644 --- a/X10D/src/Math/DecimalExtensions.cs +++ b/X10D/src/Math/DecimalExtensions.cs @@ -140,32 +140,4 @@ public static class DecimalExtensions return current; } - - /// - /// Wraps the current decimal number between a low and a high value. - /// - /// The value to wrap. - /// The inclusive lower bound. - /// The exclusive upper bound. - /// The wrapped value. - [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; - } - - /// - /// Wraps the current decimal number between 0 and a high value. - /// - /// The value to wrap. - /// The exclusive upper bound. - /// The wrapped value. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static decimal Wrap(this decimal value, decimal length) - { - return ((value % length) + length) % length; - } } diff --git a/X10D/src/Math/DoubleExtensions.cs b/X10D/src/Math/DoubleExtensions.cs index 06abc82..0ca716c 100644 --- a/X10D/src/Math/DoubleExtensions.cs +++ b/X10D/src/Math/DoubleExtensions.cs @@ -386,32 +386,4 @@ public static class DoubleExtensions { return System.Math.Tanh(value); } - - /// - /// Wraps the current double-precision floating-point number between a low and a high value. - /// - /// The value to wrap. - /// The inclusive lower bound. - /// The exclusive upper bound. - /// The wrapped value. - [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; - } - - /// - /// Wraps the current double-precision floating-point number between 0 and a high value. - /// - /// The value to wrap. - /// The exclusive upper bound. - /// The wrapped value. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static double Wrap(this double value, double length) - { - return ((value % length) + length) % length; - } } diff --git a/X10D/src/Math/Int16Extensions.cs b/X10D/src/Math/Int16Extensions.cs index 71594a5..626403f 100644 --- a/X10D/src/Math/Int16Extensions.cs +++ b/X10D/src/Math/Int16Extensions.cs @@ -37,31 +37,4 @@ public static class Int16Extensions { return ((long)value).MultiplicativePersistence(); } - - /// - /// Wraps the current 16-bit signed integer between a low and a high value. - /// - /// The value to wrap. - /// The inclusive lower bound. - /// The exclusive upper bound. - /// The wrapped value. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static short Wrap(this short value, short low, short high) - { - return (short)((long)value).Wrap(low, high); - } - - /// - /// Wraps the current 16-bit signed integer between 0 and a high value. - /// - /// The value to wrap. - /// The exclusive upper bound. - /// The wrapped value. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static short Wrap(this short value, short length) - { - return (short)((long)value).Wrap(length); - } } diff --git a/X10D/src/Math/Int32Extensions.cs b/X10D/src/Math/Int32Extensions.cs index b4fefe4..6ed9af9 100644 --- a/X10D/src/Math/Int32Extensions.cs +++ b/X10D/src/Math/Int32Extensions.cs @@ -37,31 +37,4 @@ public static class Int32Extensions { return ((long)value).MultiplicativePersistence(); } - - /// - /// Wraps the current 32-bit signed integer between a low and a high value. - /// - /// The value to wrap. - /// The inclusive lower bound. - /// The exclusive upper bound. - /// The wrapped value. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static int Wrap(this int value, int low, int high) - { - return (int)((long)value).Wrap(low, high); - } - - /// - /// Wraps the current 32-bit signed integer between 0 and a high value. - /// - /// The value to wrap. - /// The exclusive upper bound. - /// The wrapped value. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static int Wrap(this int value, int length) - { - return (int)((long)value).Wrap(length); - } } diff --git a/X10D/src/Math/Int64Extensions.cs b/X10D/src/Math/Int64Extensions.cs index e06907e..7dd7ec2 100644 --- a/X10D/src/Math/Int64Extensions.cs +++ b/X10D/src/Math/Int64Extensions.cs @@ -87,32 +87,4 @@ public static class Int64Extensions return persistence; } - - /// - /// Wraps the current 64-bit signed integer between a low and a high value. - /// - /// The value to wrap. - /// The inclusive lower bound. - /// The exclusive upper bound. - /// The wrapped value. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static long Wrap(this long value, long low, long high) - { - long difference = high - low; - return low + (((value - low) % difference) + difference) % difference; - } - - /// - /// Wraps the current 64-bit signed integer between 0 and a high value. - /// - /// The value to wrap. - /// The exclusive upper bound. - /// The wrapped value. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static long Wrap(this long value, long length) - { - return ((value % length) + length) % length; - } } diff --git a/X10D/src/Math/NumberExtensions.cs b/X10D/src/Math/NumberExtensions.cs index 99a6468..6f14fdc 100644 --- a/X10D/src/Math/NumberExtensions.cs +++ b/X10D/src/Math/NumberExtensions.cs @@ -147,4 +147,34 @@ public static class NumberExtensions { return TNumber.Sign(value); } + + /// + /// Wraps the current integer between a low and a high value. + /// + /// The value to wrap. + /// The inclusive lower bound. + /// The exclusive upper bound. + /// The wrapped value. + [Pure] + [MethodImpl(CompilerResources.MaxOptimization)] + public static TNumber Wrap(this TNumber value, TNumber low, TNumber high) + where TNumber : INumber + { + TNumber difference = high - low; + return low + (((value - low) % difference) + difference) % difference; + } + + /// + /// Wraps the current integer between 0 and a high value. + /// + /// The value to wrap. + /// The exclusive upper bound. + /// The wrapped value. + [Pure] + [MethodImpl(CompilerResources.MaxOptimization)] + public static TNumber Wrap(this TNumber value, TNumber length) + where TNumber : INumber + { + return ((value % length) + length) % length; + } } diff --git a/X10D/src/Math/SByteExtensions.cs b/X10D/src/Math/SByteExtensions.cs index 4d22aa4..53a29d6 100644 --- a/X10D/src/Math/SByteExtensions.cs +++ b/X10D/src/Math/SByteExtensions.cs @@ -72,31 +72,4 @@ public static class SByteExtensions { return System.Math.Sign(value); } - - /// - /// Wraps the current 8-bit signed integer between a low and a high value. - /// - /// The value to wrap. - /// The inclusive lower bound. - /// The exclusive upper bound. - /// The wrapped value. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static sbyte Wrap(this sbyte value, sbyte low, sbyte high) - { - return (sbyte)((long)value).Wrap(low, high); - } - - /// - /// Wraps the current 8-bit signed integer between 0 and a high value. - /// - /// The value to wrap. - /// The exclusive upper bound. - /// The wrapped value. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static sbyte Wrap(this sbyte value, sbyte length) - { - return (sbyte)((long)value).Wrap(length); - } } diff --git a/X10D/src/Math/SingleExtensions.cs b/X10D/src/Math/SingleExtensions.cs index fa90dbf..2d35054 100644 --- a/X10D/src/Math/SingleExtensions.cs +++ b/X10D/src/Math/SingleExtensions.cs @@ -386,31 +386,4 @@ public static class SingleExtensions { return MathF.Tanh(value); } - - /// - /// Wraps the current single-precision floating-point number between a low and a high value. - /// - /// The value to wrap. - /// The inclusive lower bound. - /// The exclusive upper bound. - /// The wrapped value. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static float Wrap(this float value, float low, float high) - { - return (float)((double)value).Wrap(low, high); - } - - /// - /// Wraps the current single-precision floating-point number between 0 and a high value. - /// - /// The value to wrap. - /// The exclusive upper bound. - /// The wrapped value. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static float Wrap(this float value, float length) - { - return (float)((double)value).Wrap(length); - } } diff --git a/X10D/src/Math/UInt16Extensions.cs b/X10D/src/Math/UInt16Extensions.cs index 0d8afe2..fd46029 100644 --- a/X10D/src/Math/UInt16Extensions.cs +++ b/X10D/src/Math/UInt16Extensions.cs @@ -38,31 +38,4 @@ public static class UInt16Extensions { return ((ulong)value).MultiplicativePersistence(); } - - /// - /// Wraps the current 16-bit unsigned integer between a low and a high value. - /// - /// The value to wrap. - /// The inclusive lower bound. - /// The exclusive upper bound. - /// The wrapped value. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static ushort Wrap(this ushort value, ushort low, ushort high) - { - return (ushort)((ulong)value).Wrap(low, high); - } - - /// - /// Wraps the current 16-bit unsigned integer between 0 and a high value. - /// - /// The value to wrap. - /// The exclusive upper bound. - /// The wrapped value. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static ushort Wrap(this ushort value, ushort length) - { - return (ushort)((ulong)value).Wrap(length); - } } diff --git a/X10D/src/Math/UInt32Extensions.cs b/X10D/src/Math/UInt32Extensions.cs index 61abefd..2c2d73d 100644 --- a/X10D/src/Math/UInt32Extensions.cs +++ b/X10D/src/Math/UInt32Extensions.cs @@ -38,31 +38,4 @@ public static class UInt32Extensions { return ((ulong)value).MultiplicativePersistence(); } - - /// - /// Wraps the current 32-bit unsigned integer between a low and a high value. - /// - /// The value to wrap. - /// The inclusive lower bound. - /// The exclusive upper bound. - /// The wrapped value. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static uint Wrap(this uint value, uint low, uint high) - { - return (uint)((ulong)value).Wrap(low, high); - } - - /// - /// Wraps the current 32-bit unsigned integer between 0 and a high value. - /// - /// The value to wrap. - /// The exclusive upper bound. - /// The wrapped value. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static uint Wrap(this uint value, uint length) - { - return (uint)((ulong)value).Wrap(length); - } } diff --git a/X10D/src/Math/UInt64Extensions.cs b/X10D/src/Math/UInt64Extensions.cs index e64374e..b6ef392 100644 --- a/X10D/src/Math/UInt64Extensions.cs +++ b/X10D/src/Math/UInt64Extensions.cs @@ -88,32 +88,4 @@ public static class UInt64Extensions return persistence; } - - /// - /// Wraps the current 64-bit unsigned integer between a low and a high value. - /// - /// The value to wrap. - /// The inclusive lower bound. - /// The exclusive upper bound. - /// The wrapped value. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static ulong Wrap(this ulong value, ulong low, ulong high) - { - ulong difference = high - low; - return low + (((value - low) % difference) + difference) % difference; - } - - /// - /// Wraps the current 64-bit unsigned integer between 0 and a high value. - /// - /// The value to wrap. - /// The exclusive upper bound. - /// The wrapped value. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static ulong Wrap(this ulong value, ulong length) - { - return ((value % length) + length) % length; - } } From 7af3c96405b96b15751f8cd91f7dbccc360b81c2 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Thu, 14 Nov 2024 16:42:20 +0000 Subject: [PATCH 23/27] refactor: replace T.Saturate for float types with generic math --- CHANGELOG.md | 1 + X10D/src/Math/DecimalExtensions.cs | 13 ------------- X10D/src/Math/DoubleExtensions.cs | 13 ------------- X10D/src/Math/NumberExtensions.cs | 16 ++++++++++++++++ 4 files changed, 17 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43469b0..ada6f54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - X10D: Removed `IEnumerable.LowestCommonMultiple` for all integer types in favour of generic math. - X10D: Removed `IEnumerable.Product` for all integer types in favour of generic math. - X10D: Removed `IEnumerable.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. diff --git a/X10D/src/Math/DecimalExtensions.cs b/X10D/src/Math/DecimalExtensions.cs index 07db13d..af1a9ed 100644 --- a/X10D/src/Math/DecimalExtensions.cs +++ b/X10D/src/Math/DecimalExtensions.cs @@ -77,19 +77,6 @@ public static class DecimalExtensions return System.Math.Round(value / nearest) * nearest; } - /// - /// Saturates this decimal number. - /// - /// The value to saturate. - /// The saturated value. - /// This method clamps between 0 and 1. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static decimal Saturate(this decimal value) - { - return System.Math.Clamp(value, 0.0m, 1.0m); - } - /// /// Returns the square root of this decimal number. /// diff --git a/X10D/src/Math/DoubleExtensions.cs b/X10D/src/Math/DoubleExtensions.cs index 0ca716c..33ee481 100644 --- a/X10D/src/Math/DoubleExtensions.cs +++ b/X10D/src/Math/DoubleExtensions.cs @@ -255,19 +255,6 @@ public static class DoubleExtensions return System.Math.Round(value / nearest) * nearest; } - /// - /// Saturates this double-precision floating-point number. - /// - /// The value to saturate. - /// The saturated value. - /// This method clamps between 0 and 1. - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static double Saturate(this double value) - { - return System.Math.Clamp(value, 0.0, 1.0); - } - /// /// Returns the sine of the specified angle. /// diff --git a/X10D/src/Math/NumberExtensions.cs b/X10D/src/Math/NumberExtensions.cs index 6f14fdc..3fdcc7c 100644 --- a/X10D/src/Math/NumberExtensions.cs +++ b/X10D/src/Math/NumberExtensions.cs @@ -113,6 +113,22 @@ public static class NumberExtensions return r < TNumber.Zero ? r + divisor : r; } + /// + /// Saturates this number. + /// + /// The value to saturate. + /// The saturated value. + /// + /// This method clamps between and . + /// + [Pure] + [MethodImpl(CompilerResources.MaxOptimization)] + public static TNumber Saturate(this TNumber value) + where TNumber : INumber + { + return TNumber.Clamp(value, TNumber.Zero, TNumber.One); + } + /// /// Returns an integer that indicates the sign of this number. /// From 027f6f23e187818d5770ba21bec4aee21ca096ed Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Thu, 14 Nov 2024 16:48:22 +0000 Subject: [PATCH 24/27] refactor!: replace T.MultiplicativePersistence with generic math --- CHANGELOG.md | 1 + X10D/src/Math/BigIntegerExtensions.cs | 46 ---------------------- X10D/src/Math/BinaryIntegerExtensions.cs | 50 ++++++++++++++++++++++++ X10D/src/Math/ByteExtensions.cs | 17 -------- X10D/src/Math/Int16Extensions.cs | 15 ------- X10D/src/Math/Int32Extensions.cs | 15 ------- X10D/src/Math/Int64Extensions.cs | 46 ---------------------- X10D/src/Math/SByteExtensions.cs | 15 ------- X10D/src/Math/UInt16Extensions.cs | 15 ------- X10D/src/Math/UInt32Extensions.cs | 15 ------- X10D/src/Math/UInt64Extensions.cs | 46 ---------------------- 11 files changed, 51 insertions(+), 230 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ada6f54..0cf7ea8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - X10D: Removed `IEnumerable.GreatestCommonFactor` for all integer types in favour of generic math. - X10D: Removed `IEnumerable.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.Product` for all integer types in favour of generic math. - X10D: Removed `IEnumerable.RangeTo` for all integer types in favour of generic math. - X10D: Removed `T.Saturate` for all floating-point types in favour of generic math. diff --git a/X10D/src/Math/BigIntegerExtensions.cs b/X10D/src/Math/BigIntegerExtensions.cs index 55102e6..bb408b4 100644 --- a/X10D/src/Math/BigIntegerExtensions.cs +++ b/X10D/src/Math/BigIntegerExtensions.cs @@ -90,50 +90,4 @@ public static class BigIntegerExtensions return true; } - - /// - /// Returns the multiplicative persistence of a specified value. - /// - /// The value whose multiplicative persistence to calculate. - /// The multiplicative persistence. - /// - /// Multiplicative persistence is defined as the recursive digital product until that product is a single digit. - /// - [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; - } } diff --git a/X10D/src/Math/BinaryIntegerExtensions.cs b/X10D/src/Math/BinaryIntegerExtensions.cs index 08d76fd..47f9ff1 100644 --- a/X10D/src/Math/BinaryIntegerExtensions.cs +++ b/X10D/src/Math/BinaryIntegerExtensions.cs @@ -77,4 +77,54 @@ public static class BinaryIntegerExtensions return result; } + + /// + /// Returns the multiplicative persistence of the current integer. + /// + /// The value whose multiplicative persistence to calculate. + /// The multiplicative persistence. + /// + /// Multiplicative persistence is defined as the recursive digital product until that product is a single digit. + /// + [Pure] + [MethodImpl(CompilerResources.MaxOptimization)] + public static int MultiplicativePersistence(this TInteger value) + where TInteger : IBinaryInteger + { + var nine = TInteger.CreateChecked(9); + var ten = TInteger.CreateChecked(10); + + var persistence = 0; + TInteger product = TInteger.Abs(value); + + while (product > nine) + { + 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 persistence; + } } diff --git a/X10D/src/Math/ByteExtensions.cs b/X10D/src/Math/ByteExtensions.cs index a813c0a..1c289ba 100644 --- a/X10D/src/Math/ByteExtensions.cs +++ b/X10D/src/Math/ByteExtensions.cs @@ -1,6 +1,4 @@ using System.Diagnostics.Contracts; -using System.Runtime.CompilerServices; -using X10D.CompilerServices; namespace X10D.Math; @@ -21,19 +19,4 @@ public static class ByteExtensions { return ((long)value).IsPrime(); } - - /// - /// Returns the multiplicative persistence of a specified value. - /// - /// The value whose multiplicative persistence to calculate. - /// The multiplicative persistence. - /// - /// Multiplicative persistence is defined as the recursive digital product until that product is a single digit. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static int MultiplicativePersistence(this byte value) - { - return ((long)value).MultiplicativePersistence(); - } } diff --git a/X10D/src/Math/Int16Extensions.cs b/X10D/src/Math/Int16Extensions.cs index 626403f..204de0c 100644 --- a/X10D/src/Math/Int16Extensions.cs +++ b/X10D/src/Math/Int16Extensions.cs @@ -22,19 +22,4 @@ public static class Int16Extensions { return ((long)value).IsPrime(); } - - /// - /// Returns the multiplicative persistence of a specified value. - /// - /// The value whose multiplicative persistence to calculate. - /// The multiplicative persistence. - /// - /// Multiplicative persistence is defined as the recursive digital product until that product is a single digit. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static int MultiplicativePersistence(this short value) - { - return ((long)value).MultiplicativePersistence(); - } } diff --git a/X10D/src/Math/Int32Extensions.cs b/X10D/src/Math/Int32Extensions.cs index 6ed9af9..f6d646b 100644 --- a/X10D/src/Math/Int32Extensions.cs +++ b/X10D/src/Math/Int32Extensions.cs @@ -22,19 +22,4 @@ public static class Int32Extensions { return ((long)value).IsPrime(); } - - /// - /// Returns the multiplicative persistence of a specified value. - /// - /// The value whose multiplicative persistence to calculate. - /// The multiplicative persistence. - /// - /// Multiplicative persistence is defined as the recursive digital product until that product is a single digit. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static int MultiplicativePersistence(this int value) - { - return ((long)value).MultiplicativePersistence(); - } } diff --git a/X10D/src/Math/Int64Extensions.cs b/X10D/src/Math/Int64Extensions.cs index 7dd7ec2..e4fb474 100644 --- a/X10D/src/Math/Int64Extensions.cs +++ b/X10D/src/Math/Int64Extensions.cs @@ -41,50 +41,4 @@ public static class Int64Extensions return true; } - - /// - /// Returns the multiplicative persistence of a specified value. - /// - /// The value whose multiplicative persistence to calculate. - /// The multiplicative persistence. - /// - /// Multiplicative persistence is defined as the recursive digital product until that product is a single digit. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static int MultiplicativePersistence(this long value) - { - var persistence = 0; - long product = System.Math.Abs(value); - - while (product > 9) - { - if (value % 10 == 0) - { - return persistence + 1; - } - - while (value > 9) - { - value /= 10; - if (value % 10 == 0) - { - return persistence + 1; - } - } - - long newProduct = 1; - long currentProduct = product; - while (currentProduct > 0) - { - newProduct *= currentProduct % 10; - currentProduct /= 10; - } - - product = newProduct; - persistence++; - } - - return persistence; - } } diff --git a/X10D/src/Math/SByteExtensions.cs b/X10D/src/Math/SByteExtensions.cs index 53a29d6..25c0454 100644 --- a/X10D/src/Math/SByteExtensions.cs +++ b/X10D/src/Math/SByteExtensions.cs @@ -24,21 +24,6 @@ public static class SByteExtensions return ((long)value).IsPrime(); } - /// - /// Returns the multiplicative persistence of a specified value. - /// - /// The value whose multiplicative persistence to calculate. - /// The multiplicative persistence. - /// - /// Multiplicative persistence is defined as the recursive digital product until that product is a single digit. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static int MultiplicativePersistence(this sbyte value) - { - return ((long)value).MultiplicativePersistence(); - } - /// /// Returns an integer that indicates the sign of this 8-bit signed integer. /// diff --git a/X10D/src/Math/UInt16Extensions.cs b/X10D/src/Math/UInt16Extensions.cs index fd46029..40b7ae7 100644 --- a/X10D/src/Math/UInt16Extensions.cs +++ b/X10D/src/Math/UInt16Extensions.cs @@ -23,19 +23,4 @@ public static class UInt16Extensions { return ((ulong)value).IsPrime(); } - - /// - /// Returns the multiplicative persistence of a specified value. - /// - /// The value whose multiplicative persistence to calculate. - /// The multiplicative persistence. - /// - /// Multiplicative persistence is defined as the recursive digital product until that product is a single digit. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static int MultiplicativePersistence(this ushort value) - { - return ((ulong)value).MultiplicativePersistence(); - } } diff --git a/X10D/src/Math/UInt32Extensions.cs b/X10D/src/Math/UInt32Extensions.cs index 2c2d73d..0549f8c 100644 --- a/X10D/src/Math/UInt32Extensions.cs +++ b/X10D/src/Math/UInt32Extensions.cs @@ -23,19 +23,4 @@ public static class UInt32Extensions { return ((ulong)value).IsPrime(); } - - /// - /// Returns the multiplicative persistence of a specified value. - /// - /// The value whose multiplicative persistence to calculate. - /// The multiplicative persistence. - /// - /// Multiplicative persistence is defined as the recursive digital product until that product is a single digit. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static int MultiplicativePersistence(this uint value) - { - return ((ulong)value).MultiplicativePersistence(); - } } diff --git a/X10D/src/Math/UInt64Extensions.cs b/X10D/src/Math/UInt64Extensions.cs index b6ef392..3ad4528 100644 --- a/X10D/src/Math/UInt64Extensions.cs +++ b/X10D/src/Math/UInt64Extensions.cs @@ -42,50 +42,4 @@ public static class UInt64Extensions return true; } - - /// - /// Returns the multiplicative persistence of a specified value. - /// - /// The value whose multiplicative persistence to calculate. - /// The multiplicative persistence. - /// - /// Multiplicative persistence is defined as the recursive digital product until that product is a single digit. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static int MultiplicativePersistence(this ulong value) - { - var persistence = 0; - ulong product = value; - - while (product > 9) - { - if (value % 10 == 0) - { - return persistence + 1; - } - - while (value > 9) - { - value /= 10; - if (value % 10 == 0) - { - return persistence + 1; - } - } - - ulong newProduct = 1; - ulong currentProduct = product; - while (currentProduct > 0) - { - newProduct *= currentProduct % 10; - currentProduct /= 10; - } - - product = newProduct; - persistence++; - } - - return persistence; - } } From bdef9b144238bec4f8e7475f5cbf925197f58de6 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Thu, 14 Nov 2024 17:35:19 +0000 Subject: [PATCH 25/27] refactor!: remove DateOnly.Deconstruct --- CHANGELOG.md | 4 +++- X10D.Tests/src/Time/DateOnlyTests.cs | 24 ------------------------ X10D/src/Time/DateOnlyExtensions.cs | 14 -------------- 3 files changed, 3 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cf7ea8..3217162 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,8 +20,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### 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.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-8.0). +[`System.MemoryExtensions.Split`](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.split?view=net-9.0). ## [4.0.0] - 2024-06-12 diff --git a/X10D.Tests/src/Time/DateOnlyTests.cs b/X10D.Tests/src/Time/DateOnlyTests.cs index 25dc25d..868c8e4 100644 --- a/X10D.Tests/src/Time/DateOnlyTests.cs +++ b/X10D.Tests/src/Time/DateOnlyTests.cs @@ -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() { diff --git a/X10D/src/Time/DateOnlyExtensions.cs b/X10D/src/Time/DateOnlyExtensions.cs index fd59001..39dc5d3 100644 --- a/X10D/src/Time/DateOnlyExtensions.cs +++ b/X10D/src/Time/DateOnlyExtensions.cs @@ -39,20 +39,6 @@ public static class DateOnlyExtensions return value.ToDateTime(default).Age(referenceDate.ToDateTime(default)); } - /// - /// Deconstructs the current into its year, month, and day. - /// - /// The date to deconstruct. - /// When this method returns, contains the year. - /// When this method returns, contains the month. - /// When this method returns, contains the day. - public static void Deconstruct(this DateOnly value, out int year, out int month, out int day) - { - year = value.Year; - month = value.Month; - day = value.Day; - } - /// /// Gets a date representing the first occurence of a specified day of the week in the current month. /// From b74bf60fe8a2b940bc432166bcde881f087895b6 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Thu, 14 Nov 2024 17:35:46 +0000 Subject: [PATCH 26/27] style: perform sln-wide cleanup --- X10D/src/IO/DoubleExtensions.cs | 1 - tools/SourceGenerator/OverloadSyntaxReceiver.cs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/X10D/src/IO/DoubleExtensions.cs b/X10D/src/IO/DoubleExtensions.cs index 8856c79..9f131d3 100644 --- a/X10D/src/IO/DoubleExtensions.cs +++ b/X10D/src/IO/DoubleExtensions.cs @@ -1,6 +1,5 @@ using System.Buffers.Binary; using System.Diagnostics.Contracts; -using System.Runtime.InteropServices; namespace X10D.IO; diff --git a/tools/SourceGenerator/OverloadSyntaxReceiver.cs b/tools/SourceGenerator/OverloadSyntaxReceiver.cs index 723dd46..c7a2cde 100644 --- a/tools/SourceGenerator/OverloadSyntaxReceiver.cs +++ b/tools/SourceGenerator/OverloadSyntaxReceiver.cs @@ -6,7 +6,7 @@ namespace SourceGenerator; public class OverloadSyntaxReceiver : ISyntaxReceiver { - private readonly List _candidateMethods = new(); + private readonly List _candidateMethods = []; public IReadOnlyList CandidateMethods { From 465dd2ee300b94eb3cd5f2cc4af27a97f233ada2 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Thu, 14 Nov 2024 17:47:46 +0000 Subject: [PATCH 27/27] test: bring Linq.EnumerableExtensions coverage to 100% in --- X10D.Tests/src/Linq/EnumerableTests.cs | 81 ++++++++++++++++++-------- 1 file changed, 58 insertions(+), 23 deletions(-) diff --git a/X10D.Tests/src/Linq/EnumerableTests.cs b/X10D.Tests/src/Linq/EnumerableTests.cs index 6d55bb0..99fe9ac 100644 --- a/X10D.Tests/src/Linq/EnumerableTests.cs +++ b/X10D.Tests/src/Linq/EnumerableTests.cs @@ -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 source = Enumerable.Range(1, 10).Select(i => new Person {Age = i}); + IEnumerable 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 source = Enumerable.Range(1, 10).Select(i => new Person {Age = i}); + IEnumerable source = Enumerable.Range(1, 10).Select(i => new Person { Age = i }); (int minimum, int maximum) = source.MinMax(p => p.Age, new InverseComparer()); 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()); Assert.Multiple(() => { @@ -113,36 +113,65 @@ internal class EnumerableTests public void MinMax_ShouldThrowArgumentNullException_GivenNullSelector() { IEnumerable source = []; - Assert.Throws(() => source.MinMax((Func)(null!))); - Assert.Throws(() => source.MinMax((Func)(null!), null)); + + Assert.Multiple(() => + { + Assert.Throws(() => source.MinMax((Func)(null!))); + Assert.Throws(() => source.MinMax((Func)(null!), null)); + }); } [Test] public void MinMax_ShouldThrowArgumentNullException_GivenNullSource() { IEnumerable? source = null; - Assert.Throws(() => source!.MinMax()); - Assert.Throws(() => source!.MinMax(v => v)); - Assert.Throws(() => source!.MinMax(null)); - Assert.Throws(() => source!.MinMax(v => v, null)); + + Assert.Multiple(() => + { + Assert.Throws(() => source!.MinMax()); + Assert.Throws(() => source!.MinMax(v => v)); + Assert.Throws(() => source!.MinMax(null)); + Assert.Throws(() => source!.MinMax(v => v, null)); + }); } [Test] public void MinMax_ShouldThrowInvalidOperationException_GivenEmptySource() { - Assert.Throws(() => Enumerable.Empty().MinMax()); - Assert.Throws(() => Array.Empty().MinMax()); - Assert.Throws(() => new List().MinMax()); + Assert.Multiple(() => + { + Assert.Throws(() => + { + Empty().MinMax(); + return; - Assert.Throws(() => Enumerable.Empty().MinMax(i => i * 2)); - Assert.Throws(() => Array.Empty().MinMax(i => i * 2)); - Assert.Throws(() => new List().MinMax(i => i * 2)); + static IEnumerable Empty() + { + yield break; + } + }); + Assert.Throws(() => Array.Empty().MinMax()); + Assert.Throws(() => new List().MinMax()); + + Assert.Throws(() => + { + Empty().MinMax(i => i * 2); + return; + + static IEnumerable Empty() + { + yield break; + } + }); + Assert.Throws(() => Array.Empty().MinMax(i => i * 2)); + Assert.Throws(() => new List().MinMax(i => i * 2)); + }); } [Test] public void MinMaxBy_ShouldReturnCorrectSelectedValues_UsingDefaultComparer() { - IEnumerable source = Enumerable.Range(1, 10).Select(i => new Person {Age = i}); + IEnumerable 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 source = Enumerable.Range(1, 10).Select(i => new Person {Age = i}); + IEnumerable source = Enumerable.Range(1, 10).Select(i => new Person { Age = i }); (Person minimum, Person maximum) = source.MinMaxBy(p => p.Age, new InverseComparer()); 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()); 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(() => source.MinMaxBy((Func)null!)); Assert.Throws(() => source.MinMaxBy((Func)null!, null)); @@ -201,8 +230,14 @@ internal class EnumerableTests { Assert.Throws(() => { - IEnumerable source = []; + IEnumerable source = Empty(); _ = source.MinMaxBy(p => p.Age); + return; + + static IEnumerable Empty() + { + yield break; + } }); Assert.Throws(() =>