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

@@ -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));
}
}