Skip to content

Commit 79497a6

Browse files
authored
chore: migrate to Primary constructors and collection expressions (#532)
1 parent b47cdc9 commit 79497a6

File tree

98 files changed

+476
-566
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+476
-566
lines changed

Algorithms.Tests/Crypto/Digests/AsconDigestTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public void AsconHash_WhenGetByteLengthIsCalled_ReturnsCorrectValue()
159159
public void Update_ShouldProcessByte_WhenBufferIsFull()
160160
{
161161
// Arrange
162-
byte[] inputBytes = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 }; // 8 bytes to fill the buffer
162+
byte[] inputBytes = [0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77]; // 8 bytes to fill the buffer
163163

164164
// Act
165165
foreach (var input in inputBytes)
@@ -178,7 +178,7 @@ public void Update_ShouldProcessByte_WhenBufferIsFull()
178178
public void Update_ShouldNotProcess_WhenBufferIsNotFull()
179179
{
180180
// Arrange
181-
byte[] inputBytes = { 0x00, 0x11, 0x22, 0x33 }; // Only 4 bytes (buffer is not full)
181+
byte[] inputBytes = [0x00, 0x11, 0x22, 0x33]; // Only 4 bytes (buffer is not full)
182182

183183
// Act
184184
foreach (var input in inputBytes)
@@ -233,7 +233,7 @@ public void Update_ShouldHandleSingleByteCorrectly()
233233
public void Update_ShouldAccumulateStateWithMultipleUpdates()
234234
{
235235
// Arrange
236-
byte[] inputBytes = { 0x00, 0x11, 0x22 }; // Partial input
236+
byte[] inputBytes = [0x00, 0x11, 0x22]; // Partial input
237237

238238
// Act
239239
foreach (var input in inputBytes)
@@ -242,7 +242,7 @@ public void Update_ShouldAccumulateStateWithMultipleUpdates()
242242
}
243243

244244
// Add more data to fill the buffer.
245-
byte[] additionalBytes = { 0x33, 0x44, 0x55, 0x66, 0x77 };
245+
byte[] additionalBytes = [0x33, 0x44, 0x55, 0x66, 0x77];
246246
foreach (var input in additionalBytes)
247247
{
248248
asconHashA.Update(input);

Algorithms.Tests/Crypto/Paddings/Iso7816D4PaddingTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Algorithms.Crypto.Paddings;
1+
using Algorithms.Crypto.Paddings;
22

33
namespace Algorithms.Tests.Crypto.Paddings;
44

@@ -75,7 +75,7 @@ public void RemovePadding_WhenCalledWithValidInput_shouldReturnCorrectData()
7575

7676
var result = padding.RemovePadding(inputData);
7777

78-
result.Should().Equal(new byte[] { 1, 2, 3, 4, 5 });
78+
result.Should().Equal([1, 2, 3, 4, 5]);
7979
}
8080

8181
[Test]

Algorithms.Tests/Crypto/Utils/ByteEncodingUtils.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class ByteEncodingUtilsTests
99
public void BigEndianToUint64_ByteArray_ShouldConvertCorrectly()
1010
{
1111
// Arrange
12-
byte[] input = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF };
12+
byte[] input = [0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF];
1313
var expected = 0x0123456789ABCDEFUL;
1414

1515
// Act
@@ -23,7 +23,7 @@ public void BigEndianToUint64_ByteArray_ShouldConvertCorrectly()
2323
public void BigEndianToUint64_ByteArray_WithOffset_ShouldConvertCorrectly()
2424
{
2525
// Arrange
26-
byte[] input = { 0x00, 0x00, 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF };
26+
byte[] input = [0x00, 0x00, 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF];
2727
var expected = 0x0123456789ABCDEFUL;
2828

2929
// Act
@@ -53,7 +53,7 @@ public void UInt64ToBigEndian_ShouldWriteCorrectly()
5353
// Arrange
5454
var value = 0x0123456789ABCDEFUL;
5555
Span<byte> output = stackalloc byte[8];
56-
byte[] expected = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF };
56+
byte[] expected = [0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF];
5757

5858
// Act
5959
ByteEncodingUtils.UInt64ToBigEndian(value, output);
@@ -66,7 +66,7 @@ public void UInt64ToBigEndian_ShouldWriteCorrectly()
6666
public void BigEndianToUint64_InvalidOffset_ShouldThrowException()
6767
{
6868
// Arrange
69-
byte[] input = { 0x01, 0x23 };
69+
byte[] input = [0x01, 0x23];
7070

7171
// Act
7272
Action act = () => ByteEncodingUtils.BigEndianToUint64(input, 1);

Algorithms.Tests/Encoders/NysiisEncoderTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ namespace Algorithms.Tests.Encoders;
55
public class NysiisEncoderTests
66
{
77
private static readonly string[] Names =
8-
{
8+
[
99
"Jay", "John", "Jane", "Zayne", "Guerra", "Iga", "Cowan", "Louisa", "Arnie", "Olsen", "Corban", "Nava",
1010
"Cynthia Malone", "Amiee MacKee", "MacGyver", "Yasmin Edge",
11-
};
11+
];
1212

1313
private static readonly string[] Expected =
14-
{
14+
[
1515
"JY", "JAN", "JAN", "ZAYN", "GAR", "IG", "CAN", "LAS", "ARNY", "OLSAN", "CARBAN", "NAV", "CYNTANALAN",
1616
"ANANACY", "MCGYVAR", "YASNANADG",
17-
};
17+
];
1818

1919
private static IEnumerable<string[]> TestData => Names.Zip(Expected, (l, r) => new[] { l, r });
2020

Algorithms.Tests/Encoders/SoundexEncoderTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ namespace Algorithms.Tests.Encoders;
55
public static class SoundexEncoderTest
66
{
77
private static readonly string[] Names =
8-
{
8+
[
99
"Robert", "Rupert", "Rubin", "Ashcraft", "Ashcroft", "Tymczak", "Pfister", "Honeyman",
10-
};
10+
];
1111

12-
private static readonly string[] Expected = { "R163", "R163", "R150", "A261", "A261", "T522", "P236", "H555" };
12+
private static readonly string[] Expected = ["R163", "R163", "R150", "A261", "A261", "T522", "P236", "H555"];
1313

1414
private static IEnumerable<string[]> TestData => Names.Zip(Expected, (l, r) => new[] { l, r });
1515

Algorithms.Tests/Graph/BellmanFordTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void CorrectDistancesTest()
3535
{ vertex5, -4 }
3636
};
3737

38-
var bellmanFord = new BellmanFord<int>(graph, new Dictionary<Vertex<int>, double>(), new Dictionary<Vertex<int>, Vertex<int>?>());
38+
var bellmanFord = new BellmanFord<int>(graph, [], []);
3939

4040
var calculatedDistances = bellmanFord.Run(vertex1);
4141

@@ -61,7 +61,7 @@ public void NegativeWeightCycleTest()
6161
graph.AddEdge(vertex2, vertex3, -2);
6262
graph.AddEdge(vertex3, vertex1, -3);
6363

64-
var bellmanFord = new BellmanFord<int>(graph, new Dictionary<Vertex<int>, double>(), new Dictionary<Vertex<int>, Vertex<int>?>());
64+
var bellmanFord = new BellmanFord<int>(graph, [], []);
6565

6666
Action action = () => bellmanFord.Run(vertex1);
6767

Algorithms.Tests/Graph/BreadthFirstTreeTraversalTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ public static class BreadthFirstTreeTraversalTests
99
public static void CorrectLevelOrderTraversal()
1010
{
1111
// Arrange
12-
int[] correctPath = { 7, 4, 13, 2, 5, 11, 15, 14, 16 };
13-
int[] insertionOrder = { 7, 13, 11, 15, 14, 4, 5, 16, 2 };
12+
int[] correctPath = [7, 4, 13, 2, 5, 11, 15, 14, 16];
13+
int[] insertionOrder = [7, 13, 11, 15, 14, 4, 5, 16, 2];
1414
BinarySearchTree<int> testTree = new BinarySearchTree<int>();
1515
foreach (int data in insertionOrder)
1616
{
@@ -60,7 +60,7 @@ public static void DeepestNodeInTree()
6060
{
6161
// Arrange
6262
BinarySearchTree<int> testTree = new BinarySearchTree<int>();
63-
int[] insertion = { 7, 13, 11, 15, 4, 5, 12, 2, 9 };
63+
int[] insertion = [7, 13, 11, 15, 4, 5, 12, 2, 9];
6464
foreach (int data in insertion)
6565
{
6666
testTree.Add(data);

Algorithms.Tests/LinearAlgebra/Eigenvalue/PowerIterationTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Algorithms.Tests.LinearAlgebra.Eigenvalue;
55
public class PowerIterationTests
66
{
77
private static readonly object[] DominantVectorTestCases =
8-
{
8+
[
99
new object[]
1010
{
1111
3.0,
@@ -18,7 +18,7 @@ public class PowerIterationTests
1818
new[] { 0.91287093, 0.40824829 },
1919
new[,] { { 2.0, 5.0 }, { 1.0, 2.0 } },
2020
},
21-
};
21+
];
2222

2323
private readonly double epsilon = Math.Pow(10, -5);
2424

Algorithms.Tests/Numeric/AutomorphicNumberTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,21 @@ public void TestInvalidAutomorphicNumbers(int number)
5555
[TestCase(1, 100)]
5656
public void TestAutomorphicNumberSequence(int lower, int upper)
5757
{
58-
List<long> automorphicList = new() { 1, 5, 6, 25, 76 };
58+
List<long> automorphicList = [1, 5, 6, 25, 76];
5959
Assert.That(AutomorphicNumber.GetAutomorphicNumbers(lower, upper), Is.EqualTo(automorphicList));
6060
}
6161

6262
[TestCase(8, 12)]
6363
public void TestNoAutomorphicNumberInTheSequence(int lower, int upper)
6464
{
65-
List<long> automorphicList = new();
65+
List<long> automorphicList = [];
6666
Assert.That(AutomorphicNumber.GetAutomorphicNumbers(lower, upper), Is.EqualTo(automorphicList));
6767
}
6868

6969
[TestCase(25, 25)]
7070
public void TestAutomorphicNumberSequenceSameBounds(int lower, int upper)
7171
{
72-
List<long> automorphicList = new() { 25 };
72+
List<long> automorphicList = [25];
7373
Assert.That(AutomorphicNumber.GetAutomorphicNumbers(lower, upper), Is.EqualTo(automorphicList));
7474
}
7575

Algorithms.Tests/Numeric/NewtonSquareRootTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
namespace Algorithms.Tests.Numeric;
1+
namespace Algorithms.Tests.Numeric;
22

33
public class NewtonSquareRootTests
44
{
55
private static readonly object[] CalculateSquareRootInput =
6-
{
6+
[
77
new object[] {BigInteger.One, BigInteger.One},
88
new object[] {new BigInteger(221295376), new BigInteger(14876)},
99
new object[] {new BigInteger(2530995481), new BigInteger(50309)},
@@ -13,7 +13,7 @@ public class NewtonSquareRootTests
1313
new object[] {new BigInteger(5551442064), new BigInteger(74508)},
1414
new object[] {new BigInteger(6980435401), new BigInteger(83549)},
1515
new object[] {new BigInteger(8036226025), new BigInteger(89645)},
16-
};
16+
];
1717

1818
[TestCaseSource(nameof(CalculateSquareRootInput))]
1919
public void CalculateSquareRootTest(BigInteger number, BigInteger result)

0 commit comments

Comments
 (0)