Adding Method Displayer, and renaming projects

This commit is contained in:
2025-08-06 14:25:08 +02:00
parent bb32e873c1
commit 866628af59
16 changed files with 71 additions and 39 deletions

View File

@@ -0,0 +1,64 @@
using MethodLibrary;
namespace BasicProgrammingTests;
public class BasicTests
{
private readonly Basic basic = new Basic();
[Theory]
[InlineData(30, 2, 4, 5)]
public void AddAndMultiply(int expected, int a, int b, int c)
{
Assert.Equal(expected, basic.AddAndMultiply(a, b, c));
}
[Theory]
[InlineData("T = 32F", 0)]
[InlineData("T = 212F", 100)]
[InlineData("Temperature below absolute zero!", -300)]
public void CToF(string expected, int input)
{
Assert.Equal(expected, basic.CtoF(input));
}
[Theory]
[InlineData(new double[] { 11.0, -5.0, 24.0, 0.375 }, 3, 8)]
public void ElementaryOperations(double[] expected, int a, int b)
{
var result = basic.ElementaryOperations(a, b);
Assert.Equal(expected, result);
}
[Theory]
[InlineData(true, 2 + 2, 2 * 2)]
[InlineData(false, 9 / 3, 16 - 1)]
public void IsResultTheSame(bool expected, int a, int b)
{
Assert.Equal(expected, basic.IsResultTheSame(a, b));
}
[Theory]
[InlineData(1, 8, 5, 2)]
public void ModuloOperations(int expected, int a, int b, int c)
{
Assert.Equal(expected, basic.ModuloOperations(a, b, c));
}
[Theory]
[InlineData(8, 2)]
[InlineData(-166.375, -5.5)]
public void CubeOf(double expected, double a)
{
Assert.Equal(expected, basic.CubeOf(a));
}
[Theory]
[InlineData(new int[] { 45, 87 }, 87, 45)]
[InlineData(new int[] {2, -13}, -13, 2)]
public void SwapTwoNumbers(int[] expected, int a, int b)
{
Assert.Equal(expected, basic.SwapTwoNumbers(a, b));
}
}

View File

@@ -0,0 +1,109 @@
using MethodLibrary;
namespace BasicProgrammingTests;
public class LoopsTests
{
Loops loops = new Loops();
[Fact]
public void MultiplicationTable()
{
var expected = new List<List<int>>
{
new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
new List<int> { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 },
new List<int> { 3, 6, 9, 12, 15, 18, 21, 24, 27, 30 },
new List<int> { 4, 8, 12, 16, 20, 24, 28, 32, 36, 40 },
new List<int> { 5, 10, 15, 20, 25, 30, 35, 40, 45, 50 },
new List<int> { 6, 12, 18, 24, 30, 36, 42, 48, 54, 60 },
new List<int> { 7, 14, 21, 28, 35, 42, 49, 56, 63, 70 },
new List<int> { 8, 16, 24, 32, 40, 48, 56, 64, 72, 80 },
new List<int> { 9, 18, 27, 36, 45, 54, 63, 72, 81, 90 },
new List<int> { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 }
};
Assert.Equal(expected, loops.MultiplicationTable(10, 10));
}
[Theory]
[InlineData(291, new int[] { 190, 291, 145, 209, 280, 200 })]
[InlineData(-2, new int[] { -9, -2, -7, -8, -4 })]
public void TheBiggestNumber(int expected, int[] a)
{
Assert.Equal(expected, loops.TheBiggestNumber(a.ToList()));
}
[Theory]
[InlineData(1, new int[] { 8, 2, 5, 7, 9, 0, 7, 7, 3, 1 })]
[InlineData(3, new int[] { 9, 4, 5, 3, 7, 7, 7, 3, 2, 5, 7, 7 })]
public void Two7sNextToEachOther(int expected, int[] a)
{
Assert.Equal(expected, loops.Two7sNextToEachOther(a.ToList()));
}
[Theory]
[InlineData(true, new int[] { 45, 23, 44, 68, 65, 70, 80, 81, 82 })]
[InlineData(false, new int[] { 7, 3, 5, 8, 9, 3, 1, 4 })]
public void ThreeIncreasingAdjacent(bool expected, int[] a)
{
Assert.Equal(expected, loops.ThreeIncreasingAdjacent(a.ToList()));
}
[Theory]
[InlineData(new int[] {2, 3, 5, 7, 11, 13, 17, 19, 23, 29}, 30)]
public void SieveOfEratosthenes(int[] expected, int a)
{
Assert.Equal(expected.ToList(), loops.SieveOfEratosthenes(a));
}
[Theory]
[InlineData("abc", "##abc##def")]
[InlineData("", "12####78")]
[InlineData("", "gar##d#en")]
[InlineData("--", "++##--##++")]
public void ExtractString(string expected, string a)
{
Assert.Equal(expected, loops.ExtractString(a));
}
[Theory]
[InlineData("defghijklmnopqrs", "ds")]
[InlineData("opqr", "or")]
public void FullSequenceOfLetters(string expected, string a)
{
Assert.Equal(expected, loops.FullSequenceOfLetters(a));
}
[Theory]
[InlineData("Sum: 2156, Average: 38,5", 11, 66)]
[InlineData("Sum: -55, Average: -5", -10, 0)]
public void SumAndAverage(string expected, int a, int b)
{
Assert.Equal(expected, loops.SumAndAverage(a, b));
}
[Fact]
public void DrawTriangle()
{
Assert.Equal(
@" *
***
*****
*******
*********
***********
*************
***************
*****************
*******************", loops.DrawTriangle(10));
}
[Theory]
[InlineData(-8, -2, 3)]
[InlineData(3125, 5, 5)]
public void ToThePowerOf(int expected, int a, int b)
{
Assert.Equal(expected, loops.ToThePowerOf(a, b));
}
}

View File

@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../MethodLibrary/MethodLibrary.csproj" />
</ItemGroup>
<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,75 @@
using MethodLibrary;
namespace BasicProgrammingTests;
public class StatementTests
{
Statement statement = new Statement();
[Theory]
[InlineData(6832, 6832)]
[InlineData(392, -392)]
public void AbsoluteValue(int expected, int a)
{
Assert.Equal(expected, statement.AbsoluteValue(a));
}
[Theory]
[InlineData(450, 15, 30)]
[InlineData(180, 2, 90)]
[InlineData(19, 7, 12)]
public void DivisibleBy2Or3(int expected, int a, int b)
{
Assert.Equal(expected, statement.DivisibleBy2Or3(a, b));
}
[Theory]
[InlineData(false, "xyz")]
[InlineData(true, "DOG")]
[InlineData(false, "L9#")]
public void IfConsistsOfUppercaseLetters(bool expected, string a)
{
Assert.Equal(expected, statement.IfConsistsOfUppercaseLetters(a));
}
[Theory]
[InlineData(true, new int[] { 2, 7, 12 })]
[InlineData(false, new int[] {-5, -8, 50})]
public void IfGreaterThanThirdOne(bool expected, int[] a)
{
Assert.Equal(expected, statement.IfGreaterThanThirdOne(a.ToList()));
}
[Theory]
[InlineData(false, 721)]
[InlineData(true, 1248)]
public void IfNumberIsEven(bool expected, int a)
{
Assert.Equal(expected, statement.IfNumberIsEven(a));
}
[Theory]
[InlineData(true, new int[] { 3, 7, 10 })]
[InlineData(false, new int[] {74, 62, 99})]
public void IfSortedAscending(bool expected, int[] a)
{
Assert.Equal(expected, statement.IfSortedAscending(a.ToList()));
}
[Theory]
[InlineData("positive", 5.24)]
[InlineData("zero", 0)]
[InlineData("negative", -994.53)]
public void PositiveNegativeOrZero(string expected, double a)
{
Assert.Equal(expected, statement.PositiveNegativeOrZero(a));
}
[Theory]
[InlineData(true, 2016)]
[InlineData(false, 2018)]
public void IfYearIsLeap(bool expected, int a)
{
Assert.Equal(expected, statement.IfYearIsLeap(a));
}
}

View File

@@ -0,0 +1,80 @@
using MethodLibrary;
namespace BasicProgrammingTests;
public class StringsTests
{
Strings strings = new Strings();
[Theory]
[InlineData("A^B^C^D", "ABCD", "^")]
[InlineData("c-h-o-c-o-l-a-t-e", "chocolate", "-")]
public void AddSeperator(string expected, string a, string b)
{
Assert.Equal(expected, strings.AddSeparator(a, b));
}
[Theory]
[InlineData(true, "eye")]
[InlineData(false, "home")]
public void IsPalindrome(bool expected, string a)
{
Assert.Equal(expected, strings.IsPalindrome(a));
}
[Theory]
[InlineData(8, "computer")]
[InlineData(9, "ice cream")]
public void LengthOfAString(int expected, string a)
{
Assert.Equal(expected, strings.LengthOfAString(a));
}
[Theory]
[InlineData("ytrewq", "qwerty")]
[InlineData("rk 39eo", "oe93 kr")]
public void StringInReverseOrder(string expected, string a)
{
Assert.Equal(expected, strings.StringInReverseOrder(a));
}
[Theory]
[InlineData(4, "This is sample sentence")]
[InlineData(1, "OK")]
public void NumberOfWords(int expected, string a)
{
Assert.Equal(expected, strings.NumberOfWords(a));
}
[Theory]
[InlineData("Doe. John", "John Doe.")]
[InlineData("A, B. C", "C B. A,")]
public void RevertWordsOrder(string expected, string a)
{
Assert.Equal(expected, strings.RevertWordsOrder(a));
}
[Theory]
[InlineData(1, "do it now", "do")]
[InlineData(0, "empty", "d")]
public void HowManyOccurrences(int expected, string a, string b)
{
Assert.Equal(expected, strings.HowManyOccurrences(a, b));
}
[Theory]
[InlineData(new char[] { 't', 'p', 'o', 'o', 'o', 'o', 'n', 'm', 'i', 'e', 'a', 'a' }, "onomatopoeia")]
[InlineData(new char[] { 'w', 's', 'o', 'o', 'j', 'h', 'f', 'f', '4', '2' }, "fohjwf42os")]
public void SortCharactersDescending(char[] expected, string a)
{
Assert.Equal(expected.ToList(), strings.SortCharactersDescending(a));
}
[Theory]
[InlineData("k4t3r10", "kkkktttrrrrrrrrrr")]
[InlineData("p153p371w3","p555ppp7www")]
public void CompressString(string expected, string a)
{
Assert.Equal(expected, strings.CompressString(a));
}
}