From bd546e6f04b2af3c7f43dc604e6217d4d2906902 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Wed, 13 Nov 2024 18:56:13 +0000 Subject: [PATCH] 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]; } ///