Skip to content

Commit 1e861b0

Browse files
authored
Cleanup minor things (TheAlgorithms#221)
* Add DIRECTORY.md to solution * Add missing algorithms to README.md * Apply code style * Update .editorconfig
1 parent 6f4407e commit 1e861b0

File tree

198 files changed

+3547
-12948
lines changed

Some content is hidden

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

198 files changed

+3547
-12948
lines changed

.editorconfig

+110-189
Large diffs are not rendered by default.

Algorithms.Tests/Compressors/HuffmanCompressorTests.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
using Algorithms.DataCompression;
22
using Algorithms.Sorters.Comparison;
3-
43
using FluentAssertions;
5-
64
using NUnit.Framework;
75
using NUnit.Framework.Internal;
86

@@ -33,7 +31,9 @@ public static void CompressingPhrase(string uncompressedText, string expectedCom
3331
}
3432

3533
[Test]
36-
public static void DecompressedTextTheSameAsOriginal([Random(0, 1000, 100, Distinct = true)]int length)
34+
public static void DecompressedTextTheSameAsOriginal(
35+
[Random(0, 1000, 100, Distinct = true)]
36+
int length)
3737
{
3838
//Arrange
3939
var sorter = new BubbleSorter<HuffmanCompressor.ListNode>();

Algorithms.Tests/Compressors/ShannonFanoCompressorTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static void CompressingPhrase(string uncompressedText, string expectedCom
2828
}
2929

3030
[Test]
31-
public static void DecompressedTextTheSameAsOriginal([Random(0, 1000, 100)]int length)
31+
public static void DecompressedTextTheSameAsOriginal([Random(0, 1000, 100)] int length)
3232
{
3333
//Arrange
3434
var solver = new NaiveKnapsackSolver<(char, double)>();

Algorithms.Tests/Encoders/CaesarEncoderTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Algorithms.Tests.Encoders
77
public static class CaesarEncoderTests
88
{
99
[Test]
10-
public static void DecodedStringIsTheSame([Random(100)]int key)
10+
public static void DecodedStringIsTheSame([Random(100)] int key)
1111
{
1212
// Arrange
1313
var encoder = new CaesarEncoder();
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,32 @@
11
using System.Collections.Generic;
2+
using System.Linq;
23
using Algorithms.Encoders;
34
using NUnit.Framework;
4-
using System.Linq;
55

66
namespace Algorithms.Tests.Encoders
77
{
88
public class NysiisEncoderTests
99
{
10+
private static readonly string[] _names =
11+
{
12+
"Jay", "John", "Jane", "Zayne", "Guerra", "Iga", "Cowan", "Louisa", "Arnie", "Olsen", "Corban", "Nava",
13+
"Cynthia Malone", "Amiee MacKee", "MacGyver", "Yasmin Edge",
14+
};
15+
16+
private static readonly string[] _expected =
17+
{
18+
"JY", "JAN", "JAN", "ZAYN", "GAR", "IG", "CAN", "LAS", "ARNY", "OLSAN", "CARBAN", "NAV", "CYNTANALAN",
19+
"ANANACY", "MCGYVAR", "YASNANADG",
20+
};
21+
22+
private static IEnumerable<string[]> TestData => _names.Zip(_expected, (l, r) => new[] { l, r });
23+
1024
[TestCaseSource(nameof(TestData))]
1125
public void AttemptNysiis(string source, string expected)
1226
{
1327
var enc = new NysiisEncoder();
1428
var nysiis = enc.Encode(source);
1529
Assert.AreEqual(expected, nysiis);
1630
}
17-
18-
static IEnumerable<string[]> TestData => _names.Zip(_expected, (l, r) => new[] { l, r });
19-
20-
static string[] _names = {
21-
"Jay", "John", "Jane", "Zayne", "Guerra",
22-
"Iga", "Cowan", "Louisa", "Arnie", "Olsen",
23-
"Corban", "Nava", "Cynthia Malone", "Amiee MacKee",
24-
"MacGyver", "Yasmin Edge"
25-
};
26-
static string[] _expected = {
27-
"JY", "JAN", "JAN", "ZAYN", "GAR",
28-
"IG", "CAN", "LAS", "ARNY", "OLSAN",
29-
"CARBAN", "NAV", "CYNTANALAN", "ANANACY",
30-
"MCGYVAR", "YASNANADG"
31-
};
3231
}
3332
}

Algorithms.Tests/Encoders/SoundexEncoderTest.cs

+9-11
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,21 @@ namespace Algorithms.Tests.Encoders
77
{
88
public static class SoundexEncoderTest
99
{
10+
private static readonly string[] _names =
11+
{
12+
"Robert", "Rupert", "Rubin", "Ashcraft", "Ashcroft", "Tymczak", "Pfister", "Honeyman",
13+
};
14+
15+
private static readonly string[] _expected = { "R163", "R163", "R150", "A261", "A261", "T522", "P236", "H555" };
16+
17+
private static IEnumerable<string[]> TestData => _names.Zip(_expected, (l, r) => new[] { l, r });
18+
1019
[TestCaseSource(nameof(TestData))]
1120
public static void AttemptSoundex(string source, string encoded)
1221
{
1322
SoundexEncoder enc = new();
1423
var nysiis = enc.Encode(source);
1524
Assert.AreEqual(nysiis, encoded);
1625
}
17-
18-
static IEnumerable<string[]> TestData => _names.Zip(_expected, (l, r) => new[] { l, r });
19-
20-
static readonly string[] _names = {
21-
"Robert", "Rupert", "Rubin", "Ashcraft", "Ashcroft",
22-
"Tymczak", "Pfister", "Honeyman"
23-
};
24-
static readonly string[] _expected = {
25-
"R163", "R163", "R150", "A261", "A261", "T522", "P236",
26-
"H555"
27-
};
2826
}
2927
}

Algorithms.Tests/Helpers/RandomHelper.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ public static (int[] correctArray, int[] testArray) GetArrays(int n)
1919
return (correctArray, testArr);
2020
}
2121

22-
public static (string[] correctArray, string[] testArray) GetStringArrays(int n, int maxLength, bool equalLength)
22+
public static (string[] correctArray, string[] testArray) GetStringArrays(
23+
int n,
24+
int maxLength,
25+
bool equalLength)
2326
{
2427
var testArr = new string[n];
2528
var correctArray = new string[n];

Algorithms.Tests/Knapsack/DynamicProgrammingKnapsackSolverTests.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ public static void FSU_P07_WithNonIntegralValues()
8585

8686

8787
[Test]
88-
public static void TakesHalf([Random(0, 1000, 100, Distinct = true)]int length)
88+
public static void TakesHalf(
89+
[Random(0, 1000, 100, Distinct = true)]
90+
int length)
8991
{
9092
//Arrange
9193
var solver = new DynamicProgrammingKnapsackSolver<int>();

Algorithms.Tests/Knapsack/NaiveKnapsackSolverTests.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ namespace Algorithms.Tests.Knapsack
77
public static class NaiveKnapsackSolverTests
88
{
99
[Test]
10-
public static void TakesHalf([Random(0, 1000, 100, Distinct = true)]int length)
10+
public static void TakesHalf(
11+
[Random(0, 1000, 100, Distinct = true)]
12+
int length)
1113
{
1214
//Arrange
1315
var solver = new NaiveKnapsackSolver<int>();
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,74 @@
11
using System;
22
using Algorithms.LinearAlgebra.Eigenvalue;
33
using FluentAssertions;
4-
using Utilities.Extensions;
54
using NUnit.Framework;
5+
using Utilities.Extensions;
66

77
namespace Algorithms.Tests.LinearAlgebra.Eigenvalue
88
{
99
public class PowerIterationTests
1010
{
11+
private static readonly object[] DominantVectorTestCases =
12+
{
13+
new object[]
14+
{
15+
3.0,
16+
new[] { 0.7071039, 0.70710966 },
17+
new[,] { { 2.0, 1.0 }, { 1.0, 2.0 } },
18+
},
19+
new object[]
20+
{
21+
4.235889,
22+
new[] { 0.91287093, 0.40824829 },
23+
new[,] { { 2.0, 5.0 }, { 1.0, 2.0 } },
24+
},
25+
};
26+
1127
private readonly double epsilon = Math.Pow(10, -5);
1228

1329
[Test]
1430
public void Dominant_ShouldThrowArgumentException_WhenSourceMatrixIsNotSquareShaped()
1531
{
1632
// Arrange
17-
var source = new double[,] {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}, {0, 0, 0}};
18-
33+
var source = new double[,] { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 }, { 0, 0, 0 } };
34+
1935
// Act
2036
Action action = () => PowerIteration.Dominant(source, StartVector(source.GetLength(0)), epsilon);
21-
37+
2238
// Assert
2339
action.Should().Throw<ArgumentException>().WithMessage("The source matrix is not square-shaped.");
2440
}
25-
41+
2642
[Test]
2743
public void Dominant_ShouldThrowArgumentException_WhenStartVectorIsNotSameSizeAsMatrix()
2844
{
2945
// Arrange
30-
var source = new double[,] {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
31-
var startVector = new double[] {1, 0, 0, 0};
32-
46+
var source = new double[,] { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } };
47+
var startVector = new double[] { 1, 0, 0, 0 };
48+
3349
// Act
3450
Action action = () => PowerIteration.Dominant(source, startVector, epsilon);
35-
51+
3652
// Assert
3753
action.Should().Throw<ArgumentException>()
3854
.WithMessage("The length of the start vector doesn't equal the size of the source matrix.");
3955
}
4056

41-
[Test, TestCaseSource(nameof(DominantVectorTestCases))]
57+
[TestCaseSource(nameof(DominantVectorTestCases))]
4258
public void Dominant_ShouldCalculateDominantEigenvalueAndEigenvector(
43-
double eigenvalue, double[] eigenvector, double[,] source)
59+
double eigenvalue,
60+
double[] eigenvector,
61+
double[,] source)
4462
{
4563
// Act
46-
var (actualEigVal, actualEigVec) = PowerIteration.Dominant(source, StartVector(source.GetLength(0)), epsilon);
47-
64+
var (actualEigVal, actualEigVec) =
65+
PowerIteration.Dominant(source, StartVector(source.GetLength(0)), epsilon);
66+
4867
// Assert
4968
actualEigVal.Should().BeApproximately(eigenvalue, epsilon);
5069
actualEigVec.Magnitude().Should().BeApproximately(eigenvector.Magnitude(), epsilon);
5170
}
5271

53-
static readonly object[] DominantVectorTestCases =
54-
{
55-
new object[]
56-
{
57-
3.0,
58-
new[] { 0.7071039, 0.70710966 },
59-
new[,] { { 2.0, 1.0 }, { 1.0, 2.0 } }
60-
},
61-
new object[]
62-
{
63-
4.235889,
64-
new[] { 0.91287093, 0.40824829 },
65-
new[,] { { 2.0, 5.0 }, { 1.0, 2.0 } }
66-
}
67-
};
68-
69-
private double[] StartVector(int length) => new Random(Seed: 111111).NextVector(length);
72+
private double[] StartVector(int length) => new Random(111111).NextVector(length);
7073
}
71-
}
74+
}

0 commit comments

Comments
 (0)