Skip to content

Commit d1a4666

Browse files
committed
refactor: update array syntax to use modern bracket notation and improve comments
1 parent 4f54c64 commit d1a4666

File tree

4 files changed

+31
-34
lines changed

4 files changed

+31
-34
lines changed

src/ReedSolomon.NET.TablesGenerator/GeneratorHelpers.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ public static class Helpers
1212
/// </summary>
1313
private const int GeneratingPolynomial = 29;
1414

15-
private static readonly short[] _logTable = {
15+
private static readonly short[] _logTable =
16+
[
1617
-1, 0, 1, 25, 2, 50, 26, 198,
1718
3, 223, 51, 238, 27, 104, 199, 75,
1819
4, 100, 224, 14, 52, 141, 239, 129,
@@ -44,8 +45,8 @@ public static class Helpers
4445
203, 89, 95, 176, 156, 169, 160, 81,
4546
11, 245, 22, 235, 122, 117, 44, 215,
4647
79, 174, 213, 233, 230, 231, 173, 232,
47-
116, 214, 244, 234, 168, 80, 88, 175,
48-
};
48+
116, 214, 244, 234, 168, 80, 88, 175
49+
];
4950

5051

5152
/// <summary>

tests/ReedSolomon.NET.Tests/GaloisTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public void Closure_Should_Never_Be_Tested()
1212
// Unlike the Python implementation, there is no need to test
1313
// for closure. Because add(), subtract(), multiply(), and
1414
// divide() all return bytes, there's no way they could
15-
// possible return something outside the field.
15+
// possibly return something outside the field.
1616
}
1717

1818
[Fact]

tests/ReedSolomon.NET.Tests/MatrixTests.cs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,27 @@ public void ToOneLineString_Should_Return_The_Right_String() =>
1717
[Fact]
1818
public void Multiply_Two_Matrices_Should_Return_The_Right_Matrix()
1919
{
20-
var m1 = new Matrix(new[]
21-
{
22-
new byte []{ 1, 2 },
23-
new byte []{ 3, 4 }
24-
});
20+
var m1 = new Matrix([
21+
[1, 2],
22+
[3, 4]
23+
]);
2524

26-
var m2 = new Matrix(new[]
27-
{
28-
new byte []{ 5, 6 },
29-
new byte []{ 7, 8 }
30-
});
25+
var m2 = new Matrix([
26+
[5, 6],
27+
[7, 8]
28+
]);
3129
var result = m1.Multiply(m2);
3230
result.ToString().ShouldBe("[11, 22]\n[19, 42]\n");
3331
}
3432

3533
[Fact]
3634
public void Inverse_Matrix_Should_Return_The_Right_Matrix()
3735
{
38-
Matrix m = new (
39-
new[]
40-
{
41-
new byte [] { 56, 23, 98 },
42-
new byte [] { 3, 100, 200 },
43-
new byte [] { 45, 201, 123 }
44-
});
36+
Matrix m = new ([
37+
[56, 23, 98],
38+
[3, 100, 200],
39+
[45, 201, 123]
40+
]);
4541
m.Invert().ToString().ShouldBe("[175, 133, 33]\n[130, 13, 245]\n[112, 35, 126]\n");
4642
Matrix.Identity(3).ShouldBe(m.Multiply(m.Invert()));
4743
}

tests/ReedSolomon.NET.Tests/ReedSolomonTests.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ public void OneEncode_Parity_Should_Be_Correct()
1616
{
1717
var codec = new ReedSolomon(5, 5, codingLoop);
1818
var shards = new byte[10][];
19-
shards[0] = new byte[] {0, 1};
20-
shards[1] = new byte[] {4, 5};
21-
shards[2] = new byte[] {2, 3};
22-
shards[3] = new byte[] {6, 7};
23-
shards[4] = new byte[] {8, 9};
19+
shards[0] = [0, 1];
20+
shards[1] = [4, 5];
21+
shards[2] = [2, 3];
22+
shards[3] = [6, 7];
23+
shards[4] = [8, 9];
2424
shards[5] = new byte[2];
2525
shards[6] = new byte[2];
2626
shards[7] = new byte[2];
@@ -29,11 +29,11 @@ public void OneEncode_Parity_Should_Be_Correct()
2929

3030
codec.EncodeParity(shards, 0, 2);
3131

32-
shards[5].ShouldBe(new byte[] {12, 13});
33-
shards[6].ShouldBe(new byte[] {10, 11});
34-
shards[7].ShouldBe(new byte[] {14, 15});
35-
shards[8].ShouldBe(new byte[] {90, 91});
36-
shards[9].ShouldBe(new byte[] {94, 95});
32+
shards[5].ShouldBe([12, 13]);
33+
shards[6].ShouldBe([10, 11]);
34+
shards[7].ShouldBe([14, 15]);
35+
shards[8].ShouldBe([90, 91]);
36+
shards[9].ShouldBe([94, 95]);
3737

3838
codec.IsParityCorrect(shards, 0, 2).ShouldBeTrue();
3939
shards[8][0] += 1;
@@ -76,7 +76,7 @@ public void BigEncodeDecode()
7676
}
7777

7878
/**
79-
* Encodes a set of data shards, and then tries decoding
79+
* Encodes a set of data shards and then tries decoding
8080
* using all possible subsets of the encoded shards.
8181
*
8282
* Uses 5+5 coding, so there must be 5 input data shards.
@@ -258,13 +258,13 @@ private static List<int[]> AllSubsets(int n, int min, int max)
258258
var result = new List<int[]>();
259259
if (n == 0)
260260
{
261-
result.Add(Array.Empty<int>());
261+
result.Add([]);
262262
}
263263
else
264264
{
265265
for (var i = min; i < max - n; i++)
266266
{
267-
int[] prefix = {i};
267+
int[] prefix = [i];
268268
result.AddRange(AllSubsets(n - 1, i + 1, max)
269269
.Select(suffix => AppendIntArrays(prefix, suffix)));
270270
}

0 commit comments

Comments
 (0)