Skip to content

Commit

Permalink
Merge pull request #7 from Miiraak/new_lists
Browse files Browse the repository at this point in the history
Add unit tests, refactor namespaces, and update methods
  • Loading branch information
Miiraak authored Aug 31, 2024
2 parents 43223ec + 403c0c9 commit f767616
Show file tree
Hide file tree
Showing 9 changed files with 631 additions and 366 deletions.
101 changes: 101 additions & 0 deletions ClassicalCompendium.Tests/CalculsMethodsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
namespace ClassicalCompendium.Tests
{
public class CalculsMethodsTests
{
[Fact]
public void IsOddTest()
{
Assert.False(CalculsMethods.IsOdd(0));
Assert.True(CalculsMethods.IsOdd(1));
Assert.False(CalculsMethods.IsOdd(2));
Assert.True(CalculsMethods.IsOdd(3));
Assert.False(CalculsMethods.IsOdd(4));
Assert.True(CalculsMethods.IsOdd(5));
Assert.False(CalculsMethods.IsOdd(6));
Assert.True(CalculsMethods.IsOdd(7));
Assert.False(CalculsMethods.IsOdd(8));
Assert.True(CalculsMethods.IsOdd(9));
Assert.False(CalculsMethods.IsOdd(10));
}

[Fact]
public void IsEvenTest()
{
Assert.True(CalculsMethods.IsEven(0));
Assert.False(CalculsMethods.IsEven(1));
Assert.True(CalculsMethods.IsEven(2));
Assert.False(CalculsMethods.IsEven(3));
Assert.True(CalculsMethods.IsEven(4));
Assert.False(CalculsMethods.IsEven(5));
Assert.True(CalculsMethods.IsEven(6));
Assert.False(CalculsMethods.IsEven(7));
Assert.True(CalculsMethods.IsEven(8));
Assert.False(CalculsMethods.IsEven(9));
Assert.True(CalculsMethods.IsEven(10));
}

[Fact]
public void SumToNTest()
{
Assert.Equal(0, CalculsMethods.SumToN(0));
Assert.Equal(1, CalculsMethods.SumToN(1));
Assert.Equal(3, CalculsMethods.SumToN(2));
Assert.Equal(6, CalculsMethods.SumToN(3));
Assert.Equal(10, CalculsMethods.SumToN(4));
Assert.Equal(15, CalculsMethods.SumToN(5));
Assert.Equal(21, CalculsMethods.SumToN(6));
Assert.Equal(28, CalculsMethods.SumToN(7));
Assert.Equal(36, CalculsMethods.SumToN(8));
Assert.Equal(45, CalculsMethods.SumToN(9));
Assert.Equal(55, CalculsMethods.SumToN(10));
}

[Fact]
public void SubtractToNTest()
{
Assert.Equal(0, CalculsMethods.SubtractToN(0));
Assert.Equal(-1, CalculsMethods.SubtractToN(1));
Assert.Equal(-3, CalculsMethods.SubtractToN(2));
Assert.Equal(-6, CalculsMethods.SubtractToN(3));
Assert.Equal(-10, CalculsMethods.SubtractToN(4));
Assert.Equal(-15, CalculsMethods.SubtractToN(5));
Assert.Equal(-21, CalculsMethods.SubtractToN(6));
Assert.Equal(-28, CalculsMethods.SubtractToN(7));
Assert.Equal(-36, CalculsMethods.SubtractToN(8));
Assert.Equal(-45, CalculsMethods.SubtractToN(9));
Assert.Equal(-55, CalculsMethods.SubtractToN(10));
}

[Fact]
public void FactorialNTest()
{
Assert.Equal(0, CalculsMethods.FactorialN(0));
Assert.Equal(1, CalculsMethods.FactorialN(1));
Assert.Equal(2, CalculsMethods.FactorialN(2));
Assert.Equal(6, CalculsMethods.FactorialN(3));
Assert.Equal(24, CalculsMethods.FactorialN(4));
Assert.Equal(120, CalculsMethods.FactorialN(5));
Assert.Equal(720, CalculsMethods.FactorialN(6));
Assert.Equal(5040, CalculsMethods.FactorialN(7));
Assert.Equal(40320, CalculsMethods.FactorialN(8));
Assert.Equal(362880, CalculsMethods.FactorialN(9));
Assert.Equal(3628800, CalculsMethods.FactorialN(10));
}

[Fact]
public void NegFactorialNTest()
{
Assert.Equal(0, CalculsMethods.NegFactorialN(0));
Assert.Equal(-1, CalculsMethods.NegFactorialN(1));
Assert.Equal(2, CalculsMethods.NegFactorialN(2));
Assert.Equal(-6, CalculsMethods.NegFactorialN(3));
Assert.Equal(24, CalculsMethods.NegFactorialN(4));
Assert.Equal(-120, CalculsMethods.NegFactorialN(5));
Assert.Equal(720, CalculsMethods.NegFactorialN(6));
Assert.Equal(-5040, CalculsMethods.NegFactorialN(7));
Assert.Equal(40320, CalculsMethods.NegFactorialN(8));
Assert.Equal(-362880, CalculsMethods.NegFactorialN(9));
Assert.Equal(3628800, CalculsMethods.NegFactorialN(10));
}
}
}
325 changes: 325 additions & 0 deletions ClassicalCompendium.Tests/ConversionSystemTests.cs

Large diffs are not rendered by default.

325 changes: 0 additions & 325 deletions ClassicalCompendium.Tests/NumeralSystemTests.cs

This file was deleted.

42 changes: 21 additions & 21 deletions ClassicalCompendium.Tests/PreSetListsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,52 @@ public class PreSetListsTests
[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);
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);
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);
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()
{
Assert.Equal("AF", PreSetLists.Country.CountryISO[0].Item2);
Assert.Equal("AF", PresetLists.Countries.CountryISO[0].Item2);
}

[Fact]
public void MostUsedLangagesTests()
{
Assert.Equal("English", PreSetLists.Country.MostUsedLangages[0]);
Assert.Equal("French", PreSetLists.Country.MostUsedLangages[1]);
Assert.Equal("Arabic", PreSetLists.Country.MostUsedLangages[2]);
Assert.Equal(10, PreSetLists.Country.MostUsedLangages.Count);
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.Country.OfficialLanguages[0]);
Assert.Equal("Armenian", PreSetLists.Country.OfficialLanguages[9]);
Assert.Equal("Bedik", PreSetLists.Country.OfficialLanguages[18]);
Assert.Equal(214, PreSetLists.Country.OfficialLanguages.Count);
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);
}
}
}
75 changes: 75 additions & 0 deletions ClassicalCompendium/CalculsMethods.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
namespace ClassicalCompendium
{
public class CalculsMethods
{
public static bool IsOdd(int number)
{
return number % 2 != 0;
}

public static bool IsEven(int number)
{
return number % 2 == 0;
}

public static int SumToN(int N)
{
int S = ((N * (N + 1)) / 2);
return S;
}

public static int SubtractToN(int N)
{
int S = ((N * (N + 1)) / 2);
return -S;
}

public static int FactorialN(int N)
{
if (N <= 0)
{
return 0;
}
else
{
int S = 1;
int i = 1;

while (i <= N)
{
S *= i;
i++;
}
return S;
}
}

public static int NegFactorialN(int N)
{
if (N <= 0)
{
return 0;
}
else
{
int S = 1;
int i = 1;

while (i <= N)
{
S *= i;
i++;
}

if (IsEven(N))
{
return S;
}
else
{
return -S;
}
}
}
}
}
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.3</Version>
<Version>1.0.4</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.3</AssemblyVersion>
<FileVersion>1.0.3</FileVersion>
<AssemblyVersion>1.0.4</AssemblyVersion>
<FileVersion>1.0.4</FileVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace ClassicalCompendium
{
public class NumeralSystemMethods
public class ConversionMethods
{
/// <summary>
/// This method will convert a decimal number to a binary number.
Expand Down
16 changes: 2 additions & 14 deletions ClassicalCompendium/CryptoMethods.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
using System;
using System.Collections.Generic;

namespace ClassicalCompendium
{
public class CryptoMethods
{
static readonly Dictionary<char, string> ReverseAlphabet = new Dictionary<char, string>{
{ 'A', "Z" }, { 'B', "Y" }, { 'C', "X" },
{ 'D', "W" }, { 'E', "V "}, { 'F', "U" },
{ 'G', "T" }, { 'H', "S" }, { 'I', "R" },
{ 'J', "Q" }, { 'K', "P" }, { 'L', "O" },
{ 'M', "N" }, { 'N', "M" }, { 'O', "L" },
{ 'P', "K" }, { 'Q', "J" }, { 'R', "I" },
{ 'S', "H" }, { 'T', "G" }, { 'U', "F" },
{ 'V', "E" }, { 'W', "D" }, { 'X', "C" },
{ 'Y', "B" }, { 'Z', "A" } };

/// <summary>
/// This method will return the converted string with the Cesar code.
/// </summary>
Expand Down Expand Up @@ -49,9 +37,9 @@ public static string EncodeWithAtBash(string Text)

foreach (char letter in Text.ToUpper())
{
if (ReverseAlphabet.ContainsKey(letter))
if (PresetLists.Chars.ReverseAlphabet.ContainsKey(letter))
{
output += ReverseAlphabet[letter];
output += PresetLists.Chars.ReverseAlphabet[letter];
}
else
{
Expand Down
Loading

0 comments on commit f767616

Please sign in to comment.