Skip to content

Commit

Permalink
Merge pull request #10 from Miiraak/NewHashMethods
Browse files Browse the repository at this point in the history
v1.0.4.5 : Refactor tests, implement CRC8, update lists and README.


    Implemented the CRC8 hash method and removed too old and unimplemented methods from HashMethods.cs.
    Adding PrimesN method in PresetLists.cs, return a List<int> of n first primal numbers.
    Adding FibonacciN method in PresetLists.cs, return a List<int> of n first fibonacci numbers.
    Adding MersonneN method in PresetLists.cs, return a List<int> of n first Mersonne numbers.
    Adding MersonnePrimalN list in PresetLists.cs, return a List<long> of the 9 first Mersenne primal number.
    Adding HexagonalNumberN method in PresetLists.cs, return a List<int> of n first hexagonal numbers.
    Adding html 'Colors' list.
    Adding Security 'CommonPasswords' list.
    Refactored test files for better organization.
    Added new test methods.
    Introduced 'HTML' and 'Security' classes in 'PresetLists.cs'.
    Updated ClassicalCompendium version and added acknowledgment in 'README.md'.
  • Loading branch information
Miiraak authored Sep 1, 2024
2 parents 7f46734 + 40ddb4a commit 47d21af
Show file tree
Hide file tree
Showing 8 changed files with 499 additions and 454 deletions.
8 changes: 8 additions & 0 deletions ClassicalCompendium.Tests/HashMethodsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
{
public class HashMethodsTests
{
[Fact]
public void CRC8Test()
{
Assert.Equal("0x00", HashMethods.CRC8(""));
Assert.Equal("0x2E", HashMethods.CRC8("Bonjour"));
Assert.Equal("0xC1", HashMethods.CRC8("The quick brown fox jumps over the lazy dog"));
}

[Fact]
public void SHA256Test()
{
Expand Down
152 changes: 115 additions & 37 deletions ClassicalCompendium.Tests/PreSetListsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,133 @@
{
public class PreSetListsTests
{
[Fact]
public void MonthsTests()
public class Time
{
Assert.Equal("January", PresetLists.Time.Months[0]);
Assert.Equal("February", PresetLists.Time.Months[1]);
Assert.Equal("March", PresetLists.Time.Months[2]);
Assert.Equal(12, PresetLists.Time.Months.Count);
}
[Fact]
public void MonthsTests()
{
Assert.Equal("January", PresetLists.Time.Months[0]);
Assert.Equal("February", PresetLists.Time.Months[1]);
Assert.Equal("March", PresetLists.Time.Months[2]);
Assert.Equal(12, PresetLists.Time.Months.Count);
}

[Fact]
public void DaysOfWeekTests()
{
Assert.Equal("Monday", PresetLists.Time.WeekDays[0]);
Assert.Equal("Tuesday", PresetLists.Time.WeekDays[1]);
Assert.Equal("Wednesday", PresetLists.Time.WeekDays[2]);
Assert.Equal(7, PresetLists.Time.WeekDays.Count);
}
[Fact]
public void DaysOfWeekTests()
{
Assert.Equal("Monday", PresetLists.Time.WeekDays[0]);
Assert.Equal("Tuesday", PresetLists.Time.WeekDays[1]);
Assert.Equal("Wednesday", PresetLists.Time.WeekDays[2]);
Assert.Equal(7, PresetLists.Time.WeekDays.Count);
}

[Fact]
public void HoursTests()
{
Assert.Equal("12 PM", PresetLists.Time.Hours[0]);
Assert.Equal("1 AM", PresetLists.Time.Hours[1]);
Assert.Equal("2 AM", PresetLists.Time.Hours[2]);
Assert.Equal(24, PresetLists.Time.Hours.Count);
[Fact]
public void HoursTests()
{
Assert.Equal("12 PM", PresetLists.Time.Hours[0]);
Assert.Equal("1 AM", PresetLists.Time.Hours[1]);
Assert.Equal("2 AM", PresetLists.Time.Hours[2]);
Assert.Equal(24, PresetLists.Time.Hours.Count);
}
}

[Fact]
public void CountryISOTests()
public class Countries
{
Assert.Equal("AF", PresetLists.Countries.CountryISO[0].Item2);
[Fact]
public void CountryISOTests()
{
Assert.Equal("AF", PresetLists.Countries.CountryISO[0].Item2);
}

[Fact]
public void MostUsedLangagesTests()
{
Assert.Equal("English", PresetLists.Countries.MostUsedLangages[0]);
Assert.Equal("French", PresetLists.Countries.MostUsedLangages[1]);
Assert.Equal("Arabic", PresetLists.Countries.MostUsedLangages[2]);
Assert.Equal(10, PresetLists.Countries.MostUsedLangages.Count);
}

[Fact]
public void OfficialLanguagesTests()
{
Assert.Equal("Abkhaz", PresetLists.Countries.OfficialLanguages[0]);
Assert.Equal("Armenian", PresetLists.Countries.OfficialLanguages[9]);
Assert.Equal("Bedik", PresetLists.Countries.OfficialLanguages[18]);
Assert.Equal(214, PresetLists.Countries.OfficialLanguages.Count);
}
}

[Fact]
public void MostUsedLangagesTests()
public class Chars
{
Assert.Equal("English", PresetLists.Countries.MostUsedLangages[0]);
Assert.Equal("French", PresetLists.Countries.MostUsedLangages[1]);
Assert.Equal("Arabic", PresetLists.Countries.MostUsedLangages[2]);
Assert.Equal(10, PresetLists.Countries.MostUsedLangages.Count);
[Fact]
public void ReverseAlphabetTests()
{
Assert.Equal("Z", PresetLists.Chars.ReverseAlphabet['A']);
Assert.Equal("Y", PresetLists.Chars.ReverseAlphabet['B']);
Assert.Equal("A", PresetLists.Chars.ReverseAlphabet['Z']);
}

[Fact]
public void OrderOfMagnitudeTests()
{
Assert.Equal(("kilo", 3), PresetLists.Chars.OrderOfMagnitude[14]);
Assert.Equal(("quetta", 30), PresetLists.Chars.OrderOfMagnitude[23]);
Assert.Equal(("quecto", -30), PresetLists.Chars.OrderOfMagnitude[0]);
}
}

[Fact]
public void OfficialLanguagesTests()
public class Numbers
{
Assert.Equal("Abkhaz", PresetLists.Countries.OfficialLanguages[0]);
Assert.Equal("Armenian", PresetLists.Countries.OfficialLanguages[9]);
Assert.Equal("Bedik", PresetLists.Countries.OfficialLanguages[18]);
Assert.Equal(214, PresetLists.Countries.OfficialLanguages.Count);
[Fact]
public void HexadecimalNumbersTests()
{
Assert.Equal("0", PresetLists.Numbers.HexadecimalNumbers[0]);
Assert.Equal("1", PresetLists.Numbers.HexadecimalNumbers[1]);
Assert.Equal("9", PresetLists.Numbers.HexadecimalNumbers[9]);
Assert.Equal("A", PresetLists.Numbers.HexadecimalNumbers[10]);
Assert.Equal("F", PresetLists.Numbers.HexadecimalNumbers[15]);
Assert.Equal("10", PresetLists.Numbers.HexadecimalNumbers[16]);
Assert.Equal("1F", PresetLists.Numbers.HexadecimalNumbers[31]);
Assert.Equal("FF", PresetLists.Numbers.HexadecimalNumbers[255]);

}

[Fact]
public void PrimeN()
{
Assert.Empty(PresetLists.Numbers.PrimesN(0));
Assert.Empty(PresetLists.Numbers.PrimesN(1));
Assert.Equal(100, PresetLists.Numbers.PrimesN(100).Count);
Assert.Equal(200, PresetLists.Numbers.PrimesN(200).Count);
Assert.True(PresetLists.Numbers.PrimesN(5).SequenceEqual(new List<int> { 2, 3, 5, 7, 11 }));
}

[Fact]
public void FibonacciN()
{
Assert.True(PresetLists.Numbers.FibonacciN(1).SequenceEqual(new List<int> { 0 }));
Assert.True(PresetLists.Numbers.FibonacciN(2).SequenceEqual(new List<int> { 0, 1 }));
Assert.True(PresetLists.Numbers.FibonacciN(3).SequenceEqual(new List<int> { 0, 1, 1 }));
Assert.True(PresetLists.Numbers.FibonacciN(4).SequenceEqual(new List<int> { 0, 1, 1, 2 }));
Assert.True(PresetLists.Numbers.FibonacciN(5).SequenceEqual(new List<int> { 0, 1, 1, 2, 3 }));
Assert.True(PresetLists.Numbers.FibonacciN(6).SequenceEqual(new List<int> { 0, 1, 1, 2, 3, 5 }));
Assert.True(PresetLists.Numbers.FibonacciN(7).SequenceEqual(new List<int> { 0, 1, 1, 2, 3, 5, 8 }));
Assert.Equal(50, PresetLists.Numbers.FibonacciN(50).Count);
}

[Fact]
public void MercenneTests()
{
Assert.True(PresetLists.Numbers.MersenneN(1).SequenceEqual(new List<int> { 0 }));
Assert.True(PresetLists.Numbers.MersenneN(2).SequenceEqual(new List<int> { 0, 1 }));
Assert.True(PresetLists.Numbers.MersenneN(3).SequenceEqual(new List<int> { 0, 1, 3 }));
Assert.True(PresetLists.Numbers.MersenneN(4).SequenceEqual(new List<int> { 0, 1, 3, 7 }));
Assert.True(PresetLists.Numbers.MersenneN(5).SequenceEqual(new List<int> { 0, 1, 3, 7, 15 }));
Assert.True(PresetLists.Numbers.MersenneN(6).SequenceEqual(new List<int> { 0, 1, 3, 7, 15, 31 }));
Assert.True(PresetLists.Numbers.MersenneN(7).SequenceEqual(new List<int> { 0, 1, 3, 7, 15, 31, 63 }));
Assert.Equal(50, PresetLists.Numbers.MersenneN(50).Count);
}
}
}
}
8 changes: 4 additions & 4 deletions ClassicalCompendium.Tests/RandomMethodsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ public void RandomIntegerTest()
int min = 0;
int max = 100;
int random = RandomMethods.RandomInteger(min, max);
Assert.True(random >= min && random < max);
Assert.True(random >= min && random <= max);
min = -100;
max = 0;
random = RandomMethods.RandomInteger(min, max);
Assert.True(random >= min && random < max);
Assert.True(random >= min && random <= max);
}

[Fact]
Expand All @@ -21,11 +21,11 @@ public void RandomDoubleTest()
double min = 0;
double max = 100;
double random = RandomMethods.RandomDouble(min, max);
Assert.True(random >= min && random < max);
Assert.True(random >= min && random <= max);
min = -100;
max = 0;
random = RandomMethods.RandomDouble(min, max);
Assert.True(random >= min && random < max);
Assert.True(random >= min && random <= max);
}

[Fact]
Expand Down
6 changes: 3 additions & 3 deletions ClassicalCompendium/ClassicalCompendium.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<SignAssembly>False</SignAssembly>
<Version>1.0.4</Version>
<Version>1.0.4.5</Version>
<Company></Company>
<Description>A collection of widely-used C# utility methods </Description>
<EnablePackageValidation>true</EnablePackageValidation>
Expand All @@ -16,8 +16,8 @@
<Authors>Miiraak</Authors>
<PackageId>ClassicalCompendium</PackageId>
<PackageProjectUrl>https://www.nuget.org/packages/ClassicalCompendium</PackageProjectUrl>
<AssemblyVersion>1.0.4</AssemblyVersion>
<FileVersion>1.0.4</FileVersion>
<AssemblyVersion>1.0.4.5</AssemblyVersion>
<FileVersion>1.0.4.5</FileVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
Loading

0 comments on commit 47d21af

Please sign in to comment.