Skip to content

Commit 833a0fb

Browse files
authored
Update StyleCop (#480)
1 parent 36a7dd6 commit 833a0fb

29 files changed

+219
-218
lines changed

Algorithms.Tests/ModularArithmetic/ExtendedEuclideanAlgorithmTest.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ public static void TestCompute(long a, long b, long expectedGCD, long expectedBe
2323
var eeaResult = ExtendedEuclideanAlgorithm.Compute(a, b);
2424

2525
// Assert
26-
Assert.That(eeaResult.gcd, Is.EqualTo(expectedGCD));
27-
Assert.That(eeaResult.bezoutA, Is.EqualTo(expectedBezoutOfA));
28-
Assert.That(eeaResult.bezoutB, Is.EqualTo(expectedBezoutOfB));
26+
Assert.That(eeaResult.Gcd, Is.EqualTo(expectedGCD));
27+
Assert.That(eeaResult.BezoutA, Is.EqualTo(expectedBezoutOfA));
28+
Assert.That(eeaResult.BezoutB, Is.EqualTo(expectedBezoutOfB));
2929
}
3030

3131
[TestCase(240, 46, 2, -9, 47)]
@@ -45,8 +45,8 @@ public static void TestCompute_BigInteger(long a, long b, long expectedGCD, long
4545
var eeaResult = ExtendedEuclideanAlgorithm.Compute(new BigInteger(a), new BigInteger(b));
4646

4747
// Assert
48-
Assert.That(eeaResult.gcd, Is.EqualTo(new BigInteger(expectedGCD)));
49-
Assert.That(eeaResult.bezoutA, Is.EqualTo(new BigInteger(expectedBezoutOfA)));
50-
Assert.That(eeaResult.bezoutB, Is.EqualTo(new BigInteger(expectedBezoutOfB)));
48+
Assert.That(eeaResult.Gcd, Is.EqualTo(new BigInteger(expectedGCD)));
49+
Assert.That(eeaResult.BezoutA, Is.EqualTo(new BigInteger(expectedBezoutOfA)));
50+
Assert.That(eeaResult.BezoutB, Is.EqualTo(new BigInteger(expectedBezoutOfB)));
5151
}
5252
}

Algorithms/Algorithms.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<ItemGroup>
1919
<PackageReference Include="SkiaSharp" Version="2.88.8" />
2020
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.8" />
21-
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
21+
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
2222
<PrivateAssets>all</PrivateAssets>
2323
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2424
</PackageReference>

Algorithms/DataCompression/BurrowsWheelerTransform.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class BurrowsWheelerTransform
1616
/// rotation matrix.
1717
/// </summary>
1818
/// <param name="s">Input string.</param>
19-
public (string encoded, int index) Encode(string s)
19+
public (string Encoded, int Index) Encode(string s)
2020
{
2121
if (s.Length == 0)
2222
{

Algorithms/DataCompression/HuffmanCompressor.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public HuffmanCompressor(IComparisonSorter<ListNode> sorter, Translator translat
2727
/// </summary>
2828
/// <param name="uncompressedText">Text message to compress.</param>
2929
/// <returns>Compressed string and keys to decompress it.</returns>
30-
public (string compressedText, Dictionary<string, string> decompressionKeys) Compress(string uncompressedText)
30+
public (string CompressedText, Dictionary<string, string> DecompressionKeys) Compress(string uncompressedText)
3131
{
3232
if (string.IsNullOrEmpty(uncompressedText))
3333
{
@@ -70,7 +70,7 @@ private static ListNode[] GetListNodesFromText(string text)
7070
return occurenceCounts.Select(kvp => new ListNode(kvp.Key, 1d * kvp.Value / text.Length)).ToArray();
7171
}
7272

73-
private (Dictionary<string, string> compressionKeys, Dictionary<string, string> decompressionKeys) GetKeys(
73+
private (Dictionary<string, string> CompressionKeys, Dictionary<string, string> DecompressionKeys) GetKeys(
7474
ListNode tree)
7575
{
7676
var compressionKeys = new Dictionary<string, string>();

Algorithms/DataCompression/ShannonFanoCompressor.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ namespace Algorithms.DataCompression;
1010
/// </summary>
1111
public class ShannonFanoCompressor
1212
{
13-
private readonly IHeuristicKnapsackSolver<(char symbol, double frequency)> splitter;
13+
private readonly IHeuristicKnapsackSolver<(char Symbol, double Frequency)> splitter;
1414
private readonly Translator translator;
1515

1616
public ShannonFanoCompressor(
17-
IHeuristicKnapsackSolver<(char symbol, double frequency)> splitter,
17+
IHeuristicKnapsackSolver<(char Symbol, double Frequency)> splitter,
1818
Translator translator)
1919
{
2020
this.splitter = splitter;
@@ -27,7 +27,7 @@ public ShannonFanoCompressor(
2727
/// </summary>
2828
/// <param name="uncompressedText">Text message to compress.</param>
2929
/// <returns>Compressed string and keys to decompress it.</returns>
30-
public (string compressedText, Dictionary<string, string> decompressionKeys) Compress(string uncompressedText)
30+
public (string CompressedText, Dictionary<string, string> DecompressionKeys) Compress(string uncompressedText)
3131
{
3232
if (string.IsNullOrEmpty(uncompressedText))
3333
{
@@ -49,16 +49,16 @@ public ShannonFanoCompressor(
4949
return (translator.Translate(uncompressedText, compressionKeys), decompressionKeys);
5050
}
5151

52-
private (Dictionary<string, string> compressionKeys, Dictionary<string, string> decompressionKeys) GetKeys(
52+
private (Dictionary<string, string> CompressionKeys, Dictionary<string, string> DecompressionKeys) GetKeys(
5353
ListNode tree)
5454
{
5555
var compressionKeys = new Dictionary<string, string>();
5656
var decompressionKeys = new Dictionary<string, string>();
5757

5858
if (tree.Data.Length == 1)
5959
{
60-
compressionKeys.Add(tree.Data[0].symbol.ToString(), string.Empty);
61-
decompressionKeys.Add(string.Empty, tree.Data[0].symbol.ToString());
60+
compressionKeys.Add(tree.Data[0].Symbol.ToString(), string.Empty);
61+
decompressionKeys.Add(string.Empty, tree.Data[0].Symbol.ToString());
6262
return (compressionKeys, decompressionKeys);
6363
}
6464

@@ -86,7 +86,7 @@ private ListNode GenerateShannonFanoTree(ListNode node)
8686
return node;
8787
}
8888

89-
var left = splitter.Solve(node.Data, 0.5 * node.Data.Sum(x => x.frequency), x => x.frequency, _ => 1);
89+
var left = splitter.Solve(node.Data, 0.5 * node.Data.Sum(x => x.Frequency), x => x.Frequency, _ => 1);
9090
var right = node.Data.Except(left).ToArray();
9191

9292
node.LeftChild = GenerateShannonFanoTree(new ListNode(left));
@@ -122,9 +122,9 @@ private ListNode GetListNodeFromText(string text)
122122
/// </summary>
123123
public class ListNode
124124
{
125-
public ListNode((char symbol, double frequency)[] data) => Data = data;
125+
public ListNode((char Symbol, double Frequency)[] data) => Data = data;
126126

127-
public (char symbol, double frequency)[] Data { get; }
127+
public (char Symbol, double Frequency)[] Data { get; }
128128

129129
public ListNode? RightChild { get; set; }
130130

Algorithms/Encoders/NysiisEncoder.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ private string RemoveDuplicates(string text)
5151

5252
private string TrimEnd(string text)
5353
{
54-
var checks = new (string from, string to)?[]
54+
var checks = new (string From, string To)?[]
5555
{
5656
("S", string.Empty),
5757
("AY", "Y"),
5858
("A", string.Empty),
5959
};
60-
var replacement = checks.FirstOrDefault(t => text.EndsWith(t!.Value.from));
60+
var replacement = checks.FirstOrDefault(t => text.EndsWith(t!.Value.From));
6161
if (replacement is { })
6262
{
6363
var (from, to) = replacement!.Value;
@@ -69,7 +69,7 @@ private string TrimEnd(string text)
6969

7070
private string ReplaceStep(string text, int i)
7171
{
72-
(string from, string to)[] replacements =
72+
(string From, string To)[] replacements =
7373
{
7474
("EV", "AF"),
7575
("E", "A"),
@@ -134,7 +134,7 @@ private bool TryReplace(string text, int index, (string, string)[] opts, out str
134134

135135
private string StartReplace(string start)
136136
{
137-
var checks = new (string from, string to)?[]
137+
var checks = new (string From, string To)?[]
138138
{
139139
("MAC", "MCC"),
140140
("KN", "NN"),
@@ -143,7 +143,7 @@ private string StartReplace(string start)
143143
("PF", "FF"),
144144
("SCH", "SSS"),
145145
};
146-
var replacement = checks.FirstOrDefault(t => start.StartsWith(t!.Value.from));
146+
var replacement = checks.FirstOrDefault(t => start.StartsWith(t!.Value.From));
147147
if (replacement is { })
148148
{
149149
var (from, to) = replacement!.Value;
@@ -155,7 +155,7 @@ private string StartReplace(string start)
155155

156156
private string EndReplace(string end)
157157
{
158-
var checks = new (string from, string to)?[]
158+
var checks = new (string From, string To)?[]
159159
{
160160
("EE", "Y"),
161161
("IE", "Y"),
@@ -164,7 +164,7 @@ private string EndReplace(string end)
164164
("NT", "D"),
165165
("ND", "D"),
166166
};
167-
var replacement = checks.FirstOrDefault(t => end.EndsWith(t!.Value.from));
167+
var replacement = checks.FirstOrDefault(t => end.EndsWith(t!.Value.From));
168168
if (replacement is { })
169169
{
170170
var (from, to) = replacement!.Value;
@@ -175,5 +175,5 @@ private string EndReplace(string end)
175175
}
176176

177177
private string Replace(string text, int index, int length, string substitute) =>
178-
text[..index] + substitute + text[(index + length) ..];
178+
text[..index] + substitute + text[(index + length)..];
179179
}

Algorithms/Graph/FloydWarshall.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class FloydWarshall<T>
4949
{
5050
for (var j = 0; j < distances.GetLength(0); j++)
5151
{
52-
var dist = graph.AdjacentDistance(graph.Vertices[i] !, graph.Vertices[j] !);
52+
var dist = graph.AdjacentDistance(graph.Vertices[i]!, graph.Vertices[j]!);
5353
distances[i, j] = dist != 0 ? dist : double.PositiveInfinity;
5454
}
5555
}

Algorithms/LinearAlgebra/Eigenvalue/PowerIteration.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static class PowerIteration
2727
/// <returns>Dominant eigenvalue and eigenvector pair.</returns>
2828
/// <exception cref="ArgumentException">The <paramref name="source" /> matrix is not square-shaped.</exception>
2929
/// <exception cref="ArgumentException">The length of the start vector doesn't equal the size of the source matrix.</exception>
30-
public static (double eigenvalue, double[] eigenvector) Dominant(
30+
public static (double Eigenvalue, double[] Eigenvector) Dominant(
3131
double[,] source,
3232
double[] startVector,
3333
double error = 0.00001)
@@ -61,7 +61,7 @@ public static (double eigenvalue, double[] eigenvector) Dominant(
6161

6262
var eigenvalue = source.Multiply(currentEigenVector.ToColumnVector()).ToRowVector().Magnitude();
6363

64-
return (eigenvalue, eigenvector: currentEigenVector);
64+
return (eigenvalue, Eigenvector: currentEigenVector);
6565
}
6666

6767
/// <summary>
@@ -81,6 +81,6 @@ public static (double eigenvalue, double[] eigenvector) Dominant(
8181
/// <returns>Dominant eigenvalue and eigenvector pair.</returns>
8282
/// <exception cref="ArgumentException">The <paramref name="source" /> matrix is not square-shaped.</exception>
8383
/// <exception cref="ArgumentException">The length of the start vector doesn't equal the size of the source matrix.</exception>
84-
public static (double eigenvalue, double[] eigenvector) Dominant(double[,] source, double error = 0.00001) =>
84+
public static (double Eigenvalue, double[] Eigenvector) Dominant(double[,] source, double error = 0.00001) =>
8585
Dominant(source, new Random().NextVector(source.GetLength(1)), error);
8686
}

Algorithms/ModularArithmetic/ChineseRemainderTheorem.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static long Compute(List<long> listOfAs, List<long> listOfNs)
4949
var n_i = listOfNs[i];
5050
var modulus_i = prodN / n_i;
5151

52-
var bezout_modulus_i = ExtendedEuclideanAlgorithm.Compute(n_i, modulus_i).bezoutB;
52+
var bezout_modulus_i = ExtendedEuclideanAlgorithm.Compute(n_i, modulus_i).BezoutB;
5353
result += a_i * bezout_modulus_i * modulus_i;
5454
}
5555

@@ -102,7 +102,7 @@ public static BigInteger Compute(List<BigInteger> listOfAs, List<BigInteger> lis
102102
var n_i = listOfNs[i];
103103
var modulus_i = prodN / n_i;
104104

105-
var bezout_modulus_i = ExtendedEuclideanAlgorithm.Compute(n_i, modulus_i).bezoutB;
105+
var bezout_modulus_i = ExtendedEuclideanAlgorithm.Compute(n_i, modulus_i).BezoutB;
106106
result += a_i * bezout_modulus_i * modulus_i;
107107
}
108108

@@ -145,7 +145,7 @@ private static void CheckRequirements(List<long> listOfAs, List<long> listOfNs)
145145
for (var j = i + 1; j < listOfNs.Count; j++)
146146
{
147147
long gcd;
148-
if ((gcd = ExtendedEuclideanAlgorithm.Compute(listOfNs[i], listOfNs[j]).gcd) != 1L)
148+
if ((gcd = ExtendedEuclideanAlgorithm.Compute(listOfNs[i], listOfNs[j]).Gcd) != 1L)
149149
{
150150
throw new ArgumentException($"The GCD of n_{i} = {listOfNs[i]} and n_{j} = {listOfNs[j]} equals {gcd} and thus these values aren't coprime.");
151151
}
@@ -182,7 +182,7 @@ private static void CheckRequirements(List<BigInteger> listOfAs, List<BigInteger
182182
for (var j = i + 1; j < listOfNs.Count; j++)
183183
{
184184
BigInteger gcd;
185-
if ((gcd = ExtendedEuclideanAlgorithm.Compute(listOfNs[i], listOfNs[j]).gcd) != BigInteger.One)
185+
if ((gcd = ExtendedEuclideanAlgorithm.Compute(listOfNs[i], listOfNs[j]).Gcd) != BigInteger.One)
186186
{
187187
throw new ArgumentException($"The GCD of n_{i} = {listOfNs[i]} and n_{j} = {listOfNs[j]} equals {gcd} and thus these values aren't coprime.");
188188
}

Algorithms/ModularArithmetic/ExtendedEuclideanAlgorithm.cs

+10-10
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ namespace Algorithms.ModularArithmetic;
88
public static class ExtendedEuclideanAlgorithm
99
{
1010
/// <summary>
11-
/// Computes the greatest common divisor (gcd) of integers a and b, also the coefficients of Bézout's identity,
12-
/// which are integers x and y such that a*bezoutCoefficientOfA + b*bezoutCoefficientOfB = gcd(a, b).
11+
/// Computes the greatest common divisor (Gcd) of integers a and b, also the coefficients of Bézout's identity,
12+
/// which are integers x and y such that a*bezoutCoefficientOfA + b*bezoutCoefficientOfB = Gcd(a, b).
1313
/// </summary>
1414
/// <param name="a">Input number.</param>
1515
/// <param name="b">Second input number.</param>
16-
/// <returns>A record of ExtendedEuclideanAlgorithmResult containing the bezout coefficients of a and b as well as the gcd(a,b).</returns>
16+
/// <returns>A record of ExtendedEuclideanAlgorithmResult containing the bezout coefficients of a and b as well as the Gcd(a,b).</returns>
1717
public static ExtendedEuclideanAlgorithmResult<long> Compute(long a, long b)
1818
{
1919
long quotient;
@@ -46,12 +46,12 @@ public static ExtendedEuclideanAlgorithmResult<long> Compute(long a, long b)
4646
}
4747

4848
/// <summary>
49-
/// Computes the greatest common divisor (gcd) of integers a and b, also the coefficients of Bézout's identity,
50-
/// which are integers x and y such that a*bezoutCoefficientOfA + b*bezoutCoefficientOfB = gcd(a, b).
49+
/// Computes the greatest common divisor (Gcd) of integers a and b, also the coefficients of Bézout's identity,
50+
/// which are integers x and y such that a*bezoutCoefficientOfA + b*bezoutCoefficientOfB = Gcd(a, b).
5151
/// </summary>
5252
/// <param name="a">Input number.</param>
5353
/// <param name="b">Second input number.</param>
54-
/// <returns>A record of ExtendedEuclideanAlgorithmResult containing the bezout coefficients of a and b as well as the gcd(a,b).</returns>
54+
/// <returns>A record of ExtendedEuclideanAlgorithmResult containing the bezout coefficients of a and b as well as the Gcd(a,b).</returns>
5555
public static ExtendedEuclideanAlgorithmResult<BigInteger> Compute(BigInteger a, BigInteger b)
5656
{
5757
BigInteger quotient;
@@ -87,8 +87,8 @@ public static ExtendedEuclideanAlgorithmResult<BigInteger> Compute(BigInteger a,
8787
/// The result type for the computation of the Extended Euclidean Algorithm.
8888
/// </summary>
8989
/// <typeparam name="T">The data type of the computation (i.e. long or BigInteger).</typeparam>
90-
/// <param name="bezoutA">The bezout coefficient of the parameter a to the computation.</param>
91-
/// <param name="bezoutB">The bezout coefficient of the parameter b to the computation.</param>
92-
/// <param name="gcd">The greatest common divisor of the parameters a and b to the computation.</param>
93-
public record ExtendedEuclideanAlgorithmResult<T>(T bezoutA, T bezoutB, T gcd);
90+
/// <param name="BezoutA">The bezout coefficient of the parameter a to the computation.</param>
91+
/// <param name="BezoutB">The bezout coefficient of the parameter b to the computation.</param>
92+
/// <param name="Gcd">The greatest common divisor of the parameters a and b to the computation.</param>
93+
public record ExtendedEuclideanAlgorithmResult<T>(T BezoutA, T BezoutB, T Gcd);
9494
}

Algorithms/ModularArithmetic/ModularMultiplicativeInverse.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ public static long Compute(long a, long n)
2020
var eeaResult = ExtendedEuclideanAlgorithm.Compute(a, n);
2121

2222
// Check if there is an inverse:
23-
if (eeaResult.gcd != 1)
23+
if (eeaResult.Gcd != 1)
2424
{
2525
throw new ArithmeticException($"{a} is not invertible in Z/{n}Z.");
2626
}
2727

2828
// Make sure, inverseOfA (i.e. the bezout coefficient of a) is in the interval [0, n).
29-
var inverseOfA = eeaResult.bezoutA;
29+
var inverseOfA = eeaResult.BezoutA;
3030
if (inverseOfA < 0)
3131
{
3232
inverseOfA += n;
@@ -47,13 +47,13 @@ public static BigInteger Compute(BigInteger a, BigInteger n)
4747
var eeaResult = ExtendedEuclideanAlgorithm.Compute(a, n);
4848

4949
// Check if there is an inverse:
50-
if (eeaResult.gcd != 1)
50+
if (eeaResult.Gcd != 1)
5151
{
5252
throw new ArithmeticException($"{a} is not invertible in Z/{n}Z.");
5353
}
5454

5555
// Make sure, inverseOfA (i.e. the bezout coefficient of a) is in the interval [0, n).
56-
var inverseOfA = eeaResult.bezoutA;
56+
var inverseOfA = eeaResult.BezoutA;
5757
if (inverseOfA < 0)
5858
{
5959
inverseOfA += n;

0 commit comments

Comments
 (0)