Changing from Fact to Theory, and moving methods into classes

This commit is contained in:
2025-08-06 12:54:44 +02:00
parent a70ea5d707
commit 39ecc637e8
15 changed files with 802 additions and 734 deletions

View File

@@ -1,53 +0,0 @@
using static BasicProgramming.Program;
namespace BasicProgrammingUnitTest;
public class BasicProgramming__BASIC
{
[Fact]
public void AddAndMultiply_TEST()
{
Assert.Equal(30, AddAndMultiply(2, 4, 5));
}
[Fact]
public void CToF_TEST()
{
Assert.Equal("T = 32F", CtoF(0));
Assert.Equal("T = 212F", CtoF(100));
Assert.Equal("Temperature below absolute zero!", CtoF(-300));
}
[Fact]
public void ElementaryOperations_TEST()
{
Assert.Equal([11, -5, 24, 0.375], ElementaryOperations(3, 8));
}
[Fact]
public void IsResultTheSame_TEST()
{
Assert.True(IsResultTheSame(2 + 2, 2 * 2));
Assert.False(IsResultTheSame(9 / 3, 16 - 1));
}
[Fact]
public void ModuloOperations_TEST()
{
Assert.Equal(1, ModuloOperations(8, 5, 2));
}
[Fact]
public void CubeOf_TEST()
{
Assert.Equal(8, CubeOf(2));
Assert.Equal(-166.375, CubeOf(-5.5));
}
[Fact]
public void SwapTwoNumbers_TEST()
{
Assert.Equal([45, 87], SwapTwoNumbers(87, 45));
Assert.Equal([2, -13], SwapTwoNumbers(-13, 2));
}
}

View File

@@ -1,99 +0,0 @@
using static BasicProgramming.Program;
namespace BasicProgrammingUnitTest;
public class BasicProgramming__LOOPS
{
[Fact]
public void MultiplicationTable_TEST()
{
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, MultiplicationTable(10, 10));
}
[Fact]
public void TheBiggestNumber_TEST()
{
Assert.Equal(291, TheBiggestNumber([190, 291, 145, 209, 280, 200]));
Assert.Equal(-2, TheBiggestNumber([-9, -2, -7, -8, -4]));
}
[Fact]
public void Two7sNextToEachOther_TEST()
{
Assert.Equal(1, Two7sNextToEachOther([8, 2, 5, 7, 9, 0, 7, 7, 3, 1]));
Assert.Equal(3, Two7sNextToEachOther([9, 4, 5, 3, 7, 7, 7, 3, 2, 5, 7, 7]));
}
[Fact]
public void ThreeIncreasingAdjacent_TEST()
{
Assert.True(ThreeIncreasingAdjacent([45, 23, 44, 68, 65, 70, 80, 81, 82]));
Assert.False(ThreeIncreasingAdjacent([7, 3, 5, 8, 9, 3, 1, 4]));
}
[Fact]
public void SieveOfEratosthenes_TEST()
{
Assert.Equal([2, 3, 5, 7, 11, 13, 17, 19, 23, 29], SieveOfEratosthenes(30));
}
[Fact]
public void ExtractString_TEST()
{
Assert.Equal("abc", ExtractString("##abc##def"));
Assert.Equal(string.Empty, ExtractString("12####78"));
Assert.Equal(string.Empty, ExtractString("gar##d#en"));
Assert.Equal("--", ExtractString("++##--##++"));
}
[Fact]
public void FullSequenceOfLetters_TEST()
{
Assert.Equal("defghijklmnopqrs", FullSequenceOfLetters("ds"));
Assert.Equal("opqr", FullSequenceOfLetters("or"));
}
[Fact]
public void SumAndAverage_TEST()
{
Assert.Equal("Sum: 2156, Average: 38,5", SumAndAverage(11, 66));
Assert.Equal("Sum: -55, Average: -5", SumAndAverage(-10, 0));
}
[Fact]
public void DrawTriangle_TEST()
{
Assert.Equal(
@" *
***
*****
*******
*********
***********
*************
***************
*****************
*******************", DrawTriangle(10));
}
[Fact]
public void ToThePowerOf_TEST()
{
Assert.Equal(-8, ToThePowerOf(-2, 3));
Assert.Equal(3125, ToThePowerOf(5, 5));
}
}

View File

@@ -1,65 +0,0 @@
using static BasicProgramming.Program;
namespace BasicProgrammingUnitTest;
public class BasicProgramming__STATEMENTS
{
[Fact]
public void AbsoluteValue_TEST()
{
Assert.Equal(6832, AbsoluteValue(6832));
Assert.Equal(392, AbsoluteValue(-392));
}
[Fact]
public void DivisibleBy2Or3_TEST()
{
Assert.Equal(450, DivisibleBy2Or3(15, 30));
Assert.Equal(180, DivisibleBy2Or3(2, 90));
Assert.Equal(19, DivisibleBy2Or3(7, 12));
}
[Fact]
public void IfConsistsOfUppercaseLetters_TEST()
{
Assert.False(IfConsistsOfUppercaseLetters("xyz"));
Assert.True(IfConsistsOfUppercaseLetters("DOG"));
Assert.False(IfConsistsOfUppercaseLetters("L9#"));
}
[Fact]
public void IfGreaterThanThirdOne_TEST()
{
Assert.True(IfGreaterThanThirdOne([2, 7, 12]));
Assert.False(IfGreaterThanThirdOne([-5, -8, 50]));
}
[Fact]
public void IfNumberIsEven_TEST()
{
Assert.False(IfNumberIsEven(721));
Assert.True(IfNumberIsEven(1248));
}
[Fact]
public void IfSortedAscending_TEST()
{
Assert.True(IfSortedAscending([3, 7, 10]));
Assert.False(IfSortedAscending([74, 62, 99]));
}
[Fact]
public void PositiveNegativeOrZero_TEST()
{
Assert.Equal("positive", PositiveNegativeOrZero(5.24));
Assert.Equal("zero", PositiveNegativeOrZero(0.0));
Assert.Equal("negative", PositiveNegativeOrZero(-994.53));
}
[Fact]
public void IfYearIsLeap_TEST()
{
Assert.True(IfYearIsLeap(2016));
Assert.False(IfYearIsLeap(2018));
}
}

View File

@@ -1,69 +0,0 @@
using static BasicProgramming.Program;
namespace BasicProgrammingUnitTest;
public class BasicProgramming__STRINGS
{
[Fact]
public void AddSeperator_TEST()
{
Assert.Equal("A^B^C^D", AddSeparator("ABCD", "^"));
Assert.Equal("c-h-o-c-o-l-a-t-e", AddSeparator("chocolate", "-"));
}
[Fact]
public void IsPalindrome_TEST()
{
Assert.True(IsPalindrome("eye"));
Assert.False(IsPalindrome("home"));
}
[Fact]
public void LengthOfAString_TEST()
{
Assert.Equal(8, LengthOfAString("computer"));
Assert.Equal(9, LengthOfAString("ice cream"));
}
[Fact]
public void StringInReverseOrder_TEST()
{
Assert.Equal("ytrewq", StringInReverseOrder("qwerty"));
Assert.Equal("rk 39eo", StringInReverseOrder("oe93 kr"));
}
[Fact]
public void NumberOfWords_TEST()
{
Assert.Equal(4, NumberOfWords("This is sample sentence"));
Assert.Equal(1, NumberOfWords("OK"));
}
[Fact]
public void RevertWordsOrder_TEST()
{
Assert.Equal("Doe. John", RevertWordsOrder("John Doe."));
Assert.Equal("C B. A,", RevertWordsOrder("A, B. C"));
}
[Fact]
public void HowManyOccurrences_TEST()
{
Assert.Equal(1, HowManyOccurrences("do it now", "do"));
Assert.Equal(0, HowManyOccurrences("empty", "d"));
}
[Fact]
public void SortCharactersDescending_TEST()
{
Assert.Equal(['t', 'p', 'o', 'o', 'o', 'o', 'n', 'm', 'i', 'e', 'a', 'a'], SortCharactersDescending("onomatopoeia"));
Assert.Equal(['w', 's', 'o', 'o', 'j', 'h', 'f', 'f', '4', '2'], SortCharactersDescending("fohjwf42os"));
}
[Fact]
public void CompressString_TEST()
{
Assert.Equal("k4t3r10", CompressString("kkkktttrrrrrrrrrr"));
Assert.Equal("p153p371w3", CompressString("p555ppp7www"));
}
}

View File

@@ -0,0 +1,64 @@
using BasicProgramming;
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 BasicProgramming;
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,75 @@
using BasicProgramming;
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 BasicProgramming;
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));
}
}