Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Algorithms.Tests/Crypto/Digests/AsconDigestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public void AsconHash_WhenGetByteLengthIsCalled_ReturnsCorrectValue()
public void Update_ShouldProcessByte_WhenBufferIsFull()
{
// Arrange
byte[] inputBytes = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 }; // 8 bytes to fill the buffer
byte[] inputBytes = [0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77]; // 8 bytes to fill the buffer

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

// Act
foreach (var input in inputBytes)
Expand Down Expand Up @@ -233,7 +233,7 @@ public void Update_ShouldHandleSingleByteCorrectly()
public void Update_ShouldAccumulateStateWithMultipleUpdates()
{
// Arrange
byte[] inputBytes = { 0x00, 0x11, 0x22 }; // Partial input
byte[] inputBytes = [0x00, 0x11, 0x22]; // Partial input

// Act
foreach (var input in inputBytes)
Expand All @@ -242,7 +242,7 @@ public void Update_ShouldAccumulateStateWithMultipleUpdates()
}

// Add more data to fill the buffer.
byte[] additionalBytes = { 0x33, 0x44, 0x55, 0x66, 0x77 };
byte[] additionalBytes = [0x33, 0x44, 0x55, 0x66, 0x77];
foreach (var input in additionalBytes)
{
asconHashA.Update(input);
Expand Down
4 changes: 2 additions & 2 deletions Algorithms.Tests/Crypto/Paddings/Iso7816D4PaddingTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Algorithms.Crypto.Paddings;
using Algorithms.Crypto.Paddings;

namespace Algorithms.Tests.Crypto.Paddings;

Expand Down Expand Up @@ -75,7 +75,7 @@ public void RemovePadding_WhenCalledWithValidInput_shouldReturnCorrectData()

var result = padding.RemovePadding(inputData);

result.Should().Equal(new byte[] { 1, 2, 3, 4, 5 });
result.Should().Equal([1, 2, 3, 4, 5]);
}

[Test]
Expand Down
8 changes: 4 additions & 4 deletions Algorithms.Tests/Crypto/Utils/ByteEncodingUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class ByteEncodingUtilsTests
public void BigEndianToUint64_ByteArray_ShouldConvertCorrectly()
{
// Arrange
byte[] input = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF };
byte[] input = [0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF];
var expected = 0x0123456789ABCDEFUL;

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

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

// Act
ByteEncodingUtils.UInt64ToBigEndian(value, output);
Expand All @@ -66,7 +66,7 @@ public void UInt64ToBigEndian_ShouldWriteCorrectly()
public void BigEndianToUint64_InvalidOffset_ShouldThrowException()
{
// Arrange
byte[] input = { 0x01, 0x23 };
byte[] input = [0x01, 0x23];

// Act
Action act = () => ByteEncodingUtils.BigEndianToUint64(input, 1);
Expand Down
8 changes: 4 additions & 4 deletions Algorithms.Tests/Encoders/NysiisEncoderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ namespace Algorithms.Tests.Encoders;
public class NysiisEncoderTests
{
private static readonly string[] Names =
{
[
"Jay", "John", "Jane", "Zayne", "Guerra", "Iga", "Cowan", "Louisa", "Arnie", "Olsen", "Corban", "Nava",
"Cynthia Malone", "Amiee MacKee", "MacGyver", "Yasmin Edge",
};
];

private static readonly string[] Expected =
{
[
"JY", "JAN", "JAN", "ZAYN", "GAR", "IG", "CAN", "LAS", "ARNY", "OLSAN", "CARBAN", "NAV", "CYNTANALAN",
"ANANACY", "MCGYVAR", "YASNANADG",
};
];

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

Expand Down
6 changes: 3 additions & 3 deletions Algorithms.Tests/Encoders/SoundexEncoderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ namespace Algorithms.Tests.Encoders;
public static class SoundexEncoderTest
{
private static readonly string[] Names =
{
[
"Robert", "Rupert", "Rubin", "Ashcraft", "Ashcroft", "Tymczak", "Pfister", "Honeyman",
};
];

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

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

Expand Down
6 changes: 3 additions & 3 deletions Algorithms.Tests/Graph/BreadthFirstTreeTraversalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public static class BreadthFirstTreeTraversalTests
public static void CorrectLevelOrderTraversal()
{
// Arrange
int[] correctPath = { 7, 4, 13, 2, 5, 11, 15, 14, 16 };
int[] insertionOrder = { 7, 13, 11, 15, 14, 4, 5, 16, 2 };
int[] correctPath = [7, 4, 13, 2, 5, 11, 15, 14, 16];
int[] insertionOrder = [7, 13, 11, 15, 14, 4, 5, 16, 2];
BinarySearchTree<int> testTree = new BinarySearchTree<int>();
foreach (int data in insertionOrder)
{
Expand Down Expand Up @@ -60,7 +60,7 @@ public static void DeepestNodeInTree()
{
// Arrange
BinarySearchTree<int> testTree = new BinarySearchTree<int>();
int[] insertion = { 7, 13, 11, 15, 4, 5, 12, 2, 9 };
int[] insertion = [7, 13, 11, 15, 4, 5, 12, 2, 9];
foreach (int data in insertion)
{
testTree.Add(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Algorithms.Tests.LinearAlgebra.Eigenvalue;
public class PowerIterationTests
{
private static readonly object[] DominantVectorTestCases =
{
[
new object[]
{
3.0,
Expand All @@ -18,7 +18,7 @@ public class PowerIterationTests
new[] { 0.91287093, 0.40824829 },
new[,] { { 2.0, 5.0 }, { 1.0, 2.0 } },
},
};
];

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

Expand Down
6 changes: 3 additions & 3 deletions Algorithms.Tests/Numeric/NewtonSquareRootTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace Algorithms.Tests.Numeric;
namespace Algorithms.Tests.Numeric;

public class NewtonSquareRootTests
{
private static readonly object[] CalculateSquareRootInput =
{
[
new object[] {BigInteger.One, BigInteger.One},
new object[] {new BigInteger(221295376), new BigInteger(14876)},
new object[] {new BigInteger(2530995481), new BigInteger(50309)},
Expand All @@ -13,7 +13,7 @@ public class NewtonSquareRootTests
new object[] {new BigInteger(5551442064), new BigInteger(74508)},
new object[] {new BigInteger(6980435401), new BigInteger(83549)},
new object[] {new BigInteger(8036226025), new BigInteger(89645)},
};
];

[TestCaseSource(nameof(CalculateSquareRootInput))]
public void CalculateSquareRootTest(BigInteger number, BigInteger result)
Expand Down
4 changes: 2 additions & 2 deletions Algorithms.Tests/Other/JulianEasterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ public static void CalculateTest(int year, DateTime expected)
}

private static readonly object[] CalculateCases =
{
[
new object[] { 1800, new DateTime(1800, 04, 08, 00, 00, 00, DateTimeKind.Utc) },
new object[] { 1950, new DateTime(1950, 03, 27, 00, 00, 00, DateTimeKind.Utc) },
new object[] { 1991, new DateTime(1991, 03, 25, 00, 00, 00, DateTimeKind.Utc) },
new object[] { 2000, new DateTime(2000, 04, 17, 00, 00, 00, DateTimeKind.Utc) },
new object[] { 2199, new DateTime(2199, 04, 07, 00, 00, 00, DateTimeKind.Utc) }
};
];

}
4 changes: 2 additions & 2 deletions Algorithms.Tests/Other/SieveOfEratosthenesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Algorithms.Tests.Other;
public static class SieveOfEratosthenesTests
{
private static readonly long[] First10000PrimeNumbers =
{
[
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103,
107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223,
227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347,
Expand Down Expand Up @@ -662,7 +662,7 @@ public static class SieveOfEratosthenesTests
104383, 104393, 104399, 104417, 104459, 104471, 104473, 104479, 104491, 104513, 104527, 104537, 104543,
104549, 104551, 104561, 104579, 104593, 104597, 104623, 104639, 104651, 104659, 104677, 104681, 104683,
104693, 104701, 104707, 104711, 104717, 104723, 104729,
};
];

[Test]
public static void First10_000PrimesCorrect() =>
Expand Down
12 changes: 6 additions & 6 deletions Algorithms.Tests/Other/WelfordsVarianceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void WelfordVariance_Example4()
[Test]
public void WelfordVariance_Example5()
{
var stats = new WelfordsVariance(new double[] { 2, 2, 5, 7 });
var stats = new WelfordsVariance([2, 2, 5, 7]);
Assert.That(stats.Count, Is.EqualTo(4));
Assert.That(stats.Mean, Is.EqualTo(4).Within(0.0000001));
Assert.That(stats.Variance, Is.EqualTo(4.5).Within(0.0000001));
Expand All @@ -75,7 +75,7 @@ public void WelfordVariance_Example5()
public void WelfordVariance_Example6()
{
var stats = new WelfordsVariance();
stats.AddRange(new double[] { 2, 4, 4, 4, 5, 5, 7, 9 });
stats.AddRange([2, 4, 4, 4, 5, 5, 7, 9]);
Assert.That(stats.Count, Is.EqualTo(8));
Assert.That(stats.Mean, Is.EqualTo(5).Within(0.0000001));
Assert.That(stats.Variance, Is.EqualTo(4).Within(0.0000001));
Expand All @@ -86,7 +86,7 @@ public void WelfordVariance_Example6()
public void WelfordVariance_Example7()
{
var stats = new WelfordsVariance();
stats.AddRange(new double[] { 9, 2, 5, 4, 12, 7, 8, 11, 9, 3, 7, 4, 12, 5, 4, 10, 9, 6, 9, 4 });
stats.AddRange([9, 2, 5, 4, 12, 7, 8, 11, 9, 3, 7, 4, 12, 5, 4, 10, 9, 6, 9, 4]);
Assert.That(stats.Count, Is.EqualTo(20));
Assert.That(stats.Mean, Is.EqualTo(7).Within(0.0000001));
Assert.That(stats.Variance, Is.EqualTo(8.9).Within(0.0000001));
Expand All @@ -97,7 +97,7 @@ public void WelfordVariance_Example7()
public void WelfordVariance_Example8()
{
var stats = new WelfordsVariance();
stats.AddRange(new[] { 51.3, 55.6, 49.9, 52.0 });
stats.AddRange([51.3, 55.6, 49.9, 52.0]);
Assert.That(stats.Count, Is.EqualTo(4));
Assert.That(stats.Mean, Is.EqualTo(52.2).Within(0.0000001));
Assert.That(stats.Variance, Is.EqualTo(4.4250000).Within(0.0000001));
Expand All @@ -108,7 +108,7 @@ public void WelfordVariance_Example8()
public void WelfordVariance_Example9()
{
var stats = new WelfordsVariance();
stats.AddRange(new double[] { -5, -3, -1, 1, 3 });
stats.AddRange([-5, -3, -1, 1, 3]);
Assert.That(stats.Count, Is.EqualTo(5));
Assert.That(stats.Mean, Is.EqualTo(-1).Within(0.0000001));
Assert.That(stats.Variance, Is.EqualTo(8).Within(0.0000001));
Expand All @@ -119,7 +119,7 @@ public void WelfordVariance_Example9()
public void WelfordVariance_Example10()
{
var stats = new WelfordsVariance();
stats.AddRange(new double[] { -1, 0, 1 });
stats.AddRange([-1, 0, 1]);
Assert.That(stats.Count, Is.EqualTo(3));
Assert.That(stats.Mean, Is.EqualTo(0).Within(0.0000001));
Assert.That(stats.Variance, Is.EqualTo(0.6666667).Within(0.0000001));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ public class GenerateSingleCoinChangesTests
public void GenerateSingleCoinChangesTests_Success()
{
DynamicCoinChangeSolver
.GenerateSingleCoinChanges(6, new[] { 1, 2, 3 })
.GenerateSingleCoinChanges(6, [1, 2, 3])
.SequenceEqual(new[] { 3, 4, 5 })
.Should().BeTrue();

DynamicCoinChangeSolver
.GenerateSingleCoinChanges(10, new[] { 1, 2, 3, 7, 12, 15, 14 })
.GenerateSingleCoinChanges(10, [1, 2, 3, 7, 12, 15, 14])
.SequenceEqual(new[] { 3, 7, 8, 9 })
.Should().BeTrue();

DynamicCoinChangeSolver
.GenerateSingleCoinChanges(1, new[] { 1, 2, 3, 7, 12, 15, 14 })
.GenerateSingleCoinChanges(1, [1, 2, 3, 7, 12, 15, 14])
.SequenceEqual(new[] { 0 })
.Should().BeTrue();

DynamicCoinChangeSolver
.GenerateSingleCoinChanges(2, new[] { 1, 2, 3, 7, 12, 15, 14 })
.GenerateSingleCoinChanges(2, [1, 2, 3, 7, 12, 15, 14])
.SequenceEqual(new[] { 0, 1 })
.Should().BeTrue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ public class MakeCoinChangeDynamicTests
public void MakeCoinChangeDynamicTest_Success()
{
DynamicCoinChangeSolver
.MakeCoinChangeDynamic(6, new[] { 1, 3, 4 })
.MakeCoinChangeDynamic(6, [1, 3, 4])
.SequenceEqual(new[] { 3, 3 })
.Should().BeTrue();

DynamicCoinChangeSolver
.MakeCoinChangeDynamic(8, new[] { 1, 3, 4 })
.MakeCoinChangeDynamic(8, [1, 3, 4])
.SequenceEqual(new[] { 4, 4 })
.Should().BeTrue();

DynamicCoinChangeSolver
.MakeCoinChangeDynamic(25, new[] { 1, 3, 4, 12, 13, 14 })
.MakeCoinChangeDynamic(25, [1, 3, 4, 12, 13, 14])
.SequenceEqual(new[] { 13, 12 })
.Should().BeTrue();

DynamicCoinChangeSolver
.MakeCoinChangeDynamic(26, new[] { 1, 3, 4, 12, 13, 14 })
.MakeCoinChangeDynamic(26, [1, 3, 4, 12, 13, 14])
.SequenceEqual(new[] { 14, 12 })
.Should().BeTrue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ namespace Algorithms.Tests.Sequences;
[TestFixture]
public static class MatchstickTriangleSequenceTests
{
private static BigInteger[] _testList = {
private static BigInteger[] _testList = [
0, 1, 5, 13, 27, 48, 78, 118, 170, 235, 315, 411, 525, 658,
812, 988, 1188, 1413, 1665, 1945, 2255, 2596, 2970, 3378,
3822, 4303, 4823, 5383, 5985, 6630, 7320, 8056, 8840, 9673,
10557, 11493, 12483, 13528, 14630, 15790, 17010, 18291,
19635, 21043, 22517,
};
];
/// <summary>
/// This test uses the list values provided from http://oeis.org/A002717/list.
/// </summary>
Expand Down
6 changes: 3 additions & 3 deletions Algorithms.Tests/Sequences/OnesCountingSequenceTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Algorithms.Sequences;
using Algorithms.Sequences;

namespace Algorithms.Tests.Sequences;

Expand All @@ -13,7 +13,7 @@ public class OnesCountingSequenceTest
/// While the file contains 10,000 values, this only tests 1000.
/// </para>
/// </summary>
private readonly BigInteger[] oeisValues = {
private readonly BigInteger[] oeisValues = [
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2,
3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3,
3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3,
Expand Down Expand Up @@ -54,7 +54,7 @@ public class OnesCountingSequenceTest
7, 7, 8, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8, 5, 6, 6, 7, 6, 7,
7, 8, 6, 7, 7, 8, 7, 8, 8, 9, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7,
8, 5, 6, 6, 7, 6, 7, 7, 8, 6, 7, 7, 8, 7, 8, 8, 9, 5, 6, 6, 7, 6, 7, 7, 8,
};
];

/// <summary>
/// <para>
Expand Down
6 changes: 3 additions & 3 deletions Algorithms.Tests/Sequences/TetrahedralSequenceTests.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using Algorithms.Sequences;
using Algorithms.Sequences;

namespace Algorithms.Tests.Sequences;

[TestFixture]
public class TetrahedralSequenceTests
{
private static readonly BigInteger[] TestList = {
private static readonly BigInteger[] TestList = [
0, 1, 4, 10, 20, 35, 56, 84, 120, 165, 220, 286, 364, 455,
560, 680, 816, 969, 1140, 1330, 1540, 1771, 2024, 2300,
2600, 2925, 3276, 3654, 4060, 4495, 4960, 5456, 5984, 6545,
7140, 7770, 8436, 9139, 9880, 10660, 11480, 12341, 13244,
14190, 15180,
};
];

/// <summary>
/// This test uses the list values provided from http://oeis.org/A000292/list.
Expand Down
Loading